mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Fix #197: wrong MD5 encoding in UploadFileAsync
This commit is contained in:
parent
9e92d3d814
commit
4a1b2f5f91
|
|
@ -2,7 +2,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -40,7 +39,7 @@ namespace WTelegram
|
|||
{
|
||||
bool hasLength = stream.CanSeek;
|
||||
long transmitted = 0, length = hasLength ? stream.Length : -1;
|
||||
bool isBig = hasLength ? length >= 10 * 1024 * 1024 : true;
|
||||
bool isBig = !hasLength || length >= 10 * 1024 * 1024;
|
||||
int file_total_parts = hasLength ? (int)((length - 1) / FilePartSize) + 1 : -1;
|
||||
long file_id = Helpers.RandomLong();
|
||||
int file_part = 0, read;
|
||||
|
|
@ -92,7 +91,7 @@ namespace WTelegram
|
|||
await Task.WhenAll(remainingTasks); // wait completion and eventually propagate any task exception
|
||||
if (!isBig) md5.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
|
||||
return isBig ? new InputFileBig { id = file_id, parts = file_total_parts, name = filename }
|
||||
: new InputFile { id = file_id, parts = file_total_parts, name = filename, md5_checksum = md5.Hash };
|
||||
: new InputFile { id = file_id, parts = file_total_parts, name = filename, md5_checksum = Convert.ToHexString(md5.Hash).ToLower() };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ namespace WTelegram
|
|||
public long? ContentLength;
|
||||
protected readonly Stream _innerStream;
|
||||
public override bool CanRead => _innerStream.CanRead;
|
||||
public override bool CanSeek => _innerStream.CanSeek;
|
||||
public override bool CanSeek => ContentLength.HasValue || _innerStream.CanSeek;
|
||||
public override bool CanWrite => _innerStream.CanWrite;
|
||||
public override long Length => ContentLength ?? _innerStream.Length;
|
||||
public override long Position { get => _innerStream.Position; set => _innerStream.Position = value; }
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ namespace TL
|
|||
/// <summary>Full name of the file</summary>
|
||||
public string name;
|
||||
/// <summary>In case the file's <a href="https://en.wikipedia.org/wiki/MD5#MD5_hashes">md5-hash</a> was passed, contents of the file will be checked prior to use</summary>
|
||||
public byte[] md5_checksum;
|
||||
public string md5_checksum;
|
||||
|
||||
/// <summary>Random file identifier created by the client</summary>
|
||||
public override long ID { get => id; set => id = value; }
|
||||
|
|
@ -5481,7 +5481,7 @@ namespace TL
|
|||
/// <summary>Number of saved parts</summary>
|
||||
public int parts;
|
||||
/// <summary>In case <a href="https://en.wikipedia.org/wiki/MD5">md5-HASH</a> of the (already encrypted) file was transmitted, file content will be checked prior to use</summary>
|
||||
public byte[] md5_checksum;
|
||||
public string md5_checksum;
|
||||
/// <summary>32-bit fingerprint of the key used to encrypt a file</summary>
|
||||
public int key_fingerprint;
|
||||
|
||||
|
|
@ -10806,7 +10806,7 @@ namespace TL
|
|||
/// <summary>Secure file part count</summary>
|
||||
public int parts;
|
||||
/// <summary>MD5 hash of encrypted uploaded file, to be checked server-side</summary>
|
||||
public byte[] md5_checksum;
|
||||
public string md5_checksum;
|
||||
/// <summary>File hash</summary>
|
||||
public byte[] file_hash;
|
||||
/// <summary>Secret</summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue