-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey.go
62 lines (55 loc) · 1.33 KB
/
key.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
package jwtauth
import (
"crypto/ecdsa"
"crypto/rsa"
"github.com/golang-jwt/jwt/v5"
)
func NewHMACKey(
kid string,
key []byte,
signingMethod *jwt.SigningMethodHMAC,
) *Key {
return &Key{
Kid: kid,
SigningKey: key,
VerifyingKey: key,
SigningMethod: signingMethod,
}
}
func NewECDSAKey(
kid string,
key *ecdsa.PrivateKey,
signingMethod *jwt.SigningMethodECDSA,
) *Key {
return &Key{
Kid: kid,
SigningKey: key,
VerifyingKey: &key.PublicKey,
SigningMethod: signingMethod,
}
}
func NewRSAKey(
kid string,
key *rsa.PrivateKey,
signingMethod *jwt.SigningMethodRSA,
) *Key {
return &Key{
Kid: kid,
SigningKey: key,
VerifyingKey: &key.PublicKey,
SigningMethod: signingMethod,
}
}
type Key struct {
Kid string // jwt 'kid' header value to identify the correct key for verifying
SigningKey any // key used for signing: symmetric methods have the same signing and verifying key
VerifyingKey any // key used for verifying: symmetric methods have the same signing and verifying key
SigningMethod jwt.SigningMethod // key signing method
deprecated bool
}
// Mark the key as deprecated.
// Deprecated keys are used only for verifying and not signing.
func (key *Key) Deprecated() *Key {
key.deprecated = true
return key
}