From b68311d777c444897d041d8bd42df366f1ba85f3 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Tue, 16 Jul 2024 19:45:57 +0900 Subject: [PATCH] core/crypto/hash: Make the `_to_buffer` routines return the hash slice Quality of life improvement. --- core/crypto/hash/hash.odin | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/crypto/hash/hash.odin b/core/crypto/hash/hash.odin index e4b3d4be1..f7671270a 100644 --- a/core/crypto/hash/hash.odin +++ b/core/crypto/hash/hash.odin @@ -28,20 +28,26 @@ hash_bytes :: proc(algorithm: Algorithm, data: []byte, allocator := context.allo // hash_string_to_buffer will hash the given input and assign the // computed digest to the third parameter. It requires that the -// destination buffer is at least as big as the digest size. -hash_string_to_buffer :: proc(algorithm: Algorithm, data: string, hash: []byte) { - hash_bytes_to_buffer(algorithm, transmute([]byte)(data), hash) +// destination buffer is at least as big as the digest size. The +// provided destination buffer is returned to match the behavior of +// `hash_string`. +hash_string_to_buffer :: proc(algorithm: Algorithm, data: string, hash: []byte) -> []byte { + return hash_bytes_to_buffer(algorithm, transmute([]byte)(data), hash) } // hash_bytes_to_buffer will hash the given input and write the // computed digest into the third parameter. It requires that the -// destination buffer is at least as big as the digest size. -hash_bytes_to_buffer :: proc(algorithm: Algorithm, data, hash: []byte) { +// destination buffer is at least as big as the digest size. The +// provided destination buffer is returned to match the behavior of +// `hash_bytes`. +hash_bytes_to_buffer :: proc(algorithm: Algorithm, data, hash: []byte) -> []byte { ctx: Context init(&ctx, algorithm) update(&ctx, data) final(&ctx, hash) + + return hash } // hash_stream will incrementally fully consume a stream, and return the