Compare commits

..

2 commits

Author SHA1 Message Date
Wizou bfc8e0e1b5 .NET 10 compatibility
Some checks failed
Dev build / build (push) Has been cancelled
2025-11-15 19:39:10 +01:00
Wizou e923d65d53 Clamp TL stamps to 0..int.MaxValue, mapping edge to DateTime.Min/MaxValueaa 2025-11-15 18:21:15 +01:00
2 changed files with 9 additions and 8 deletions

View file

@ -304,8 +304,8 @@ j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB
var output = new byte[input.Length];
var prevBytes = (byte[])aes_iv.Clone();
var span = MemoryMarshal.Cast<byte, long>(input);
var sout = MemoryMarshal.Cast<byte, long>(output);
var prev = MemoryMarshal.Cast<byte, long>(prevBytes);
var sout = MemoryMarshal.Cast<byte, long>(output.AsSpan());
var prev = MemoryMarshal.Cast<byte, long>(prevBytes.AsSpan());
if (!encrypt) { (prev[2], prev[0]) = (prev[0], prev[2]); (prev[3], prev[1]) = (prev[1], prev[3]); }
for (int i = 0, count = input.Length / 8; i < count;)
{
@ -556,7 +556,7 @@ 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.AsSpan());
for (offset = 0, count /= 8; offset < count;)
{
prev[0] ^= span[offset]; prev[1] ^= span[offset + 1];

View file

@ -325,13 +325,14 @@ namespace TL
}
internal static void WriteTLStamp(this BinaryWriter writer, DateTime datetime)
=> writer.Write(datetime == DateTime.MaxValue ? int.MaxValue : (int)(datetime.ToUniversalTime().Ticks / 10000000 - 62135596800L));
=> writer.Write((int)Math.Min(Math.Max(datetime.ToUniversalTime().Ticks / 10000000 - 62135596800L, 0), int.MaxValue));
internal static DateTime ReadTLStamp(this BinaryReader reader)
internal static DateTime ReadTLStamp(this BinaryReader reader) => reader.ReadInt32() switch
{
int unixstamp = reader.ReadInt32();
return unixstamp == int.MaxValue ? DateTime.MaxValue : new((unixstamp + 62135596800L) * 10000000, DateTimeKind.Utc);
}
<= 0 => default,
int.MaxValue => DateTime.MaxValue,
int unixstamp => new((unixstamp + 62135596800L) * 10000000, DateTimeKind.Utc)
};
internal static void WriteTLString(this BinaryWriter writer, string str)
{