mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2026-02-24 00:15:20 +01:00
Minor code cleaning
This commit is contained in:
parent
f1448ac517
commit
97bd76cf0f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -413,8 +413,9 @@ namespace TL
|
|||
rules = rules,
|
||||
});
|
||||
|
||||
/// <summary>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 <a href="https://corefork.telegram.org/api/srp">2FA password and no recovery method is configured</a>. <para>See <a href="https://corefork.telegram.org/method/account.deleteAccount"/></para> <para>Possible <see cref="RpcException"/> codes: 420 (<a href="https://corefork.telegram.org/method/account.deleteAccount#possible-errors">details</a>)</para></summary>
|
||||
/// <summary>Delete the user's account from the telegram servers. <para>See <a href="https://corefork.telegram.org/method/account.deleteAccount"/></para> <para>Possible <see cref="RpcException"/> codes: 420 (<a href="https://corefork.telegram.org/method/account.deleteAccount#possible-errors">details</a>)</para></summary>
|
||||
/// <param name="reason">Why is the account being deleted, can be empty</param>
|
||||
/// <param name="password"><a href="https://corefork.telegram.org/api/srp">2FA password</a>: this field can be omitted even for accounts with 2FA enabled: in this case account account deletion will be delayed by 7 days <a href="https://corefork.telegram.org/api/account-deletion">as specified in the docs »</a></param>
|
||||
public static Task<bool> Account_DeleteAccount(this Client client, string reason, InputCheckPasswordSRP password = null)
|
||||
=> client.Invoke(new Account_DeleteAccount
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue