File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,11 @@ func (s *SigningMethodKMS) Override() {
97
97
})
98
98
}
99
99
100
+ // Hash will return the crypto.Hash used for this signing method
101
+ func (s * SigningMethodKMS ) Hash () crypto.Hash {
102
+ return s .hasher
103
+ }
104
+
100
105
// Sign implements the Sign method from jwt.SigningMethod. For this signing method, a valid context.Context must be
101
106
// passed as the key containing a KMSConfig value.
102
107
// https://cloud.google.com/kms/docs/create-validate-signatures#kms-howto-sign-go
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package gcpjwt
2
2
3
3
import (
4
4
"context"
5
+ "crypto"
5
6
"encoding/json"
6
7
"fmt"
7
8
"io/ioutil"
@@ -243,3 +244,38 @@ func TestSigningMethodKMS_Sign(t *testing.T) {
243
244
})
244
245
}
245
246
}
247
+
248
+ func TestSigningMethodKMS_Hash (t * testing.T ) {
249
+ type fields struct {
250
+ alg string
251
+ override jwt.SigningMethod
252
+ hasher crypto.Hash
253
+ }
254
+ tests := []struct {
255
+ name string
256
+ fields fields
257
+ want crypto.Hash
258
+ }{
259
+ {
260
+ "SimpleTest" ,
261
+ fields {
262
+ "RS256" ,
263
+ jwt .SigningMethodRS256 ,
264
+ jwt .SigningMethodRS256 .Hash ,
265
+ },
266
+ jwt .SigningMethodRS256 .Hash ,
267
+ },
268
+ }
269
+ for _ , tt := range tests {
270
+ t .Run (tt .name , func (t * testing.T ) {
271
+ s := & SigningMethodKMS {
272
+ alg : tt .fields .alg ,
273
+ override : tt .fields .override ,
274
+ hasher : tt .fields .hasher ,
275
+ }
276
+ if got := s .Hash (); got != tt .want {
277
+ t .Errorf ("SigningMethodKMS.Hash() = %v, want %v" , got , tt .want )
278
+ }
279
+ })
280
+ }
281
+ }
You can’t perform that action at this time.
0 commit comments