Removed dependency on Crc32.NET

This commit is contained in:
Wizou 2021-08-24 10:49:32 +02:00
parent 593463f46b
commit 53ee143a1d
4 changed files with 10 additions and 5 deletions

View file

@ -27,7 +27,7 @@ Then it will attempt to sign-in as a user for which you must enter the **phone_n
If the verification succeeds but the phone number is unknown to Telegram, the user might be prompted to sign-up (accepting the Terms of Service) and enter their **first_name** and **last_name**.
And that's it, you now have access to the full range of Telegram services, mainly through calls to `await client.Some_TL_Method(...)`
And that's it, you now have access to the [full range of Telegram services](https://core.telegram.org/methods), mainly through calls to `await client.Some_TL_Method(...)`
# Saved session
If you run this program again, you will notice that the previous prompts are gone and you are automatically logged-on and ready to go.

View file

@ -234,7 +234,7 @@ namespace WTelegram
var buffer = memStream.GetBuffer();
int frameLength = (int)memStream.Length;
BinaryPrimitives.WriteInt32LittleEndian(buffer, frameLength + 4); // patch frame_len with correct value
uint crc = Force.Crc32.Crc32Algorithm.Compute(buffer, 0, frameLength);
uint crc = Helpers.UpdateCrc32(0, buffer, 0, frameLength);
writer.Write(crc); // int32 frame_crc
//TODO: support Transport obfuscation?
@ -277,8 +277,8 @@ namespace WTelegram
var payload = new byte[length];
if (await FullReadAsync(_networkStream, payload, length, ct) != length)
throw new ApplicationException("Could not read frame data : Connection shut down");
uint crc32 = Force.Crc32.Crc32Algorithm.Compute(frame, 0, 8);
crc32 = Force.Crc32.Crc32Algorithm.Append(crc32, payload);
uint crc32 = Helpers.UpdateCrc32(0, frame, 0, 8);
crc32 = Helpers.UpdateCrc32(crc32, payload, 0, payload.Length);
if (await FullReadAsync(_networkStream, frame, 4, ct) != 4)
throw new ApplicationException("Could not read frame CRC : Connection shut down");
if (crc32 != BinaryPrimitives.ReadUInt32LittleEndian(frame))

View file

@ -189,5 +189,11 @@ namespace WTelegram
}
return true;
}
// see also https://github.com/dotnet/runtime/issues/2036 and https://github.com/dotnet/runtime/pull/53623
internal static readonly Func<uint, byte[], int, int, uint> UpdateCrc32 = (Func<uint, byte[], int, int, uint>)
typeof(System.IO.Compression.ZipArchive).Assembly.GetType("System.IO.Compression.Crc32Helper")
.GetMethod("UpdateCrc32", new[] { typeof(uint), typeof(byte[]), typeof(int), typeof(int) })
.CreateDelegate(typeof(Func<uint, byte[], int, int, uint>));
}
}

View file

@ -40,7 +40,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Crc32.NET" Version="1.2.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>