The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 197c92016b890df7b54ebf6a45332f5f2ed77177
parent c7b0a929f568b1feb8d43df4498dd9b32f98187c
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Thu, 21 Apr 2022 10:49:34 +0200

remove hash::finish

Previously there where two ways of obtaining a hash sum. Write,
sum, close; and write, finish. Sometimes this may lead to double freeing
the resources when defering the close, but using finish instead of sum.

This commit removes the finish method, so that there's only one way to
use the hash API to obtain the sum, and hence trying to avoid such
misuse of the API.

Signed-off-by: Armin Preiml <apreiml@strohwolke.at>

Mhash/hash.ha | 10+---------
1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/hash/hash.ha b/hash/hash.ha @@ -22,8 +22,7 @@ export type hash = struct { // Internal block size of the hash. Writing data to the hash // function in chunks of this size will not require padding to - // obtain the final hash, such that [[hash::sum]] shall return - // the same checksum as [[hash::finish]]. + // obtain the final hash. bsz: size, }; @@ -31,13 +30,6 @@ export type hash = struct { export fn write(h: *hash, buf: const []u8) size = io::write(h, buf) as size; -// Finalizes the hash, frees resources associated with the hash, and populate -// buf with the sum. -export fn finish(h: *hash, buf: []u8) void = { - sum(h, buf); - io::close(h); -}; - // Closes a hash, freeing its resources and discarding the checksum. export fn close(h: *hash) void = io::close(h);