Commit 9abe392647

George Zhao <zhaozg@gmail.com>
2023-07-17 12:02:57
std.crypto: add finalResult and peek api for Sha1 (#16426)
close #16250
1 parent a576082
Changed files (1)
lib
std
crypto
lib/std/crypto/sha1.zig
@@ -80,6 +80,11 @@ pub const Sha1 = struct {
         d.total_len += b.len;
     }
 
+    pub fn peek(d: Self) [digest_length]u8 {
+        var copy = d;
+        return copy.finalResult();
+    }
+
     pub fn final(d: *Self, out: *[digest_length]u8) void {
         // The buffer here will never be completely full.
         @memset(d.buf[d.buf_len..], 0);
@@ -110,6 +115,12 @@ pub const Sha1 = struct {
         }
     }
 
+    pub fn finalResult(d: *Self) [digest_length]u8 {
+        var result: [digest_length]u8 = undefined;
+        d.final(&result);
+        return result;
+    }
+
     fn round(d: *Self, b: *const [64]u8) void {
         var s: [16]u32 = undefined;