-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathoptions.go
More file actions
60 lines (45 loc) · 1.18 KB
/
options.go
File metadata and controls
60 lines (45 loc) · 1.18 KB
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
package keygen
import (
"strings"
"time"
)
type CheckoutOptions struct {
Algorithm string `url:"algorithm,omitempty"`
Include string `url:"include,omitempty"`
TTL int `url:"ttl,omitempty"`
// these are mainly used to build up algorithm prior to checkout
Encrypt bool `url:"encrypt"`
Sign string `url:"-"`
}
type CheckoutOption func(*CheckoutOptions) error
func CheckoutInclude(includes ...string) CheckoutOption {
return func(options *CheckoutOptions) error {
options.Include = strings.Join(includes, ",")
return nil
}
}
func CheckoutTTL(ttl time.Duration) CheckoutOption {
return func(options *CheckoutOptions) error {
options.TTL = int(ttl.Seconds())
return nil
}
}
func CheckoutEncrypt(encrypt bool) CheckoutOption {
return func(options *CheckoutOptions) error {
options.Encrypt = encrypt
return nil
}
}
func CheckoutAlgorithm(algorithm SigningAlgorithm) CheckoutOption {
return func(options *CheckoutOptions) error {
options.Sign = string(algorithm)
return nil
}
}
type VerifyOption func(*verifier) error
func VerifyPublicKey(key string) VerifyOption {
return func(verifier *verifier) error {
verifier.PublicKey = key
return nil
}
}