summaryrefslogtreecommitdiff
path: root/pkg/integrity/digest.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/integrity/digest.go')
-rw-r--r--pkg/integrity/digest.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/pkg/integrity/digest.go b/pkg/integrity/digest.go
index 5b1ff2c..0783ed6 100644
--- a/pkg/integrity/digest.go
+++ b/pkg/integrity/digest.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2020-2021, Sylabs Inc. All rights reserved.
+// Copyright (c) 2020-2022, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file
// distributed with the sources of this project regarding your rights to use or distribute this
// software.
@@ -22,12 +22,14 @@ var (
errDigestMalformed = errors.New("digest malformed")
)
-var supportedAlgorithms = map[crypto.Hash]string{
- crypto.SHA1: "sha1",
- crypto.SHA224: "sha224",
- crypto.SHA256: "sha256",
- crypto.SHA384: "sha384",
- crypto.SHA512: "sha512",
+// Hash functions supported for digests.
+var supportedDigestAlgorithms = map[crypto.Hash]string{
+ crypto.SHA224: "sha224",
+ crypto.SHA256: "sha256",
+ crypto.SHA384: "sha384",
+ crypto.SHA512: "sha512",
+ crypto.SHA512_224: "sha512_224",
+ crypto.SHA512_256: "sha512_256",
}
// hashValue calculates a digest by applying hash function h to the contents read from r. If h is
@@ -52,7 +54,7 @@ type digest struct {
// newDigest returns a new digest. If h is not supported, errHashUnsupported is returned. If digest
// is malformed, errDigestMalformed is returned.
func newDigest(h crypto.Hash, value []byte) (digest, error) {
- if _, ok := supportedAlgorithms[h]; !ok {
+ if _, ok := supportedDigestAlgorithms[h]; !ok {
return digest{}, errHashUnsupported
}
@@ -78,8 +80,8 @@ func newDigestReader(h crypto.Hash, r io.Reader) (digest, error) {
// For reference, the plaintext of legacy signatures is comprised of the string "SIFHASH:\n",
// followed by a digest value. For example:
//
-// SIFHASH:
-// 2f0b3dca0ec42683d306338f68689aba29cdb83625b8cc0b8a789f8de92342495a6264b0c134e706630636bf90c6f331
+// SIFHASH:
+// 2f0b3dca0ec42683d306338f68689aba29cdb83625b8cc0b8a789f8de92342495a6264b0c134e706630636bf90c6f331
func newLegacyDigest(ht crypto.Hash, b []byte) (digest, error) {
b = bytes.TrimPrefix(b, []byte("SIFHASH:\n"))
b = bytes.TrimSuffix(b, []byte("\n"))
@@ -104,7 +106,7 @@ func (d digest) matches(r io.Reader) (bool, error) {
// MarshalJSON marshals d into string of format "alg:value".
func (d digest) MarshalJSON() ([]byte, error) {
- n, ok := supportedAlgorithms[d.hash]
+ n, ok := supportedDigestAlgorithms[d.hash]
if !ok {
return nil, errHashUnsupported
}
@@ -130,7 +132,7 @@ func (d *digest) UnmarshalJSON(data []byte) error {
return fmt.Errorf("%w: %v", errDigestMalformed, err)
}
- for h, n := range supportedAlgorithms {
+ for h, n := range supportedDigestAlgorithms {
if n == name {
digest, err := newDigest(h, v)
if err != nil {