mirror of
https://github.com/docker/docs.git
synced 2026-11-05 00:14:17 +03:00
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:
@@ -141,13 +141,13 @@ func CheckHashes(payload []byte, hashes Hashes) error {
|
||||
case notary.SHA256:
|
||||
checksum := sha256.Sum256(payload)
|
||||
if subtle.ConstantTimeCompare(checksum[:], v) == 0 {
|
||||
return fmt.Errorf("%s checksum mismatched", k)
|
||||
return ErrMismatchedChecksum{alg: notary.SHA256}
|
||||
}
|
||||
cnt++
|
||||
case notary.SHA512:
|
||||
checksum := sha512.Sum512(payload)
|
||||
if subtle.ConstantTimeCompare(checksum[:], v) == 0 {
|
||||
return fmt.Errorf("%s checksum mismatched", k)
|
||||
return ErrMismatchedChecksum{alg: notary.SHA512}
|
||||
}
|
||||
cnt++
|
||||
}
|
||||
@@ -169,12 +169,12 @@ func CheckValidHashStructures(hashes Hashes) error {
|
||||
switch k {
|
||||
case notary.SHA256:
|
||||
if len(v) != sha256.Size {
|
||||
return fmt.Errorf("invalid %s checksum", notary.SHA256)
|
||||
return ErrInvalidChecksum{alg: notary.SHA256}
|
||||
}
|
||||
cnt++
|
||||
case notary.SHA512:
|
||||
if len(v) != sha512.Size {
|
||||
return fmt.Errorf("invalid %s checksum", notary.SHA512)
|
||||
return ErrInvalidChecksum{alg: notary.SHA512}
|
||||
}
|
||||
cnt++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user