forked from MicahParks/keyfunc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgiven.go
68 lines (57 loc) · 1.64 KB
/
given.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package keyfunc
import (
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
)
// GivenKey represents a cryptographic key that resides in a JWKS. In conjuncture with Options.
type GivenKey struct {
inter interface{}
}
// NewGiven creates a JWKS from a map of given keys.
func NewGiven(givenKeys map[string]GivenKey) (jwks *JWKS) {
// Initialize the map of kid to cryptographic keys.
keys := make(map[string]interface{})
// Copy the given keys to the map of cryptographic keys.
for kid, given := range givenKeys {
keys[kid] = given.inter
}
// Return a JWKS with the map of cryptographic keys.
return &JWKS{
keys: keys,
}
}
// NewGivenCustom creates a new GivenKey given an untyped variable. The key argument is expected to be a supported
// by the jwt package used.
//
// See the https://pkg.go.dev/github.com/golang-jwt/jwt#RegisterSigningMethod function for registering an unsupported
// signing method.
func NewGivenCustom(key interface{}) (givenKey GivenKey) {
return GivenKey{
inter: key,
}
}
// NewGivenECDSA creates a new GivenKey given an ECDSA public key.
func NewGivenECDSA(key *ecdsa.PublicKey) (givenKey GivenKey) {
return GivenKey{
inter: key,
}
}
// NewGivenEdDSA creates a new GivenKey given an EdDSA public key.
func NewGivenEdDSA(key ed25519.PublicKey) (givenKey GivenKey) {
return GivenKey{
inter: key,
}
}
// NewGivenHMAC creates a new GivenKey given an HMAC key in a byte slice.
func NewGivenHMAC(key []byte) (givenKey GivenKey) {
return GivenKey{
inter: key,
}
}
// NewGivenRSA creates a new GivenKey given an RSA public key.
func NewGivenRSA(key *rsa.PublicKey) (givenKey GivenKey) {
return GivenKey{
inter: key,
}
}