Fix Naming Styles

This commit is contained in:
Wizou 2023-07-08 01:34:31 +02:00
parent c631072ae4
commit 8a9f886b62
9 changed files with 57 additions and 51 deletions

View file

@ -594,9 +594,9 @@ namespace WTelegram
class Rpc
{
public Type type;
public TaskCompletionSource<object> tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
public long msgId;
internal Type type;
internal TaskCompletionSource<object> tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
internal long msgId;
public Task<object> Task => tcs.Task;
}

View file

@ -320,31 +320,31 @@ j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB
#if OBFUSCATION
internal class AesCtr : IDisposable
{
readonly ICryptoTransform encryptor;
readonly byte[] ivec;
readonly byte[] ecount = new byte[16];
int num;
readonly ICryptoTransform _encryptor;
readonly byte[] _ivec;
readonly byte[] _ecount = new byte[16];
int _num;
public AesCtr(byte[] key, byte[] iv)
{
encryptor = AesECB.CreateEncryptor(key, null);
ivec = iv;
_encryptor = AesECB.CreateEncryptor(key, null);
_ivec = iv;
}
public void Dispose() => encryptor.Dispose();
public void Dispose() => _encryptor.Dispose();
public void EncryptDecrypt(byte[] buffer, int length)
{
for (int i = 0; i < length; i++)
{
if (num == 0)
if (_num == 0)
{
encryptor.TransformBlock(ivec, 0, 16, ecount, 0);
_encryptor.TransformBlock(_ivec, 0, 16, _ecount, 0);
for (int n = 15; n >= 0; n--) // increment big-endian counter
if (++ivec[n] != 0) break;
if (++_ivec[n] != 0) break;
}
buffer[i] ^= ecount[num];
num = (num + 1) % 16;
buffer[i] ^= _ecount[_num];
_num = (_num + 1) % 16;
}
}
}
@ -526,15 +526,15 @@ j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB
internal class AES_IGE_Stream : Helpers.IndirectStream
{
private readonly ICryptoTransform aesCrypto;
private readonly byte[] prevBytes;
private readonly ICryptoTransform _aesCrypto;
private readonly byte[] _prevBytes;
public AES_IGE_Stream(Stream stream, long size, byte[] key, byte[] iv) : this(stream, key, iv, false) { ContentLength = size; }
public AES_IGE_Stream(Stream stream, byte[] key, byte[] iv, bool encrypt) : base(stream)
{
aesCrypto = encrypt ? Encryption.AesECB.CreateEncryptor(key, null) : Encryption.AesECB.CreateDecryptor(key, null);
if (encrypt) prevBytes = (byte[])iv.Clone();
else { prevBytes = new byte[32]; Array.Copy(iv, 0, prevBytes, 16, 16); Array.Copy(iv, 16, prevBytes, 0, 16); }
_aesCrypto = encrypt ? Encryption.AesECB.CreateEncryptor(key, null) : Encryption.AesECB.CreateDecryptor(key, null);
if (encrypt) _prevBytes = (byte[])iv.Clone();
else { _prevBytes = new byte[32]; Array.Copy(iv, 0, _prevBytes, 16, 16); Array.Copy(iv, 16, _prevBytes, 0, 16); }
}
public override long Length => base.Length + 15 & ~15;
@ -563,11 +563,11 @@ j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB
{
count = count + 15 & ~15;
var span = MemoryMarshal.Cast<byte, long>(buffer.AsSpan(offset, count));
var prev = MemoryMarshal.Cast<byte, long>(prevBytes);
var prev = MemoryMarshal.Cast<byte, long>(_prevBytes);
for (offset = 0, count /= 8; offset < count;)
{
prev[0] ^= span[offset]; prev[1] ^= span[offset + 1];
aesCrypto.TransformBlock(prevBytes, 0, 16, prevBytes, 0);
_aesCrypto.TransformBlock(_prevBytes, 0, 16, _prevBytes, 0);
prev[0] ^= prev[2]; prev[1] ^= prev[3];
prev[2] = span[offset]; prev[3] = span[offset + 1];
span[offset++] = prev[0]; span[offset++] = prev[1];

View file

@ -37,39 +37,39 @@ namespace WTelegram
internal void Renew() { Helpers.Log(3, $"Renewing session on DC {DcID}..."); Id = Helpers.RandomLong(); Seqno = 0; LastSentMsgId = 0; }
public void DisableUpdates(bool disable = true) { if (WithoutUpdates != disable) { WithoutUpdates = disable; Renew(); } }
const int msgIdsN = 512;
private long[] msgIds;
private int msgIdsHead;
const int MsgIdsN = 512;
private long[] _msgIds;
private int _msgIdsHead;
internal bool CheckNewMsgId(long msg_id)
{
if (msgIds == null)
if (_msgIds == null)
{
msgIds = new long[msgIdsN];
msgIds[0] = msg_id;
_msgIds = new long[MsgIdsN];
_msgIds[0] = msg_id;
msg_id -= 300L << 32; // until the array is filled with real values, allow ids up to 300 seconds in the past
for (int i = 1; i < msgIdsN; i++) msgIds[i] = msg_id;
for (int i = 1; i < MsgIdsN; i++) _msgIds[i] = msg_id;
return true;
}
int newHead = (msgIdsHead + 1) % msgIdsN;
if (msg_id > msgIds[msgIdsHead])
msgIds[msgIdsHead = newHead] = msg_id;
else if (msg_id <= msgIds[newHead])
int newHead = (_msgIdsHead + 1) % MsgIdsN;
if (msg_id > _msgIds[_msgIdsHead])
_msgIds[_msgIdsHead = newHead] = msg_id;
else if (msg_id <= _msgIds[newHead])
return false;
else
{
int min = 0, max = msgIdsN - 1;
int min = 0, max = MsgIdsN - 1;
while (min <= max) // binary search (rotated at newHead)
{
int mid = (min + max) / 2;
int sign = msg_id.CompareTo(msgIds[(mid + newHead) % msgIdsN]);
int sign = msg_id.CompareTo(_msgIds[(mid + newHead) % MsgIdsN]);
if (sign == 0) return false;
else if (sign < 0) max = mid - 1;
else min = mid + 1;
}
msgIdsHead = newHead;
for (min = (min + newHead) % msgIdsN; newHead != min;)
msgIds[newHead] = msgIds[newHead = newHead == 0 ? msgIdsN - 1 : newHead - 1];
msgIds[min] = msg_id;
_msgIdsHead = newHead;
for (min = (min + newHead) % MsgIdsN; newHead != min;)
_msgIds[newHead] = _msgIds[newHead = newHead == 0 ? MsgIdsN - 1 : newHead - 1];
_msgIds[min] = msg_id;
}
return true;
}

View file

@ -173,7 +173,7 @@ namespace TL
if (i == sb.Length) break;
for (; offset == nextEntity?.offset; nextEntity = ++entityIndex < entities.Length ? entities[entityIndex] : null)
{
if (entityToMD.TryGetValue(nextEntity.GetType(), out var md))
if (EntityToMD.TryGetValue(nextEntity.GetType(), out var md))
{
var closing = (nextEntity.offset + nextEntity.length, md);
if (md[0] is '[' or '!')
@ -207,7 +207,7 @@ namespace TL
return sb.ToString();
}
static readonly Dictionary<Type, string> entityToMD = new()
static readonly Dictionary<Type, string> EntityToMD = new()
{
[typeof(MessageEntityBold)] = "*",
[typeof(MessageEntityItalic)] = "_",
@ -360,7 +360,7 @@ namespace TL
if (i == sb.Length) break;
for (; offset == nextEntity?.offset; nextEntity = ++entityIndex < entities.Length ? entities[entityIndex] : null)
{
if (entityToTag.TryGetValue(nextEntity.GetType(), out var tag))
if (EntityToTag.TryGetValue(nextEntity.GetType(), out var tag))
{
var closing = (nextEntity.offset + nextEntity.length, $"</{tag}>");
if (tag[0] == 'a')
@ -397,7 +397,7 @@ namespace TL
return sb.ToString();
}
static readonly Dictionary<Type, string> entityToTag = new()
static readonly Dictionary<Type, string> EntityToTag = new()
{
[typeof(MessageEntityBold)] = "b",
[typeof(MessageEntityItalic)] = "i",

View file

@ -5,6 +5,7 @@ using Client = WTelegram.Client;
namespace TL
{
#pragma warning disable IDE1006
[TLDef(0x05162463)] //resPQ#05162463 nonce:int128 server_nonce:int128 pq:bytes server_public_key_fingerprints:Vector<long> = ResPQ
public class ResPQ : IObject
{
@ -365,6 +366,7 @@ namespace TL
namespace TL.Methods
{
#pragma warning disable IDE1006
[TLDef(0x60469778)] //req_pq#60469778 nonce:int128 = ResPQ
public class ReqPq : IMethod<ResPQ>
{

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
namespace TL
{
#pragma warning disable IDE1006
/// <summary>Boolean type. <para>See <a href="https://corefork.telegram.org/type/Bool"/></para></summary>
public enum Bool : uint
{
@ -6811,7 +6812,7 @@ namespace TL
/// <summary>Unknown message entity <para>See <a href="https://corefork.telegram.org/constructor/messageEntityUnknown"/></para></summary>
[TLDef(0xBB92BA95)]
public class MessageEntityUnknown : MessageEntity { }
/// <summary>Message entity <a href="https://corefork.telegram.org/api/mentions">mentioning</a> the current user <para>See <a href="https://corefork.telegram.org/constructor/messageEntityMention"/></para></summary>
/// <summary>Message entity <a href="https://corefork.telegram.org/api/mentions">mentioning</a> a user by <c>@username</c>; <see cref="MessageEntityMentionName"/> can also be used to mention users by their ID. <para>See <a href="https://corefork.telegram.org/constructor/messageEntityMention"/></para></summary>
[TLDef(0xFA04579D)]
public class MessageEntityMention : MessageEntity { }
/// <summary><strong>#hashtag</strong> message entity <para>See <a href="https://corefork.telegram.org/constructor/messageEntityHashtag"/></para></summary>

View file

@ -5603,6 +5603,7 @@ namespace TL
namespace TL.Methods
{
#pragma warning disable IDE1006
[TLDef(0xCB9F372D)]
public class InvokeAfterMsg<X> : IMethod<X>
{

View file

@ -2,6 +2,7 @@
namespace TL
{
#pragma warning disable IDE1006
/// <summary>Object describes the contents of an encrypted message. <para>See <a href="https://corefork.telegram.org/type/DecryptedMessage"/></para></summary>
public abstract class DecryptedMessageBase : IObject
{

View file

@ -7,6 +7,8 @@ using System.Reflection;
using System.Security.Cryptography;
using System.Text;
#pragma warning disable IDE1006 // Naming Styles
namespace TL
{
public interface IObject { }
@ -333,9 +335,9 @@ namespace TL
public Int128(RNGCryptoServiceProvider rng) => rng.GetBytes(raw = new byte[16]);
public static bool operator ==(Int128 left, Int128 right) { for (int i = 0; i < 16; i++) if (left.raw[i] != right.raw[i]) return false; return true; }
public static bool operator !=(Int128 left, Int128 right) { for (int i = 0; i < 16; i++) if (left.raw[i] != right.raw[i]) return true; return false; }
public override bool Equals(object obj) => obj is Int128 other && this == other;
public override int GetHashCode() => BitConverter.ToInt32(raw, 0);
public override string ToString() => Convert.ToHexString(raw);
public override readonly bool Equals(object obj) => obj is Int128 other && this == other;
public override readonly int GetHashCode() => BitConverter.ToInt32(raw, 0);
public override readonly string ToString() => Convert.ToHexString(raw);
public static implicit operator byte[](Int128 int128) => int128.raw;
}
@ -347,9 +349,9 @@ namespace TL
public Int256(RNGCryptoServiceProvider rng) => rng.GetBytes(raw = new byte[32]);
public static bool operator ==(Int256 left, Int256 right) { for (int i = 0; i < 32; i++) if (left.raw[i] != right.raw[i]) return false; return true; }
public static bool operator !=(Int256 left, Int256 right) { for (int i = 0; i < 32; i++) if (left.raw[i] != right.raw[i]) return true; return false; }
public override bool Equals(object obj) => obj is Int256 other && this == other;
public override int GetHashCode() => BitConverter.ToInt32(raw, 0);
public override string ToString() => Convert.ToHexString(raw);
public override readonly bool Equals(object obj) => obj is Int256 other && this == other;
public override readonly int GetHashCode() => BitConverter.ToInt32(raw, 0);
public override readonly string ToString() => Convert.ToHexString(raw);
public static implicit operator byte[](Int256 int256) => int256.raw;
}
@ -369,7 +371,6 @@ namespace TL
public object result;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006")]
[TLDef(0x5BB8E511)] //message#5bb8e511 msg_id:long seqno:int bytes:int body:Object = Message
public class _Message
{