diff --git a/vlib/crypto/sha256/sha256.v b/vlib/crypto/sha256/sha256.v index af37727c7d..c8ea3a8e08 100644 --- a/vlib/crypto/sha256/sha256.v +++ b/vlib/crypto/sha256/sha256.v @@ -124,7 +124,7 @@ fn (mut d Digest) write(p_ []byte) ?int { } } -fn (d &Digest) sum(b_in []byte) []byte { +pub fn (d &Digest) sum(b_in []byte) []byte { // Make a copy of d so that caller can keep writing and summing. mut d0 := *d hash := d0.checksum() diff --git a/vlib/crypto/sha256/sha256_test.v b/vlib/crypto/sha256/sha256_test.v index 8aad0001a6..0f4c5ed643 100644 --- a/vlib/crypto/sha256/sha256_test.v +++ b/vlib/crypto/sha256/sha256_test.v @@ -8,3 +8,12 @@ fn test_crypto_sha256() { assert sha256.sum('This is a sha256 checksum.'.bytes()).hex() == 'dc7163299659529eae29683eb1ffec50d6c8fc7275ecb10c145fde0e125b8727' } + +fn test_crypto_sha256_writer() { + mut digest := sha256.new() + digest.write('This is a'.bytes()) or { assert false } + digest.write(' sha256 checksum.'.bytes()) or { assert false } + sum := digest.sum([]) + assert sum.hex() == + 'dc7163299659529eae29683eb1ffec50d6c8fc7275ecb10c145fde0e125b8727' +}