forked from smallstep/cli
/
options.go
69 lines (59 loc) · 1.41 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package jose
type context struct {
use, alg, kid string
subtle, insecure bool
noDefaults bool
password []byte
}
// apply the options to the context and returns it.
func (ctx *context) apply(opts ...Option) *context {
for _, opt := range opts {
opt(ctx)
}
return ctx
}
// Option is the type used to add attributes to the context.
type Option func(ctx *context)
// WithUse adds the use claim to the context.
func WithUse(use string) Option {
return func(ctx *context) {
ctx.use = use
}
}
// WithAlg adds the alg claim to the context.
func WithAlg(alg string) Option {
return func(ctx *context) {
ctx.alg = alg
}
}
// WithKid adds the kid property to the context.
func WithKid(kid string) Option {
return func(ctx *context) {
ctx.kid = kid
}
}
// WithSubtle marks the context as subtle.
func WithSubtle(subtle bool) Option {
return func(ctx *context) {
ctx.subtle = subtle
}
}
// WithInsecure marks the context as insecure.
func WithInsecure(insecure bool) Option {
return func(ctx *context) {
ctx.insecure = insecure
}
}
// WithNoDefaults avoids that the parser loads defaults values, specially the
// default algorithms.
func WithNoDefaults(val bool) Option {
return func(ctx *context) {
ctx.noDefaults = val
}
}
// WithPassword is a method that adds the given password to the context.
func WithPassword(pass []byte) Option {
return func(ctx *context) {
ctx.password = pass
}
}