1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

crypto/sha256: make digest sum public (#10047)

This commit is contained in:
Leigh McCulloch 2021-05-08 03:14:37 -07:00 committed by GitHub
parent 600017d7fe
commit cba2cb6b9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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. // Make a copy of d so that caller can keep writing and summing.
mut d0 := *d mut d0 := *d
hash := d0.checksum() hash := d0.checksum()

View File

@ -8,3 +8,12 @@ fn test_crypto_sha256() {
assert sha256.sum('This is a sha256 checksum.'.bytes()).hex() == assert sha256.sum('This is a sha256 checksum.'.bytes()).hex() ==
'dc7163299659529eae29683eb1ffec50d6c8fc7275ecb10c145fde0e125b8727' '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'
}