@@ -38,7 +38,7 @@ var signingKeyHeader = "kid"
38
38
// RequestSigner exposes an interface for digitally signing requests using an RSA private key.
39
39
// See comments for the Sign() method below, for more on how this signature is constructed.
40
40
type RequestSigner struct {
41
- hasher hash.Hash
41
+ newHasher func () hash.Hash
42
42
signingKey crypto.Signer
43
43
publicKeyStr string
44
44
publicKeyID string
@@ -79,7 +79,7 @@ func NewRequestSigner(signingKeyPemStr string) (*RequestSigner, error) {
79
79
keyHash = hasher .Sum (keyHash )
80
80
81
81
return & RequestSigner {
82
- hasher : sha256 .New (),
82
+ newHasher : func () hash. Hash { return sha256 .New () } ,
83
83
signingKey : privateKey ,
84
84
publicKeyStr : string (publicKeyPEM ),
85
85
publicKeyID : hex .EncodeToString (keyHash ),
@@ -168,9 +168,10 @@ func (signer RequestSigner) Sign(req *http.Request) error {
168
168
169
169
// Generate hash of the document buffer.
170
170
var documentHash []byte
171
- signer .hasher .Reset ()
172
- _ , _ = signer .hasher .Write ([]byte (repr ))
173
- documentHash = signer .hasher .Sum (documentHash )
171
+ hasher := signer .newHasher ()
172
+ hasher .Reset ()
173
+ _ , _ = hasher .Write ([]byte (repr ))
174
+ documentHash = hasher .Sum (documentHash )
174
175
175
176
// Sign the documentHash with the signing key.
176
177
signatureBytes , err := signer .signingKey .Sign (rand .Reader , documentHash , crypto .SHA256 )
0 commit comments