crypto/sha256: make digest sum public (#10047)
							parent
							
								
									600017d7fe
								
							
						
					
					
						commit
						cba2cb6b9c
					
				|  | @ -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() | ||||
|  |  | |||
|  | @ -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' | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue