From 046db8bf1cca4b82cf70d47ed0aec0422e1e9815 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Mon, 9 Oct 2023 18:27:40 -0700 Subject: [PATCH] Add blake2s and blake2b to the list of valid hash algos --- internal/dl/dl.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/dl/dl.go b/internal/dl/dl.go index aa83811..354a3f4 100644 --- a/internal/dl/dl.go +++ b/internal/dl/dl.go @@ -36,9 +36,11 @@ import ( "github.com/PuerkitoBio/purell" "github.com/vmihailenco/msgpack/v5" + "golang.org/x/crypto/blake2b" + "golang.org/x/crypto/blake2s" + "golang.org/x/exp/slices" "lure.sh/lure/internal/dlcache" "lure.sh/lure/pkg/loggerctx" - "golang.org/x/exp/slices" ) const manifestFileName = ".lure_cache_manifest" @@ -91,11 +93,8 @@ type Options struct { } func (opts Options) NewHash() (hash.Hash, error) { - if opts.HashAlgorithm == "" { - opts.HashAlgorithm = "sha256" - } switch opts.HashAlgorithm { - case "sha256": + case "", "sha256": return sha256.New(), nil case "sha224": return sha256.New224(), nil @@ -107,8 +106,17 @@ func (opts Options) NewHash() (hash.Hash, error) { return sha1.New(), nil case "md5": return md5.New(), nil + case "blake2s-128": + return blake2s.New256(nil) + case "blake2s-256": + return blake2s.New256(nil) + case "blake2b-256": + return blake2b.New(32, nil) + case "blake2b-512": + return blake2b.New(64, nil) + default: + return nil, fmt.Errorf("%w: %s", ErrNoSuchHashAlgo, opts.HashAlgorithm) } - return nil, fmt.Errorf("%w: %s", ErrNoSuchHashAlgo, opts.HashAlgorithm) } // Manifest holds information about the type and name