diff --git a/src/Client.cs b/src/Client.cs index a1be6f9..8b27bb0 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -17,9 +17,6 @@ using System.Web; using TL; using static WTelegram.Encryption; -// necessary for .NET Standard 2.0 compilation: -#pragma warning disable CA1835 // Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' - namespace WTelegram { public partial class Client : IDisposable diff --git a/src/Compat.cs b/src/Compat.cs index c33a9bb..c4db45b 100644 --- a/src/Compat.cs +++ b/src/Compat.cs @@ -16,7 +16,7 @@ namespace WTelegram internal static IPEndPoint IPEndPoint_Parse(string addr) => IPEndPoint.Parse(addr); } } -#else +#else // Compatibility shims for methods missing in netstandard2.0: namespace WTelegram { static class Compat diff --git a/src/Encryption.cs b/src/Encryption.cs index 9211776..dd340f7 100644 --- a/src/Encryption.cs +++ b/src/Encryption.cs @@ -64,7 +64,7 @@ namespace WTelegram using var writer = new BinaryWriter(clearStream, Encoding.UTF8); byte[] aes_key = new byte[32], zero_iv = new byte[32]; var n = BigEndianInteger(publicKey.n); - while (encrypted_data == null) + do { RNG.GetBytes(aes_key); clearStream.Position = 0; @@ -84,7 +84,7 @@ namespace WTelegram var x = BigEndianInteger(clearBuffer); if (x < n) // if good result, encrypt with RSA key: encrypted_data = BigInteger.ModPow(x, BigEndianInteger(publicKey.e), n).To256Bytes(); - } // otherwise, repeat the steps + } while (encrypted_data == null); // otherwise, repeat the steps } var serverDHparams = await client.ReqDHParams(pqInnerData.nonce, pqInnerData.server_nonce, pqInnerData.p, pqInnerData.q, fingerprint, encrypted_data); //5) @@ -95,11 +95,11 @@ namespace WTelegram var (tmp_aes_key, tmp_aes_iv) = ConstructTmpAESKeyIV(resPQ.server_nonce, pqInnerData.new_nonce); var answer = AES_IGE_EncryptDecrypt(serverDHparamsOk.encrypted_answer, tmp_aes_key, tmp_aes_iv, false); - using var encryptedReader = new TL.BinaryReader(new MemoryStream(answer), client); - var answerHash = encryptedReader.ReadBytes(20); - var answerObj = encryptedReader.ReadTLObject(); + using var answerReader = new TL.BinaryReader(new MemoryStream(answer), client); + var answerHash = answerReader.ReadBytes(20); + var answerObj = answerReader.ReadTLObject(); if (answerObj is not ServerDHInnerData serverDHinnerData) throw new ApplicationException("not server_DH_inner_data"); - long padding = encryptedReader.BaseStream.Length - encryptedReader.BaseStream.Position; + long padding = answerReader.BaseStream.Length - answerReader.BaseStream.Position; if (padding >= 16) throw new ApplicationException("Too much pad"); if (!Enumerable.SequenceEqual(sha1.ComputeHash(answer, 20, answer.Length - (int)padding - 20), answerHash)) throw new ApplicationException("Answer SHA1 mismatch"); diff --git a/src/TL.SchemaFuncs.cs b/src/TL.SchemaFuncs.cs index 2dc4f09..fe44547 100644 --- a/src/TL.SchemaFuncs.cs +++ b/src/TL.SchemaFuncs.cs @@ -413,8 +413,9 @@ namespace TL rules = rules, }); - /// Delete the user's account from the telegram servers. Can be used, for example, to delete the account of a user that provided the login code, but forgot the 2FA password and no recovery method is configured. See Possible codes: 420 (details) + /// Delete the user's account from the telegram servers. See Possible codes: 420 (details) /// Why is the account being deleted, can be empty + /// 2FA password: this field can be omitted even for accounts with 2FA enabled: in this case account account deletion will be delayed by 7 days as specified in the docs ยป public static Task Account_DeleteAccount(this Client client, string reason, InputCheckPasswordSRP password = null) => client.Invoke(new Account_DeleteAccount {