diff --git a/vlib/crypto/md5/md5.v b/vlib/crypto/md5/md5.v index 2bd9bc87d2..83f4470cc5 100644 --- a/vlib/crypto/md5/md5.v +++ b/vlib/crypto/md5/md5.v @@ -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 { diff --git a/vlib/crypto/sha1/sha1.v b/vlib/crypto/sha1/sha1.v index 45f6dd14c5..0795c88435 100644 --- a/vlib/crypto/sha1/sha1.v +++ b/vlib/crypto/sha1/sha1.v @@ -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 { diff --git a/vlib/crypto/sha256/sha256.v b/vlib/crypto/sha256/sha256.v index e6447b4dfa..467db5f412 100644 --- a/vlib/crypto/sha256/sha256.v +++ b/vlib/crypto/sha256/sha256.v @@ -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 { diff --git a/vlib/crypto/sha512/sha512.v b/vlib/crypto/sha512/sha512.v index 9f3db5f742..e669843972 100644 --- a/vlib/crypto/sha512/sha512.v +++ b/vlib/crypto/sha512/sha512.v @@ -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 {