Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Nov 4, 2024
1 parent 3e632e5 commit 8d7d390
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions export_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package openssl

var ErrOpen = errOpen

var TestNotMarshalable = &testNotMarshalable
4 changes: 4 additions & 0 deletions hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,14 @@ func SHA3_512(p []byte) (sum [64]byte) {
}

var isMarshallableCache sync.Map
var testNotMarshalable bool // Used in tests.

// isHashMarshallable returns true if the memory layout of cb
// is known by this library and can therefore be marshalled.
func isHashMarshallable(ch crypto.Hash) bool {
if testNotMarshalable {
return false
}
if vMajor == 1 {
return true
}
Expand Down
21 changes: 21 additions & 0 deletions hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ func cryptoToHash(h crypto.Hash) func() hash.Hash {
return nil
}

func TestHashNotMarshalable(t *testing.T) {
h := openssl.NewSHA256()
state, err := h.(encoding.BinaryMarshaler).MarshalBinary()
if err != nil {
t.Fatal(err)
}
*openssl.TestNotMarshalable = true
defer func() {
*openssl.TestNotMarshalable = false
}()

_, err = h.(encoding.BinaryMarshaler).MarshalBinary()
if err == nil {
t.Error("expected error")
}
err = h.(encoding.BinaryUnmarshaler).UnmarshalBinary(state)
if err == nil {
t.Error("expected error")
}
}

func TestHash(t *testing.T) {
msg := []byte("testing")
var tests = []struct {
Expand Down

0 comments on commit 8d7d390

Please sign in to comment.