mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2026-02-22 23:44:20 +01:00
net8.0 target, compatible with AOT
This commit is contained in:
parent
9fe1196606
commit
e2323092dc
|
|
@ -918,7 +918,7 @@ namespace WTelegram
|
|||
TLConfig = new Config { this_dc = _session.MainDC, dc_options = _session.DcOptions };
|
||||
else
|
||||
{
|
||||
var initParams = JSONValue.FromJsonElement(System.Text.Json.JsonSerializer.Deserialize<System.Text.Json.JsonElement>(Config("init_params")));
|
||||
var initParams = JSONValue.FromJsonElement(System.Text.Json.JsonDocument.Parse(Config("init_params")).RootElement);
|
||||
TLConfig = await this.InvokeWithLayer(Layer.Version,
|
||||
new TL.Methods.InitConnection<Config>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -76,6 +76,13 @@ static class Convert
|
|||
internal static string ToHexString(byte[] data) => BitConverter.ToString(data).Replace("-", "");
|
||||
internal static byte[] FromHexString(string hex) => Enumerable.Range(0, hex.Length / 2).Select(i => System.Convert.ToByte(hex.Substring(i * 2, 2), 16)).ToArray();
|
||||
}
|
||||
public class RandomNumberGenerator
|
||||
{
|
||||
internal static readonly RNGCryptoServiceProvider RNG = new();
|
||||
public static RandomNumberGenerator Create() => new();
|
||||
public void GetBytes(byte[] data) => RNG.GetBytes(data);
|
||||
public void GetBytes(byte[] data, int offset, int count) => RNG.GetBytes(data, offset, count);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NETSTANDARD2_0
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace WTelegram
|
|||
internal static class Encryption
|
||||
{
|
||||
private static readonly Dictionary<long, RSAPublicKey> PublicKeys = [];
|
||||
internal static readonly RNGCryptoServiceProvider RNG = new();
|
||||
internal static readonly RandomNumberGenerator RNG = RandomNumberGenerator.Create();
|
||||
internal static readonly Aes AesECB = Aes.Create();
|
||||
|
||||
static Encryption()
|
||||
|
|
@ -33,7 +33,7 @@ namespace WTelegram
|
|||
var sha256 = SHA256.Create();
|
||||
|
||||
//1)
|
||||
var nonce = new Int128(RNG);
|
||||
var nonce = new TL.Int128(RNG);
|
||||
var resPQ = await client.ReqPqMulti(nonce);
|
||||
//2)
|
||||
if (resPQ.nonce != nonce) throw new WTException("Nonce mismatch");
|
||||
|
|
@ -164,7 +164,7 @@ namespace WTelegram
|
|||
session.Salt = BinaryPrimitives.ReadInt64LittleEndian(pqInnerData.new_nonce.raw) ^ BinaryPrimitives.ReadInt64LittleEndian(resPQ.server_nonce.raw);
|
||||
session.OldSalt = session.Salt;
|
||||
|
||||
(byte[] key, byte[] iv) ConstructTmpAESKeyIV(Int128 server_nonce, Int256 new_nonce)
|
||||
(byte[] key, byte[] iv) ConstructTmpAESKeyIV(TL.Int128 server_nonce, Int256 new_nonce)
|
||||
{
|
||||
byte[] tmp_aes_key = new byte[32], tmp_aes_iv = new byte[32];
|
||||
sha1.TransformBlock(new_nonce, 0, 32, null, 0);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@ using System.Text.Json;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
[JsonSerializable(typeof(WTelegram.Session))]
|
||||
internal partial class WTelegramContext : JsonSerializerContext { }
|
||||
#endif
|
||||
|
||||
namespace WTelegram
|
||||
{
|
||||
public static class Helpers
|
||||
|
|
@ -16,6 +23,9 @@ namespace WTelegram
|
|||
|
||||
/// <summary>For serializing indented Json with fields included</summary>
|
||||
public static readonly JsonSerializerOptions JsonOptions = new() { IncludeFields = true, WriteIndented = true,
|
||||
#if NET8_0_OR_GREATER
|
||||
TypeInfoResolver = JsonSerializer.IsReflectionEnabledByDefault ? new DefaultJsonTypeInfoResolver() : WTelegramContext.Default,
|
||||
#endif
|
||||
IgnoreReadOnlyProperties = true, DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull };
|
||||
|
||||
private static readonly ConsoleColor[] LogLevelToColor = [ ConsoleColor.DarkGray, ConsoleColor.DarkCyan,
|
||||
|
|
|
|||
|
|
@ -328,8 +328,8 @@ namespace TL
|
|||
{
|
||||
public byte[] raw;
|
||||
|
||||
public Int128(System.IO.BinaryReader reader) => raw = reader.ReadBytes(16);
|
||||
public Int128(RNGCryptoServiceProvider rng) => rng.GetBytes(raw = new byte[16]);
|
||||
public Int128(BinaryReader reader) => raw = reader.ReadBytes(16);
|
||||
public Int128(RandomNumberGenerator 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 readonly bool Equals(object obj) => obj is Int128 other && this == other;
|
||||
|
|
@ -342,8 +342,8 @@ namespace TL
|
|||
{
|
||||
public byte[] raw;
|
||||
|
||||
public Int256(System.IO.BinaryReader reader) => raw = reader.ReadBytes(32);
|
||||
public Int256(RNGCryptoServiceProvider rng) => rng.GetBytes(raw = new byte[32]);
|
||||
public Int256(BinaryReader reader) => raw = reader.ReadBytes(32);
|
||||
public Int256(RandomNumberGenerator 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 readonly bool Equals(object obj) => obj is Int256 other && this == other;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
|
||||
<TargetFrameworks>netstandard2.0;net5.0;net8.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<RootNamespace>WTelegram</RootNamespace>
|
||||
<Deterministic>true</Deterministic>
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
<PackageReleaseNotes>$(ReleaseNotes.Replace("|", "%0D%0A").Replace(" - ","%0D%0A- ").Replace(" ", "%0D%0A%0D%0A"))</PackageReleaseNotes>
|
||||
<NoWarn>0419;1573;1591;NETSDK1138</NoWarn>
|
||||
<DefineConstants>TRACE;OBFUSCATION</DefineConstants>
|
||||
<!--<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>-->
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue