1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-19 08:30:25 +02:00

Add Stream support to MD5

This commit is contained in:
disarray2077 2022-01-01 20:58:24 -03:00 committed by GitHub
parent 7a4a7bd2fb
commit 152cb8321e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,5 @@
using system.IO;
namespace System.Security.Cryptography
{
struct HashEncode
@ -343,5 +345,26 @@ namespace System.Security.Cryptography
md5.Update(data);
return md5.Finish();
}
public static Result<MD5Hash> Hash(Stream stream)
{
let md5 = scope MD5();
loop: while (true)
{
uint8[4096] buffer;
switch (stream.TryRead(.(&buffer, 4096)))
{
case .Ok(let bytes):
if (bytes == 0)
break loop;
md5.Update(.(&buffer, bytes));
case .Err(let err):
return .Err(err);
}
}
return md5.Finish();
}
}
}