Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Jul 1, 2024
1 parent 772c1d3 commit 41c8d86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func NewRequest(opts RequestOptions) (*Request, error) {
if err != nil {
return nil, &MalformedRequestError{Msg: err.Error()}
}
parameter := opts.HashAlgorithmParameters
if reflect.DeepEqual(parameter, asn1.RawValue{}) {
parameter = asn1.NullRawValue
hashAlgParameter := opts.HashAlgorithmParameters
if reflect.DeepEqual(hashAlgParameter, asn1.RawValue{}) {
hashAlgParameter = asn1.NullRawValue
}
var nonce *big.Int
if !opts.NoNonce {
Expand All @@ -138,7 +138,7 @@ func NewRequest(opts RequestOptions) (*Request, error) {
MessageImprint: MessageImprint{
HashAlgorithm: pkix.AlgorithmIdentifier{
Algorithm: hashAlg,
Parameters: parameter,
Parameters: hashAlgParameter,
},
HashedMessage: digest,
},
Expand Down
6 changes: 5 additions & 1 deletion request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/asn1"
"errors"
"fmt"
"reflect"
"testing"

"github.com/notaryproject/tspclient-go/internal/hashutil"
Expand Down Expand Up @@ -60,10 +61,13 @@ func TestNewRequest(t *testing.T) {
Content: message,
HashAlgorithm: crypto.SHA256,
}
_, err = NewRequest(opts)
req, err := NewRequest(opts)
if err != nil {
t.Fatalf("expected nil error, but got %v", err)
}
if !reflect.DeepEqual(req.MessageImprint.HashAlgorithm.Parameters, asn1.NullRawValue) {
t.Fatalf("expected %v, but got %v", asn1.NullRawValue, req.MessageImprint.HashAlgorithm.Parameters)
}
}

func TestRequestMarshalBinary(t *testing.T) {
Expand Down

0 comments on commit 41c8d86

Please sign in to comment.