From 7344f4e3da9becee44a939e9bfbe8259ee0d86bc Mon Sep 17 00:00:00 2001 From: HuKeping Date: Sat, 27 Feb 2016 11:06:08 +0800 Subject: [PATCH] [PATCH 1/8] Create constants for sha256 and sha512 Signed-off-by: Hu Keping --- const.go | 4 ++++ tuf/data/types.go | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/const.go b/const.go index 566c7f0fbd..cc15a935e9 100644 --- a/const.go +++ b/const.go @@ -20,6 +20,10 @@ const ( PubCertPerms = 0755 // Sha256HexSize is how big a Sha256 hex is in number of characters Sha256HexSize = 64 + // SHA256 is the name of SHA256 hash algorithm + SHA256 = "sha256" + // SHA512 is the name of SHA512 hash algorithm + SHA512 = "sha512" // TrustedCertsDir is the directory, under the notary repo base directory, where trusted certs are stored TrustedCertsDir = "trusted_certificates" // PrivDir is the directory, under the notary repo base directory, where private keys are stored diff --git a/tuf/data/types.go b/tuf/data/types.go index 4de55c4e1c..1bff3ef9fd 100644 --- a/tuf/data/types.go +++ b/tuf/data/types.go @@ -119,6 +119,9 @@ type Files map[string]FileMeta // and target file type Hashes map[string][]byte +// NotaryDefaultHashes contains the default supported hash algorithms. +var NotaryDefaultHashes = []string{notary.SHA256, notary.SHA512} + // FileMeta contains the size and hashes for a metadata or target file. Custom // data can be optionally added. type FileMeta struct { @@ -137,12 +140,12 @@ func NewFileMeta(r io.Reader, hashAlgorithms ...string) (FileMeta, error) { for _, hashAlgorithm := range hashAlgorithms { var h hash.Hash switch hashAlgorithm { - case "sha256": + case notary.SHA256: h = sha256.New() - case "sha512": + case notary.SHA512: h = sha512.New() default: - return FileMeta{}, fmt.Errorf("Unknown Hash Algorithm: %s", hashAlgorithm) + return FileMeta{}, fmt.Errorf("Unknown hash algorithm: %s", hashAlgorithm) } hashes[hashAlgorithm] = h r = io.TeeReader(r, h)