-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
encryption_key_size.go
61 lines (51 loc) · 1.19 KB
/
encryption_key_size.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
package encryption
import (
"bytes"
"encoding/json"
)
type EncryptionKeySize int64
const (
Bit256 EncryptionKeySize = 256
Bit384 EncryptionKeySize = 384
Bit512 EncryptionKeySize = 512
Bit1024 EncryptionKeySize = 1024
Bit2048 EncryptionKeySize = 2048
Bit4096 EncryptionKeySize = 4096
)
func (s EncryptionKeySize) String() string {
return toEncryptionKeySizeString[s]
}
func (s EncryptionKeySize) FromString(key string) EncryptionKeySize {
return toEncryptionKeySizeID[key]
}
var toEncryptionKeySizeString = map[EncryptionKeySize]string{
Bit256: "256",
Bit384: "384",
Bit512: "512",
Bit1024: "1024",
Bit2048: "2048",
Bit4096: "4096",
}
var toEncryptionKeySizeID = map[string]EncryptionKeySize{
"256": Bit256,
"384": Bit384,
"512": Bit512,
"1024": Bit1024,
"2048": Bit2048,
"4096": Bit4096,
}
func (s EncryptionKeySize) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(toEncryptionKeySizeString[s])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
func (s *EncryptionKeySize) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
*s = toEncryptionKeySizeID[j]
return nil
}