diff --git a/evp.go b/evp.go index 1fd08fd..b595ce9 100644 --- a/evp.go +++ b/evp.go @@ -168,7 +168,7 @@ func loadHash(ch crypto.Hash) *hashAlgorithm { hash.md = md } } - hash.marshallable = isHashMarshallable(hash.md) + hash.marshallable = hash.magic != "" && isHashMarshallable(hash.md) cacheMD.Store(ch, &hash) return &hash } diff --git a/hash.go b/hash.go index a40c2bc..d01dd68 100644 --- a/hash.go +++ b/hash.go @@ -384,7 +384,7 @@ func (d *evpHash) AppendBinary(buf []byte) ([]byte, error) { case crypto.SHA512: appender = (*sha512State)(state) default: - return nil, errors.New("openssl: unsupported hash function: " + strconv.Itoa(int(d.alg.ch))) + panic("openssl: unsupported hash function: " + strconv.Itoa(int(d.alg.ch))) } buf = append(buf, d.alg.magic[:]...) return appender.AppendBinary(buf) @@ -422,7 +422,7 @@ func (d *evpHash) UnmarshalBinary(b []byte) error { case crypto.SHA512: unmarshaler = (*sha512State)(state) default: - return errors.New("openssl: unsupported hash function: " + strconv.Itoa(int(d.alg.ch))) + panic("openssl: unsupported hash function: " + strconv.Itoa(int(d.alg.ch))) } return unmarshaler.UnmarshalBinary(b) } diff --git a/hash_test.go b/hash_test.go index 12b00c3..948be94 100644 --- a/hash_test.go +++ b/hash_test.go @@ -110,7 +110,7 @@ func TestHash_BinaryMarshaler(t *testing.T) { state, err := hashMarshaler.MarshalBinary() if err != nil { - if strings.Contains(err.Error(), "unsupported hash function") { + if strings.Contains(err.Error(), "hash state is not marshallable") { t.Skip("BinaryMarshaler not supported") } t.Fatalf("MarshalBinary failed: %v", err) @@ -160,7 +160,7 @@ func TestHash_BinaryAppender(t *testing.T) { // Append binary data to the prebuilt slice state, err := hashWithBinaryAppender.AppendBinary(prebuiltSlice) if err != nil { - if strings.Contains(err.Error(), "unsupported hash function") { + if strings.Contains(err.Error(), "hash state is not marshallable") { t.Skip("AppendBinary not supported") } t.Errorf("could not append binary: %v", err)