-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
52 lines (47 loc) · 1.29 KB
/
options.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
package jwt
type DecoderOption func(*Decoder)
func WithNamedDecodingAlgorithms(names ...string) DecoderOption {
return func(this *Decoder) {
for _, name := range names {
algorithm := translateNamedAlgorithm(name)
WithDecodingAlgorithm(algorithm)(this)
}
}
}
func WithDecodingAlgorithm(algorithm Algorithm) DecoderOption {
return func(this *Decoder) {
this.algorithms[algorithm.Name()] = algorithm
}
}
func WithDecodingSecrets(callback func(id string) (secret []byte)) DecoderOption {
return func(this *Decoder) {
this.secret = callback
}
}
func WithDecodingValidator(validator Validator) DecoderOption {
return func(this *Decoder) {
this.validators = append(this.validators, validator)
}
}
func noSecret(_ string) []byte {
return nil
}
type EncoderOption func(encoder *Encoder)
func WithNamedEncodingAlgorithm(algorithm string) EncoderOption {
return func(this *Encoder) {
this.headers.Algorithm = algorithm
this.algorithm = translateNamedAlgorithm(algorithm)
}
}
func WithEncodingAlgorithm(algorithm Algorithm) EncoderOption {
return func(this *Encoder) {
this.headers.Algorithm = algorithm.Name()
this.algorithm = algorithm
}
}
func WithEncodingSecret(id string, secret []byte) EncoderOption {
return func(this *Encoder) {
this.headers.KeyID = id
this.secret = secret
}
}