Debian Codegraph @

jwt/jwt_key_templates_test.go

raw symbols SCIP
1 // Copyright 2022 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package jwt_testscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/
16
17 import (
18 "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/"
19 "timescip-go gomod github.com/golang/go/src go1.24.0 time/"
20
21 "github.com/tink-crypto/tink-go/v2/jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/"
22 "github.com/tink-crypto/tink-go/v2/keysetscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/keyset`/"
23
24 tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/ "github.com/tink-crypto/tink-go/v2/proto/tink_go_protoscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/"
25 )
26
27 type templateTestCasescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase# struct {
28 tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag. string
29 templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template. *tinkpbscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/.KeyTemplatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/proto/tink_go_proto`/KeyTemplate#
30 }
31
32 func TestJWTComputeVerifyMACscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/TestJWTComputeVerifyMAC().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
33 expiresAt := timescip-go gomod github.com/golang/go/src go1.24.0 time/.Nowscip-go gomod github.com/golang/go/src go1.24.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.24.0 time/Time#Add().(timescip-go gomod github.com/golang/go/src go1.24.0 time/.Hourscip-go gomod github.com/golang/go/src go1.24.0 time/Hour.)
34 rawJWT, err := jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.NewRawJWTscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/NewRawJWT().(&jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawJWTOptionsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawJWTOptions#{
35 ExpiresAtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawJWTOptions#ExpiresAt.: &expiresAt,
36 })
37 if err != nil {
38 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("NewRawJWT() err = %v, want nil", err)
39 }
40 for _, tc := range []templateTestCasescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#{
41 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_HS256", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.HS256Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/HS256Template().()},
42 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_HS384", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.HS384Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/HS384Template().()},
43 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_HS512", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.HS512Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/HS512Template().()},
44 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_HS256_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawHS256Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawHS256Template().()},
45 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_HS384_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawHS384Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawHS384Template().()},
46 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_HS512_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawHS512Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawHS512Template().()},
47 } {
48 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag., func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
49 handle, err := keysetscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/keyset`/.NewHandlescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/keyset`/NewHandle().(tc.templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.)
50 if err != nil {
51 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("keyset.NewHandle() err = %v, want nil", err)
52 }
53 m, err := jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.NewMACscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/NewMAC().(handle)
54 if err != nil {
55 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("jwt.NewMAC() err = %v, want nil", err)
56 }
57 compact, err := m.ComputeMACAndEncodescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/MAC#ComputeMACAndEncode.(rawJWT)
58 if err != nil {
59 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("m.ComputeMACAndEncode() err = %v, want nil", err)
60 }
61 validator, err := jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.NewValidatorscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/NewValidator().(&jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.ValidatorOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/ValidatorOpts#{})
62 if err != nil {
63 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("jwt.NewValidator() err = %v, want nil", err)
64 }
65 if _, err := m.VerifyMACAndDecodescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/MAC#VerifyMACAndDecode.(compact, validator); err != nil {
66 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("m.VerifyMACAndDecode() err = %v, want nil", err)
67 }
68
69 // In two hours, VerifyMACAndDecode should fail with an expiration error.
70 inTwoHours := timescip-go gomod github.com/golang/go/src go1.24.0 time/.Nowscip-go gomod github.com/golang/go/src go1.24.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.24.0 time/Time#Add().(timescip-go gomod github.com/golang/go/src go1.24.0 time/.Hourscip-go gomod github.com/golang/go/src go1.24.0 time/Hour. * 2)
71 futureValidator, err := jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.NewValidatorscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/NewValidator().(&jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.ValidatorOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/ValidatorOpts#{FixedNowscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/ValidatorOpts#FixedNow.: inTwoHours})
72 if err != nil {
73 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("jwt.NewValidator() err = %v, want nil", err)
74 }
75 _, futureError := m.VerifyMACAndDecodescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/MAC#VerifyMACAndDecode.(compact, futureValidator)
76 if futureError == nil {
77 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("m.VerifyMACAndDecode(compact, futureValidator) err = nil, want error")
78 }
79 if !jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.IsExpirationErrscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/IsExpirationErr().(futureError) {
80 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("jwt.IsExpirationErr(futureError) = false, want true")
81 }
82 })
83 }
84 }
85
86 func TestJWTSignVerifyscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/TestJWTSignVerify().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
87 expiresAt := timescip-go gomod github.com/golang/go/src go1.24.0 time/.Nowscip-go gomod github.com/golang/go/src go1.24.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.24.0 time/Time#Add().(timescip-go gomod github.com/golang/go/src go1.24.0 time/.Hourscip-go gomod github.com/golang/go/src go1.24.0 time/Hour.)
88 rawJWT, err := jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.NewRawJWTscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/NewRawJWT().(&jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawJWTOptionsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawJWTOptions#{
89 ExpiresAtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawJWTOptions#ExpiresAt.: &expiresAt,
90 })
91 if err != nil {
92 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("jwt.NewRawJWT() err = %v, want nil", err)
93 }
94 for _, tc := range []templateTestCasescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#{
95 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_ES256", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.ES256Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/ES256Template().()},
96 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_ES384", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.ES384Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/ES384Template().()},
97 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_ES512", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.ES512Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/ES512Template().()},
98 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_ES256_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawES256Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawES256Template().()},
99 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_ES384_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawES384Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawES384Template().()},
100 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_ES512_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawES512Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawES512Template().()},
101 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_RS256_2048_R4", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RS256_2048_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RS256_2048_F4_Key_Template().()},
102 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_RS256_2048_R4_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawRS256_2048_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawRS256_2048_F4_Key_Template().()},
103 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_RS256_3072_R4", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RS256_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RS256_3072_F4_Key_Template().()},
104 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_RS256_3072_R4_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawRS256_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawRS256_3072_F4_Key_Template().()},
105 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_RS384_3072_R4", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RS384_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RS384_3072_F4_Key_Template().()},
106 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_RS384_3072_R4_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawRS384_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawRS384_3072_F4_Key_Template().()},
107 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_RS512_4096_R4", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RS512_4096_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RS512_4096_F4_Key_Template().()},
108 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_RS512_4096_R4_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawRS384_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawRS384_3072_F4_Key_Template().()},
109 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_PS256_2048_R4", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.PS256_2048_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/PS256_2048_F4_Key_Template().()},
110 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_PS256_2048_R4_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawPS256_2048_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawPS256_2048_F4_Key_Template().()},
111 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_PS256_3072_R4", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.PS256_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/PS256_3072_F4_Key_Template().()},
112 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_PS256_3072_R4_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawPS256_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawPS256_3072_F4_Key_Template().()},
113 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_PS384_3072_R4", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.PS384_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/PS384_3072_F4_Key_Template().()},
114 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_PS384_3072_R4_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawPS384_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawPS384_3072_F4_Key_Template().()},
115 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_PS512_4096_R4", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.PS512_4096_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/PS512_4096_F4_Key_Template().()},
116 {tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag.: "JWT_PS512_4096_R4_RAW", templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.: jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.RawPS384_3072_F4_Key_Templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/RawPS384_3072_F4_Key_Template().()},
117 } {
118 t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(tc.tagscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#tag., func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
119 kh, err := keysetscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/keyset`/.NewHandlescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/keyset`/NewHandle().(tc.templatescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt_test`/templateTestCase#template.)
120 if err != nil {
121 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("keyset.NewHandle() err = %v, want nil", err)
122 }
123 signer, err := jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.NewSignerscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/NewSigner().(kh)
124 if err != nil {
125 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("jwt.NewSigner() err = %v, want nil", err)
126 }
127 compact, err := signer.SignAndEncodescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/Signer#SignAndEncode.(rawJWT)
128 if err != nil {
129 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("signer.SignAndEncode() err = %v, want nil", err)
130 }
131 pubkh, err := kh.Publicscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/keyset`/Handle#Public().()
132 if err != nil {
133 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("key handle Public() err = %v, want nil", err)
134 }
135 verifier, err := jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.NewVerifierscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/NewVerifier().(pubkh)
136 if err != nil {
137 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("jwt.NewVerifier() err = %v, want nil", err)
138 }
139 validator, err := jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.NewValidatorscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/NewValidator().(&jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.ValidatorOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/ValidatorOpts#{})
140 if err != nil {
141 t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("jwt.NewValidator() err = %v, want nil", err)
142 }
143 if _, err := verifier.VerifyAndDecodescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/Verifier#VerifyAndDecode.(compact, validator); err != nil {
144 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("verifier.VerifyAndDecode() err = %v, want nil", err)
145 }
146
147 // In two hours, VerifyAndDecode should fail with an expiration error.
148 inTwoHours := timescip-go gomod github.com/golang/go/src go1.24.0 time/.Nowscip-go gomod github.com/golang/go/src go1.24.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.24.0 time/Time#Add().(timescip-go gomod github.com/golang/go/src go1.24.0 time/.Hourscip-go gomod github.com/golang/go/src go1.24.0 time/Hour. * 2)
149 futureValidator, err := jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.NewValidatorscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/NewValidator().(&jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.ValidatorOptsscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/ValidatorOpts#{FixedNowscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/ValidatorOpts#FixedNow.: inTwoHours})
150 if err != nil {
151 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("jwt.NewValidator() err = %v, want nil", err)
152 }
153 _, futureError := verifier.VerifyAndDecodescip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/Verifier#VerifyAndDecode.(compact, futureValidator)
154 if futureError == nil {
155 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("verifier.VerifyAndDecode(compact, futureValidator) err = nil, want error")
156 }
157 if !jwtscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/.IsExpirationErrscip-go gomod github.com/tink-crypto/tink-go/v2 . `github.com/tink-crypto/tink-go/v2/jwt`/IsExpirationErr().(futureError) {
158 t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("jwt.IsExpirationErr(expirationError) = false, want true")
159 }
160 })
161 }
162 }