Skip to content

Commit

Permalink
fix: remove spurious length check
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Lock <jlock@vmware.com>
  • Loading branch information
joshuagl committed Jun 23, 2022
1 parent d73f89f commit 39b9b0f
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,23 @@ func BytesMatchLenAndHashes(fetched []byte, length int64, hashes data.Hashes) er
return ErrWrongLength{length, flen}
}

if len(hashes) != 0 {
for alg, expected := range hashes {
var h hash.Hash
switch alg {
case "sha256":
h = sha256.New()
case "sha512":
h = sha512.New()
default:
return ErrUnknownHashAlgorithm{alg}
}
h.Write(fetched)
hash := h.Sum(nil)
if !hmac.Equal(hash, expected) {
return ErrWrongHash{alg, expected, hash}
}
for alg, expected := range hashes {
var h hash.Hash
switch alg {
case "sha256":
h = sha256.New()
case "sha512":
h = sha512.New()
default:
return ErrUnknownHashAlgorithm{alg}
}
h.Write(fetched)
hash := h.Sum(nil)
if !hmac.Equal(hash, expected) {
return ErrWrongHash{alg, expected, hash}
}
}

return nil
}

Expand Down

0 comments on commit 39b9b0f

Please sign in to comment.