func TestVerifyWithJWK(t *testing.T) { payload := []byte("Hello, World!") key, err := rsa.GenerateKey(rand.Reader, 2048) if !assert.NoError(t, err, "RSA key generated") { return } jwkkey, err := jwk.NewRsaPublicKey(&key.PublicKey) if !assert.NoError(t, err, "JWK public key generated") { return } jwkkey.Algorithm = jwa.RS256.String() buf, err := Sign(payload, jwa.RS256, key) if !assert.NoError(t, err, "Signature generated successfully") { return } verified, err := VerifyWithJWK(buf, &jwk.Set{Keys: []jwk.Key{jwkkey}}) if !assert.NoError(t, err, "Verify is successful") { return } if !assert.Equal(t, payload, verified, "Verified payload is the same") { return } }
func TestPublicHeaders(t *testing.T) { key, err := rsa.GenerateKey(rand.Reader, 2048) if !assert.NoError(t, err, "GenerateKey should succeed") { return } signer, err := NewRsaSign(jwa.RS256, key) if !assert.NoError(t, err, "NewRsaSign should succeed") { return } pubkey := key.PublicKey pubjwk, err := jwk.NewRsaPublicKey(&pubkey) if !assert.NoError(t, err, "NewRsaPublicKey should succeed") { return } if !assert.NoError(t, signer.PublicHeaders().Set("jwk", pubjwk), "Set('jwk') should succeed") { return } }