From 52ffe6172d35ce9144088dfade682c0f170f3ce9 Mon Sep 17 00:00:00 2001 From: HuKeping Date: Mon, 4 Apr 2016 00:57:08 +0800 Subject: [PATCH] Use concrete error types rather than generic errors Use concrete error types for functions "CheckHashes" and "CheckValidHashStructures". Signed-off-by: Hu Keping --- tuf/data/types.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tuf/data/types.go b/tuf/data/types.go index 2a61b3f561..a664e0d9b1 100644 --- a/tuf/data/types.go +++ b/tuf/data/types.go @@ -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++ }