mirror of https://github.com/docker/docs.git
Use concrete error types rather than generic errors
Use concrete error types for functions "CheckHashes" and "CheckValidHashStructures". Signed-off-by: Hu Keping <hukeping@huawei.com>
This commit is contained in:
parent
a20c92c85f
commit
52ffe6172d
|
@ -141,13 +141,13 @@ func CheckHashes(payload []byte, hashes Hashes) error {
|
||||||
case notary.SHA256:
|
case notary.SHA256:
|
||||||
checksum := sha256.Sum256(payload)
|
checksum := sha256.Sum256(payload)
|
||||||
if subtle.ConstantTimeCompare(checksum[:], v) == 0 {
|
if subtle.ConstantTimeCompare(checksum[:], v) == 0 {
|
||||||
return fmt.Errorf("%s checksum mismatched", k)
|
return ErrMismatchedChecksum{alg: notary.SHA256}
|
||||||
}
|
}
|
||||||
cnt++
|
cnt++
|
||||||
case notary.SHA512:
|
case notary.SHA512:
|
||||||
checksum := sha512.Sum512(payload)
|
checksum := sha512.Sum512(payload)
|
||||||
if subtle.ConstantTimeCompare(checksum[:], v) == 0 {
|
if subtle.ConstantTimeCompare(checksum[:], v) == 0 {
|
||||||
return fmt.Errorf("%s checksum mismatched", k)
|
return ErrMismatchedChecksum{alg: notary.SHA512}
|
||||||
}
|
}
|
||||||
cnt++
|
cnt++
|
||||||
}
|
}
|
||||||
|
@ -169,12 +169,12 @@ func CheckValidHashStructures(hashes Hashes) error {
|
||||||
switch k {
|
switch k {
|
||||||
case notary.SHA256:
|
case notary.SHA256:
|
||||||
if len(v) != sha256.Size {
|
if len(v) != sha256.Size {
|
||||||
return fmt.Errorf("invalid %s checksum", notary.SHA256)
|
return ErrInvalidChecksum{alg: notary.SHA256}
|
||||||
}
|
}
|
||||||
cnt++
|
cnt++
|
||||||
case notary.SHA512:
|
case notary.SHA512:
|
||||||
if len(v) != sha512.Size {
|
if len(v) != sha512.Size {
|
||||||
return fmt.Errorf("invalid %s checksum", notary.SHA512)
|
return ErrInvalidChecksum{alg: notary.SHA512}
|
||||||
}
|
}
|
||||||
cnt++
|
cnt++
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue