mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-19 00:20:25 +02:00
Add Stream support to MD5
This commit is contained in:
parent
7a4a7bd2fb
commit
152cb8321e
1 changed files with 23 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue