diff --git a/BeefLibs/corlib/src/Security/Cryptography/MD5.bf b/BeefLibs/corlib/src/Security/Cryptography/MD5.bf index c79a0fd6..ed06f179 100644 --- a/BeefLibs/corlib/src/Security/Cryptography/MD5.bf +++ b/BeefLibs/corlib/src/Security/Cryptography/MD5.bf @@ -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 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(); + } } }