mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
crypto: make sum methods safe
This commit is contained in:
committed by
Alexander Medvednikov
parent
a1f0e940b7
commit
918edad525
@@ -124,20 +124,21 @@ fn (d mut Digest) write(p_ []byte) ?int {
|
||||
return nn
|
||||
}
|
||||
|
||||
fn (d &Digest) sum(b_in mut []byte) []byte {
|
||||
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()
|
||||
mut b_out := b_in.clone()
|
||||
if d0.is224 {
|
||||
for b in hash.left(Size224) {
|
||||
b_in << b
|
||||
b_out << b
|
||||
}
|
||||
} else {
|
||||
for b in hash {
|
||||
b_in << b
|
||||
b_out << b
|
||||
}
|
||||
}
|
||||
return *b_in
|
||||
return b_out
|
||||
}
|
||||
|
||||
fn (d mut Digest) checksum() []byte {
|
||||
|
||||
Reference in New Issue
Block a user