Merge pull request #192 from dmcgowan/remove-unsupported-hashes
Replace unsupported hashes with supported
This commit is contained in:
commit
5a080c8265
3 changed files with 10 additions and 11 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue