/
options.go
46 lines (40 loc) · 1.13 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
package pbkdf2
import (
"gopkg.in/encoder.v1/types"
"hash"
)
// WithSalt configure the salt value for Encoder, default automatically generate random strings
func WithSalt(salt []byte) types.Option {
return types.OptionFunc(func(e types.Encoder) {
p := e.(*Encoder)
p.salt = salt
})
}
// WithSaltLen configure the salt length for Encoder, default value is 16
func WithSaltLen(len int) types.Option {
return types.OptionFunc(func(e types.Encoder) {
p := e.(*Encoder)
p.SaltLen = len
})
}
// WithIterations configure the iterations for Encoder, default value is 10000
func WithIterations(iter int) types.Option {
return types.OptionFunc(func(e types.Encoder) {
p := e.(*Encoder)
p.Iterations = iter
})
}
// WithKeyLen configure the key length for Encoder, default value is 32
func WithKeyLen(len int) types.Option {
return types.OptionFunc(func(e types.Encoder) {
p := e.(*Encoder)
p.KeyLen = len
})
}
// WithHasFunc configure the ken hash func for Encoder, default value is sha256.New
func WithHasFunc(f func() hash.Hash) types.Option {
return types.OptionFunc(func(e types.Encoder) {
p := e.(*Encoder)
p.HashFunc = f
})
}