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:
HuKeping 2016-04-04 00:57:08 +08:00
parent a20c92c85f
commit 52ffe6172d
1 changed files with 4 additions and 4 deletions

View File

@ -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++
}