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:
parent
a1f0e940b7
commit
918edad525
@ -87,14 +87,15 @@ pub fn (d mut Digest) write(p_ []byte) ?int {
|
||||
return nn
|
||||
}
|
||||
|
||||
pub fn (d &Digest) sum(b_in mut []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()
|
||||
mut b_out := b_in.clone()
|
||||
for b in hash {
|
||||
b_in << b
|
||||
b_out << b
|
||||
}
|
||||
return *b_in
|
||||
return b_out
|
||||
}
|
||||
|
||||
pub fn (d mut Digest) checksum() []byte {
|
||||
|
@ -91,14 +91,15 @@ pub fn (d mut Digest) write(p_ []byte) ?int {
|
||||
return nn
|
||||
}
|
||||
|
||||
pub fn (d &Digest) sum(b_in mut []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()
|
||||
mut b_out := b_in.clone()
|
||||
for b in hash {
|
||||
b_in << b
|
||||
b_out << b
|
||||
}
|
||||
return *b_in
|
||||
return b_out
|
||||
}
|
||||
|
||||
fn (d mut Digest) checksum() []byte {
|
||||
|
@ -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 {
|
||||
|
@ -178,29 +178,30 @@ fn (d mut Digest) write(p_ []byte) ?int {
|
||||
return nn
|
||||
}
|
||||
|
||||
fn (d mut Digest) sum(b_in mut []byte) []byte {
|
||||
fn (d mut 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()
|
||||
switch d0.function {
|
||||
case crypto.Hash.SHA384:
|
||||
for b in hash.left(Size384) {
|
||||
b_in << b
|
||||
b_out << b
|
||||
}
|
||||
case crypto.Hash.SHA512_224:
|
||||
for b in hash.left(Size224) {
|
||||
b_in << b
|
||||
b_out << b
|
||||
}
|
||||
case crypto.Hash.SHA512_256:
|
||||
for b in hash.left(Size256) {
|
||||
b_in << b
|
||||
b_out << b
|
||||
}
|
||||
default:
|
||||
for b in hash {
|
||||
b_in << b
|
||||
b_out << b
|
||||
}
|
||||
}
|
||||
return *b_in
|
||||
return b_out
|
||||
}
|
||||
|
||||
fn (d mut Digest) checksum() []byte {
|
||||
|
Loading…
Reference in New Issue
Block a user