/
options.go
72 lines (63 loc) · 1.65 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
70
71
72
package crypto
// getOpts - iterate the inbound Options and return a struct.
func getOpts(opt ...Option) (*options, error) {
opts := getDefaultOptions()
for _, o := range opt {
if o != nil {
if err := o(opts); err != nil {
return nil, err
}
}
}
return opts, nil
}
// Option - how Options are passed as arguments.
type Option func(*options) error
// options = how options are represented
type options struct {
withPrefix string
withPrk []byte
withEd25519 bool
withBase64Encoding bool
withBase58Encoding bool
}
func getDefaultOptions() *options {
return &options{}
}
// WithPrefix allows an optional prefix to be specified for the data returned
func WithPrefix(prefix string) Option {
return func(o *options) error {
o.withPrefix = prefix
return nil
}
}
// WithPrk allows an optional PRK (pseudorandom key) to be specified for an
// operation. If you're using this option with HmacSha256, you might consider
// using HmacSha256WithPrk instead.
func WithPrk(prk []byte) Option {
return func(o *options) error {
o.withPrk = prk
return nil
}
}
// WithEd25519 allows an optional request to use ed25519 during the operation
func WithEd25519() Option {
return func(o *options) error {
o.withEd25519 = true
return nil
}
}
// WithBase64Encoding allows an optional request to base64 encode the data returned
func WithBase64Encoding() Option {
return func(o *options) error {
o.withBase64Encoding = true
return nil
}
}
// WithBase58Encoding allows an optional request to base58 encode the data returned
func WithBase58Encoding() Option {
return func(o *options) error {
o.withBase58Encoding = true
return nil
}
}