-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcryptor.go
More file actions
60 lines (51 loc) · 992 Bytes
/
Copy pathcryptor.go
File metadata and controls
60 lines (51 loc) · 992 Bytes
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 nvault
// Cryptor ...
type Cryptor interface {
Encryptor
Decryptor
}
// Encryptor ...
type Encryptor interface {
Encrypt(interface{}) (interface{}, error)
}
// Decryptor ...
type Decryptor interface {
Decrypt(interface{}) (interface{}, error)
}
// NewCryptor ...
func NewCryptor(config *Config) Cryptor {
var cryptor Cryptor
switch config.Cryptor {
case "aws-kms", "kms":
cryptor = &AwsCryptor{config.AwsConfig}
case "gcp-kms":
cryptor = &GcpCryptor{config.GcpConfig}
case "simple":
cryptor = &SimpleCryptor{config.SimpleConfig}
case "none":
fallthrough
default:
cryptor = &NoneCryptor{config.NoneConfig}
}
return cryptor
}
// Config ...
type Config struct {
NoneConfig
SimpleConfig
AwsConfig
GcpConfig
Cryptor string
}
// Option ...
type Option func(c *Config) error
// NewConfig ...
func NewConfig(cryptor string, opts ...Option) *Config {
config := &Config{
Cryptor: cryptor,
}
for _, opt := range opts {
opt(config)
}
return config
}