Fix SendAlbumAsync videoUrlAsFile. using [] syntax

This commit is contained in:
Wizou 2024-03-08 11:52:30 +01:00
parent 345f10971b
commit b5ca3fcc0e
10 changed files with 49 additions and 49 deletions

View file

@ -218,10 +218,10 @@ namespace WTelegram
case InputMediaDocumentExternal imde: case InputMediaDocumentExternal imde:
string mimeType = null; string mimeType = null;
var inputFile = await UploadFromUrl(imde.url); var inputFile = await UploadFromUrl(imde.url);
if (mimeType?.StartsWith("video/") == true) if (videoUrlAsFile || mimeType?.StartsWith("video/") != true)
ism.media = new InputMediaUploadedDocument(inputFile, mimeType, new DocumentAttributeVideo { flags = DocumentAttributeVideo.Flags.supports_streaming });
else
ism.media = new InputMediaUploadedDocument(inputFile, mimeType); ism.media = new InputMediaUploadedDocument(inputFile, mimeType);
else
ism.media = new InputMediaUploadedDocument(inputFile, mimeType, new DocumentAttributeVideo { flags = DocumentAttributeVideo.Flags.supports_streaming });
goto retry; goto retry;
case InputMediaPhotoExternal impe: case InputMediaPhotoExternal impe:
inputFile = await UploadFromUrl(impe.url); inputFile = await UploadFromUrl(impe.url);
@ -510,7 +510,7 @@ namespace WTelegram
public async Task<Channels_ChannelParticipants> Channels_GetAllParticipants(InputChannelBase channel, bool includeKickBan = false, string alphabet1 = "АБCДЕЄЖФГHИІJКЛМНОПQРСТУВWХЦЧШЩЫЮЯЗ", string alphabet2 = "АCЕHИJЛМНОРСТУВWЫ", CancellationToken cancellationToken = default) public async Task<Channels_ChannelParticipants> Channels_GetAllParticipants(InputChannelBase channel, bool includeKickBan = false, string alphabet1 = "АБCДЕЄЖФГHИІJКЛМНОПQРСТУВWХЦЧШЩЫЮЯЗ", string alphabet2 = "АCЕHИJЛМНОРСТУВWЫ", CancellationToken cancellationToken = default)
{ {
alphabet2 ??= alphabet1; alphabet2 ??= alphabet1;
var result = new Channels_ChannelParticipants { chats = new(), users = new() }; var result = new Channels_ChannelParticipants { chats = [], users = [] };
var user_ids = new HashSet<long>(); var user_ids = new HashSet<long>();
var participants = new List<ChannelParticipantBase>(); var participants = new List<ChannelParticipantBase>();
@ -616,7 +616,7 @@ namespace WTelegram
{ {
case InputPeerChat chat: case InputPeerChat chat:
await this.Messages_EditChatAdmin(chat.chat_id, user, is_admin); await this.Messages_EditChatAdmin(chat.chat_id, user, is_admin);
return new Updates { date = DateTime.UtcNow, users = new(), updates = Array.Empty<Update>(), return new Updates { date = DateTime.UtcNow, users = [], updates = [],
chats = (await this.Messages_GetChats(chat.chat_id)).chats }; chats = (await this.Messages_GetChats(chat.chat_id)).chats };
case InputPeerChannel channel: case InputPeerChannel channel:
return await this.Channels_EditAdmin(channel, user, return await this.Channels_EditAdmin(channel, user,
@ -663,7 +663,7 @@ namespace WTelegram
{ {
case InputPeerChat chat: case InputPeerChat chat:
await this.Messages_DeleteChat(chat.chat_id); await this.Messages_DeleteChat(chat.chat_id);
return new Updates { date = DateTime.UtcNow, users = new(), updates = Array.Empty<Update>(), return new Updates { date = DateTime.UtcNow, users = [], updates = [],
chats = (await this.Messages_GetChats(chat.chat_id)).chats }; chats = (await this.Messages_GetChats(chat.chat_id)).chats };
case InputPeerChannel channel: case InputPeerChannel channel:
return await this.Channels_DeleteChannel(channel); return await this.Channels_DeleteChannel(channel);
@ -695,7 +695,7 @@ namespace WTelegram
public async Task<bool> ReadHistory(InputPeer peer, int max_id = default) public async Task<bool> ReadHistory(InputPeer peer, int max_id = default)
=> peer is InputPeerChannel channel ? await this.Channels_ReadHistory(channel, max_id) : (await this.Messages_ReadHistory(peer, max_id)) != null; => peer is InputPeerChannel channel ? await this.Channels_ReadHistory(channel, max_id) : (await this.Messages_ReadHistory(peer, max_id)) != null;
private static readonly char[] UrlSeparator = new[] { '?', '#', '/' }; private static readonly char[] UrlSeparator = ['?', '#', '/'];
/// <summary>Return information about a chat/channel based on Invite Link or Public Link</summary> /// <summary>Return information about a chat/channel based on Invite Link or Public Link</summary>
/// <param name="url">Public link or Invite link, like https://t.me/+InviteHash, https://t.me/joinchat/InviteHash or https://t.me/channelname<br/>Works also without https:// prefix</param> /// <param name="url">Public link or Invite link, like https://t.me/+InviteHash, https://t.me/joinchat/InviteHash or https://t.me/channelname<br/>Works also without https:// prefix</param>

View file

@ -64,12 +64,12 @@ namespace WTelegram
private Stream _networkStream; private Stream _networkStream;
private IObject _lastSentMsg; private IObject _lastSentMsg;
private long _lastRecvMsgId; private long _lastRecvMsgId;
private readonly List<long> _msgsToAck = new(); private readonly List<long> _msgsToAck = [];
private readonly Random _random = new(); private readonly Random _random = new();
private int _saltChangeCounter; private int _saltChangeCounter;
private Task _reactorTask; private Task _reactorTask;
private Rpc _bareRpc; private Rpc _bareRpc;
private readonly Dictionary<long, Rpc> _pendingRpcs = new(); private readonly Dictionary<long, Rpc> _pendingRpcs = [];
private SemaphoreSlim _sendSemaphore = new(0); private SemaphoreSlim _sendSemaphore = new(0);
private readonly SemaphoreSlim _semaphore = new(1); private readonly SemaphoreSlim _semaphore = new(1);
private Task _connecting; private Task _connecting;
@ -489,7 +489,7 @@ namespace WTelegram
{ {
lock (_session) lock (_session)
{ {
_dcSession.Salts ??= new(); _dcSession.Salts ??= [];
if (_dcSession.Salts.Count != 0) if (_dcSession.Salts.Count != 0)
{ {
var keys = _dcSession.Salts.Keys; var keys = _dcSession.Salts.Keys;
@ -1285,7 +1285,7 @@ namespace WTelegram
if (isContent && CheckMsgsToAck() is MsgsAck msgsAck) if (isContent && CheckMsgsToAck() is MsgsAck msgsAck)
{ {
var (ackId, ackSeqno) = NewMsgId(false); var (ackId, ackSeqno) = NewMsgId(false);
var container = new MsgContainer { messages = new _Message[] { new(msgId, seqno, msg), new(ackId, ackSeqno, msgsAck) } }; var container = new MsgContainer { messages = [new(msgId, seqno, msg), new(ackId, ackSeqno, msgsAck)] };
await SendAsync(container, false); await SendAsync(container, false);
return; return;
} }

View file

@ -87,7 +87,7 @@ namespace System.Runtime.CompilerServices
{ {
if (array == null) throw new ArgumentNullException(); if (array == null) throw new ArgumentNullException();
var (offset, length) = range.GetOffsetAndLength(array.Length); var (offset, length) = range.GetOffsetAndLength(array.Length);
if (length == 0) return Array.Empty<T>(); if (length == 0) return [];
var dest = typeof(T).IsValueType || typeof(T[]) == array.GetType() ? new T[length] var dest = typeof(T).IsValueType || typeof(T[]) == array.GetType() ? new T[length]
: (T[])Array.CreateInstance(array.GetType().GetElementType()!, length); : (T[])Array.CreateInstance(array.GetType().GetElementType()!, length);
Array.Copy(array, offset, dest, 0, length); Array.Copy(array, offset, dest, 0, length);

View file

@ -15,7 +15,7 @@ namespace WTelegram
{ {
internal static class Encryption internal static class Encryption
{ {
private static readonly Dictionary<long, RSAPublicKey> PublicKeys = new(); private static readonly Dictionary<long, RSAPublicKey> PublicKeys = [];
internal static readonly RNGCryptoServiceProvider RNG = new(); internal static readonly RNGCryptoServiceProvider RNG = new();
internal static readonly Aes AesECB = Aes.Create(); internal static readonly Aes AesECB = Aes.Create();
@ -209,7 +209,7 @@ namespace WTelegram
SafePrimes.Add(p); SafePrimes.Add(p);
} }
private static readonly HashSet<BigInteger> SafePrimes = new() { new(new byte[] // C71CAEB9C6B1C904... private static readonly HashSet<BigInteger> SafePrimes = [ new(new byte[] // C71CAEB9C6B1C904...
{ {
0x5B, 0xCC, 0x2F, 0xB9, 0xE3, 0xD8, 0x9C, 0x11, 0x03, 0x04, 0xB1, 0x34, 0xF0, 0xAD, 0x4F, 0x6F, 0x5B, 0xCC, 0x2F, 0xB9, 0xE3, 0xD8, 0x9C, 0x11, 0x03, 0x04, 0xB1, 0x34, 0xF0, 0xAD, 0x4F, 0x6F,
0xBF, 0x54, 0x24, 0x4B, 0xD0, 0x15, 0x4E, 0x2E, 0xEE, 0x05, 0xB1, 0x35, 0xF6, 0x15, 0x81, 0x0D, 0xBF, 0x54, 0x24, 0x4B, 0xD0, 0x15, 0x4E, 0x2E, 0xEE, 0x05, 0xB1, 0x35, 0xF6, 0x15, 0x81, 0x0D,
@ -227,7 +227,7 @@ namespace WTelegram
0xDB, 0xF4, 0x30, 0x25, 0xD2, 0x93, 0x94, 0x22, 0x58, 0x40, 0xC1, 0xA7, 0x0A, 0x8A, 0x19, 0x48, 0xDB, 0xF4, 0x30, 0x25, 0xD2, 0x93, 0x94, 0x22, 0x58, 0x40, 0xC1, 0xA7, 0x0A, 0x8A, 0x19, 0x48,
0x0F, 0x93, 0x3D, 0x56, 0x37, 0xD0, 0x34, 0x49, 0xC1, 0x21, 0x3E, 0x8E, 0x23, 0x40, 0x0D, 0x98, 0x0F, 0x93, 0x3D, 0x56, 0x37, 0xD0, 0x34, 0x49, 0xC1, 0x21, 0x3E, 0x8E, 0x23, 0x40, 0x0D, 0x98,
0x73, 0x3F, 0xF1, 0x70, 0x2F, 0x52, 0x6C, 0x8E, 0x04, 0xC9, 0xB1, 0xC6, 0xB9, 0xAE, 0x1C, 0xC7, 0x00 0x73, 0x3F, 0xF1, 0x70, 0x2F, 0x52, 0x6C, 0x8E, 0x04, 0xC9, 0xB1, 0xC6, 0xB9, 0xAE, 0x1C, 0xC7, 0x00
})}; })];
internal static void CheckGoodGaAndGb(BigInteger g, BigInteger dh_prime) internal static void CheckGoodGaAndGb(BigInteger g, BigInteger dh_prime)
{ {

View file

@ -18,8 +18,8 @@ namespace WTelegram
public static readonly JsonSerializerOptions JsonOptions = new() { IncludeFields = true, WriteIndented = true, public static readonly JsonSerializerOptions JsonOptions = new() { IncludeFields = true, WriteIndented = true,
IgnoreReadOnlyProperties = true, DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull }; IgnoreReadOnlyProperties = true, DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull };
private static readonly ConsoleColor[] LogLevelToColor = new[] { ConsoleColor.DarkGray, ConsoleColor.DarkCyan, private static readonly ConsoleColor[] LogLevelToColor = [ ConsoleColor.DarkGray, ConsoleColor.DarkCyan,
ConsoleColor.Cyan, ConsoleColor.Yellow, ConsoleColor.Red, ConsoleColor.Magenta, ConsoleColor.DarkBlue }; ConsoleColor.Cyan, ConsoleColor.Yellow, ConsoleColor.Red, ConsoleColor.Magenta, ConsoleColor.DarkBlue ];
private static void DefaultLogger(int level, string message) private static void DefaultLogger(int level, string message)
{ {
Console.ForegroundColor = LogLevelToColor[level]; Console.ForegroundColor = LogLevelToColor[level];
@ -186,7 +186,7 @@ namespace WTelegram
} }
internal static readonly byte[] StrippedThumbJPG = // see https://core.telegram.org/api/files#stripped-thumbnails internal static readonly byte[] StrippedThumbJPG = // see https://core.telegram.org/api/files#stripped-thumbnails
{ [
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49,
0x46, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x28, 0x1c, 0x46, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x28, 0x1c,
0x1e, 0x23, 0x1e, 0x19, 0x28, 0x23, 0x21, 0x23, 0x2d, 0x2b, 0x28, 0x30, 0x3c, 0x64, 0x41, 0x3c, 0x37, 0x37, 0x1e, 0x23, 0x1e, 0x19, 0x28, 0x23, 0x21, 0x23, 0x2d, 0x2b, 0x28, 0x30, 0x3c, 0x64, 0x41, 0x3c, 0x37, 0x37,
@ -223,7 +223,7 @@ namespace WTelegram
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4,
0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00,
0x3f, 0x00 0x3f, 0x00
}; ];
internal static string GetSystemVersion() internal static string GetSystemVersion()
{ {

View file

@ -28,7 +28,7 @@ namespace WTelegram
private readonly Client client; private readonly Client client;
private readonly FileStream storage; private readonly FileStream storage;
private readonly Dictionary<int, SecretChat> chats = new(); private readonly Dictionary<int, SecretChat> chats = [];
private Messages_DhConfig dh; private Messages_DhConfig dh;
private BigInteger dh_prime; private BigInteger dh_prime;
private readonly SHA256 sha256 = SHA256.Create(); private readonly SHA256 sha256 = SHA256.Create();
@ -57,7 +57,7 @@ namespace WTelegram
public int RemoteLayer => remoteLayer; public int RemoteLayer => remoteLayer;
internal long key_fingerprint; internal long key_fingerprint;
internal SortedList<int, TL.Layer23.DecryptedMessageLayer> pendingMsgs = new(); internal SortedList<int, TL.Layer23.DecryptedMessageLayer> pendingMsgs = [];
internal void Discarded() // clear out fields for more security internal void Discarded() // clear out fields for more security
{ {
Array.Clear(authKey, 0, authKey.Length); Array.Clear(authKey, 0, authKey.Length);

View file

@ -16,7 +16,7 @@ namespace WTelegram
public int ApiId; public int ApiId;
public long UserId; public long UserId;
public int MainDC; public int MainDC;
public Dictionary<int, DCSession> DCSessions = new(); public Dictionary<int, DCSession> DCSessions = [];
public TL.DcOption[] DcOptions; public TL.DcOption[] DcOptions;
public class DCSession public class DCSession
@ -195,7 +195,7 @@ namespace WTelegram
internal class ActionStore : MemoryStream internal class ActionStore : MemoryStream
{ {
private readonly Action<byte[]> _save; private readonly Action<byte[]> _save;
public ActionStore(byte[] initial, Action<byte[]> save) : base(initial ?? Array.Empty<byte>()) => _save = save; public ActionStore(byte[] initial, Action<byte[]> save) : base(initial ?? []) => _save = save;
public override void Write(byte[] buffer, int offset, int count) => _save(buffer[offset..(offset + count)]); public override void Write(byte[] buffer, int offset, int count) => _save(buffer[offset..(offset + count)]);
public override void SetLength(long value) { } public override void SetLength(long value) { }
} }

View file

@ -285,7 +285,7 @@ namespace TL
partial class ChatParticipantAdmin { public override bool IsAdmin => true; } partial class ChatParticipantAdmin { public override bool IsAdmin => true; }
partial class ChatParticipantsBase { public abstract ChatParticipantBase[] Participants { get; }} partial class ChatParticipantsBase { public abstract ChatParticipantBase[] Participants { get; }}
partial class ChatParticipantsForbidden { public override ChatParticipantBase[] Participants => Array.Empty<ChatParticipantBase>(); } partial class ChatParticipantsForbidden { public override ChatParticipantBase[] Participants => []; }
partial class ChatParticipants { public override ChatParticipantBase[] Participants => participants; } partial class ChatParticipants { public override ChatParticipantBase[] Participants => participants; }
partial class MessageEmpty { public override string ToString() => "(no message)"; } partial class MessageEmpty { public override string ToString() => "(no message)"; }
@ -429,8 +429,8 @@ namespace TL
public abstract Update[] UpdateList { get; } public abstract Update[] UpdateList { get; }
public virtual Dictionary<long, User> Users => NoUsers; public virtual Dictionary<long, User> Users => NoUsers;
public virtual Dictionary<long, ChatBase> Chats => NoChats; public virtual Dictionary<long, ChatBase> Chats => NoChats;
private static readonly Dictionary<long, User> NoUsers = new(); private static readonly Dictionary<long, User> NoUsers = [];
private static readonly Dictionary<long, ChatBase> NoChats = new(); private static readonly Dictionary<long, ChatBase> NoChats = [];
public virtual (long mbox_id, int pts, int pts_count) GetMBox() => default; public virtual (long mbox_id, int pts, int pts_count) GetMBox() => default;
} }
partial class UpdatesCombined partial class UpdatesCombined
@ -447,10 +447,10 @@ namespace TL
public override Dictionary<long, ChatBase> Chats => chats; public override Dictionary<long, ChatBase> Chats => chats;
public override (long mbox_id, int pts, int pts_count) GetMBox() => (-2, seq, 1); public override (long mbox_id, int pts, int pts_count) GetMBox() => (-2, seq, 1);
} }
partial class UpdatesTooLong { public override Update[] UpdateList => Array.Empty<Update>(); } partial class UpdatesTooLong { public override Update[] UpdateList => []; }
partial class UpdateShort { public override Update[] UpdateList => new[] { update }; } partial class UpdateShort { public override Update[] UpdateList => [update]; }
partial class UpdateShortSentMessage { public override Update[] UpdateList => Array.Empty<Update>(); } partial class UpdateShortSentMessage { public override Update[] UpdateList => []; }
partial class UpdateShortMessage { public override Update[] UpdateList => new[] { new UpdateNewMessage partial class UpdateShortMessage { public override Update[] UpdateList => [ new UpdateNewMessage
{ {
message = new Message message = new Message
{ {
@ -460,8 +460,8 @@ namespace TL
peer_id = new PeerUser { user_id = user_id }, peer_id = new PeerUser { user_id = user_id },
fwd_from = fwd_from, via_bot_id = via_bot_id, ttl_period = ttl_period fwd_from = fwd_from, via_bot_id = via_bot_id, ttl_period = ttl_period
}, pts = pts, pts_count = pts_count }, pts = pts, pts_count = pts_count
} }; } } ]; }
partial class UpdateShortChatMessage { public override Update[] UpdateList => new[] { new UpdateNewMessage partial class UpdateShortChatMessage { public override Update[] UpdateList => [ new UpdateNewMessage
{ {
message = new Message message = new Message
{ {
@ -471,7 +471,7 @@ namespace TL
peer_id = new PeerChat { chat_id = chat_id }, peer_id = new PeerChat { chat_id = chat_id },
fwd_from = fwd_from, via_bot_id = via_bot_id, ttl_period = ttl_period fwd_from = fwd_from, via_bot_id = via_bot_id, ttl_period = ttl_period
}, pts = pts, pts_count = pts_count }, pts = pts, pts_count = pts_count
} }; } } ]; }
partial class InputEncryptedChat { public static implicit operator int(InputEncryptedChat chat) => chat.chat_id; partial class InputEncryptedChat { public static implicit operator int(InputEncryptedChat chat) => chat.chat_id;
public static implicit operator InputEncryptedChat(EncryptedChatBase chat) => new() { chat_id = chat.ID, access_hash = chat.AccessHash }; } public static implicit operator InputEncryptedChat(EncryptedChatBase chat) => new() { chat_id = chat.ID, access_hash = chat.AccessHash }; }
@ -580,8 +580,8 @@ namespace TL
} }
partial class Updates_ChannelDifferenceEmpty partial class Updates_ChannelDifferenceEmpty
{ {
public override MessageBase[] NewMessages => Array.Empty<MessageBase>(); public override MessageBase[] NewMessages => [];
public override Update[] OtherUpdates => Array.Empty<Update>(); public override Update[] OtherUpdates => [];
public override bool Final => flags.HasFlag(Flags.final); public override bool Final => flags.HasFlag(Flags.final);
public override int Timeout => timeout; public override int Timeout => timeout;
} }

View file

@ -5183,9 +5183,9 @@ namespace TL
/// <summary>Number of sent updates</summary> /// <summary>Number of sent updates</summary>
public int seq; public int seq;
public override MessageBase[] NewMessages => Array.Empty<MessageBase>(); public override MessageBase[] NewMessages => [];
public override EncryptedMessageBase[] NewEncryptedMessages => Array.Empty<EncryptedMessageBase>(); public override EncryptedMessageBase[] NewEncryptedMessages => [];
public override Update[] OtherUpdates => Array.Empty<Update>(); public override Update[] OtherUpdates => [];
/// <summary>returns a <see cref="User"/> or <see cref="ChatBase"/> for the given Peer</summary> /// <summary>returns a <see cref="User"/> or <see cref="ChatBase"/> for the given Peer</summary>
public override IPeerInfo UserOrChat(Peer peer) => null; public override IPeerInfo UserOrChat(Peer peer) => null;
} }

View file

@ -15,10 +15,10 @@ namespace WTelegram
{ {
public TlsStream(Stream innerStream) : base(innerStream) { } public TlsStream(Stream innerStream) : base(innerStream) { }
private int _tlsFrameleft; private int _tlsFrameleft;
private readonly byte[] _tlsSendHeader = new byte[] { 0x17, 0x03, 0x03, 0, 0 }; private readonly byte[] _tlsSendHeader = [0x17, 0x03, 0x03, 0, 0];
private readonly byte[] _tlsReadHeader = new byte[5]; private readonly byte[] _tlsReadHeader = new byte[5];
static readonly byte[] TlsServerHello3 = new byte[] { 0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x17, 0x03, 0x03 }; static readonly byte[] TlsServerHello3 = [0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x17, 0x03, 0x03];
static readonly byte[] TlsClientPrefix = new byte[] { 0x14, 0x03, 0x03, 0x00, 0x01, 0x01 }; static readonly byte[] TlsClientPrefix = [0x14, 0x03, 0x03, 0x00, 0x01, 0x01];
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken ct) public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken ct)
{ {
@ -85,20 +85,20 @@ namespace WTelegram
throw new WTException("TLS Handshake failed"); throw new WTException("TLS Handshake failed");
} }
static readonly byte[] TlsClientHello1 = new byte[11] { // https://tls13.xargs.org/#client-hello/annotated static readonly byte[] TlsClientHello1 = [ // https://tls13.xargs.org/#client-hello/annotated
0x16, 0x03, 0x01, 0x02, 0x00, 0x01, 0x00, 0x01, 0xfc, 0x03, 0x03 }; 0x16, 0x03, 0x01, 0x02, 0x00, 0x01, 0x00, 0x01, 0xfc, 0x03, 0x03 ];
// digest[32] // digest[32]
// 0x20 // 0x20
// random[32] // random[32]
// 0x00, 0x20 // 0x00, 0x20
// grease(0) GREASE are two identical bytes ending with nibble 'A' // grease(0) GREASE are two identical bytes ending with nibble 'A'
static readonly byte[] TlsClientHello2 = new byte[34] { static readonly byte[] TlsClientHello2 = [
0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2b, 0xc0, 0x2f, 0xc0, 0x2c, 0xc0, 0x30, 0xcc, 0xa9, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2b, 0xc0, 0x2f, 0xc0, 0x2c, 0xc0, 0x30, 0xcc, 0xa9,
0xcc, 0xa8, 0xc0, 0x13, 0xc0, 0x14, 0x00, 0x9c, 0x00, 0x9d, 0x00, 0x2f, 0x00, 0x35, 0xcc, 0xa8, 0xc0, 0x13, 0xc0, 0x14, 0x00, 0x9c, 0x00, 0x9d, 0x00, 0x2f, 0x00, 0x35,
0x01, 0x00, 0x01, 0x93 }; 0x01, 0x00, 0x01, 0x93 ];
// grease(2) // grease(2)
// 0x00, 0x00 // 0x00, 0x00
static readonly byte[] TlsClientHello3 = new byte[134] { static readonly byte[] TlsClientHello3 = [
// 0x00, 0x00, len { len { 0x00 len { domain } } } len is 16-bit big-endian length of the following block of data // 0x00, 0x00, len { len { 0x00 len { domain } } } len is 16-bit big-endian length of the following block of data
0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x4A, 0x4A,/*=grease(4)*/ 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x4A, 0x4A,/*=grease(4)*/ 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18,
@ -114,10 +114,10 @@ namespace WTelegram
0x00, 0x33, 0x00, 0x2b, 0x00, 0x29, 0x4A, 0x4A,/*=grease(4) */ 0x00, 0x01, 0x00, 0x00, 0x1d, 0x00, 0x20, /* random[32] */ 0x00, 0x33, 0x00, 0x2b, 0x00, 0x29, 0x4A, 0x4A,/*=grease(4) */ 0x00, 0x01, 0x00, 0x00, 0x1d, 0x00, 0x20, /* random[32] */
0x44, 0x69, 0x00, 0x05, 0x00, 0x03, 0x02, 0x68, 0x32, 0x44, 0x69, 0x00, 0x05, 0x00, 0x03, 0x02, 0x68, 0x32,
0xff, 0x01, 0x00, 0x01, 0x00, 0xff, 0x01, 0x00, 0x01, 0x00,
}; ];
// grease(3) // grease(3)
static readonly byte[] TlsClientHello4 = new byte[5] { static readonly byte[] TlsClientHello4 = [
0x00, 0x01, 0x00, 0x00, 0x15 }; 0x00, 0x01, 0x00, 0x00, 0x15 ];
// len { padding } padding with NUL bytes to reach 517 bytes // len { padding } padding with NUL bytes to reach 517 bytes
static byte[] TlsClientHello(byte[] key, byte[] domain) static byte[] TlsClientHello(byte[] key, byte[] domain)