Replace unsupported hashes with supported

Remote md5 and sha1 hashes which are not supported by distribution.
Add more secure hashes sha384 and sha512.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
Derek McGowan 2015-02-19 17:55:05 -08:00
parent c1840978b7
commit 2289b1f2e8
3 changed files with 10 additions and 11 deletions

View file

@ -123,7 +123,7 @@ func (d Digest) Validate() error {
} }
switch s[:i] { switch s[:i] {
case "md5", "sha1", "sha256": case "sha256", "sha384", "sha512":
break break
default: default:
return ErrDigestUnsupported return ErrDigestUnsupported

View file

@ -34,9 +34,9 @@ func TestParseDigest(t *testing.T) {
hex: "e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b", hex: "e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b",
}, },
{ {
input: "md5:d41d8cd98f00b204e9800998ecf8427e", input: "sha384:d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d",
algorithm: "md5", algorithm: "sha384",
hex: "d41d8cd98f00b204e9800998ecf8427e", hex: "d3fc7881460b7e22e3d172954463dddd7866d17597e7248453c48b3e9d26d9596bf9c4a9cf8072c9d5bad76e19af801d",
}, },
{ {
// empty hex // empty hex

View file

@ -1,9 +1,8 @@
package digest package digest
import ( import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256" "crypto/sha256"
"crypto/sha512"
"hash" "hash"
"io" "io"
"io/ioutil" "io/ioutil"
@ -32,7 +31,7 @@ type Verifier interface {
func NewDigestVerifier(d Digest) Verifier { func NewDigestVerifier(d Digest) Verifier {
alg := d.Algorithm() alg := d.Algorithm()
switch alg { switch alg {
case "md5", "sha1", "sha256": case "sha256", "sha384", "sha512":
return hashVerifier{ return hashVerifier{
hash: newHash(alg), hash: newHash(alg),
digest: d, digest: d,
@ -97,10 +96,10 @@ func newHash(name string) hash.Hash {
switch name { switch name {
case "sha256": case "sha256":
return sha256.New() return sha256.New()
case "sha1": case "sha384":
return sha1.New() return sha512.New384()
case "md5": case "sha512":
return md5.New() return sha512.New()
default: default:
panic("unsupport algorithm: " + name) panic("unsupport algorithm: " + name)
} }