diff --git a/src/Client.cs b/src/Client.cs index 61ca6ed..0b15116 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -594,9 +594,9 @@ namespace WTelegram class Rpc { - public Type type; - public TaskCompletionSource tcs = new(TaskCreationOptions.RunContinuationsAsynchronously); - public long msgId; + internal Type type; + internal TaskCompletionSource tcs = new(TaskCreationOptions.RunContinuationsAsynchronously); + internal long msgId; public Task Task => tcs.Task; } diff --git a/src/Encryption.cs b/src/Encryption.cs index 41ca816..b94edf1 100644 --- a/src/Encryption.cs +++ b/src/Encryption.cs @@ -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(buffer.AsSpan(offset, count)); - var prev = MemoryMarshal.Cast(prevBytes); + var prev = MemoryMarshal.Cast(_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]; diff --git a/src/Session.cs b/src/Session.cs index 535374b..d09b99d 100644 --- a/src/Session.cs +++ b/src/Session.cs @@ -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; } diff --git a/src/TL.Extensions.cs b/src/TL.Extensions.cs index 0e2a7fe..58fb5be 100644 --- a/src/TL.Extensions.cs +++ b/src/TL.Extensions.cs @@ -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 entityToMD = new() + static readonly Dictionary 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, $""); if (tag[0] == 'a') @@ -397,7 +397,7 @@ namespace TL return sb.ToString(); } - static readonly Dictionary entityToTag = new() + static readonly Dictionary EntityToTag = new() { [typeof(MessageEntityBold)] = "b", [typeof(MessageEntityItalic)] = "i", diff --git a/src/TL.MTProto.cs b/src/TL.MTProto.cs index d4623f1..d6313b1 100644 --- a/src/TL.MTProto.cs +++ b/src/TL.MTProto.cs @@ -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 = 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 { diff --git a/src/TL.Schema.cs b/src/TL.Schema.cs index f6b2a19..6cc28d1 100644 --- a/src/TL.Schema.cs +++ b/src/TL.Schema.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; namespace TL { + #pragma warning disable IDE1006 /// Boolean type. See public enum Bool : uint { @@ -6811,7 +6812,7 @@ namespace TL /// Unknown message entity See [TLDef(0xBB92BA95)] public class MessageEntityUnknown : MessageEntity { } - /// Message entity mentioning the current user See + /// Message entity mentioning a user by @username; can also be used to mention users by their ID. See [TLDef(0xFA04579D)] public class MessageEntityMention : MessageEntity { } /// #hashtag message entity See diff --git a/src/TL.SchemaFuncs.cs b/src/TL.SchemaFuncs.cs index e8baed5..73ca1c9 100644 --- a/src/TL.SchemaFuncs.cs +++ b/src/TL.SchemaFuncs.cs @@ -5603,6 +5603,7 @@ namespace TL namespace TL.Methods { + #pragma warning disable IDE1006 [TLDef(0xCB9F372D)] public class InvokeAfterMsg : IMethod { diff --git a/src/TL.Secret.cs b/src/TL.Secret.cs index aa35ff2..6ab716a 100644 --- a/src/TL.Secret.cs +++ b/src/TL.Secret.cs @@ -2,6 +2,7 @@ namespace TL { + #pragma warning disable IDE1006 /// Object describes the contents of an encrypted message. See public abstract class DecryptedMessageBase : IObject { diff --git a/src/TL.cs b/src/TL.cs index ba802a7..60d84ba 100644 --- a/src/TL.cs +++ b/src/TL.cs @@ -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 {