From 9abe39264724934f3d3f657912d5ac62d97c26a8 Mon Sep 17 00:00:00 2001 From: George Zhao Date: Mon, 17 Jul 2023 18:02:57 +0800 Subject: [PATCH] std.crypto: add finalResult and peek api for Sha1 (#16426) close #16250 --- lib/std/crypto/sha1.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/std/crypto/sha1.zig b/lib/std/crypto/sha1.zig index 82e23e0647..429b2e64f2 100644 --- a/lib/std/crypto/sha1.zig +++ b/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;