/
type_rune_slice.go
146 lines (117 loc) · 3.59 KB
/
type_rune_slice.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package cryptypes
import "database/sql/driver"
// EncryptedRuneSlice supports encrypting RuneSlice data
type EncryptedRuneSlice struct {
Field
Raw []rune
}
// Scan converts the value from the DB into a usable EncryptedRuneSlice value
func (s *EncryptedRuneSlice) Scan(value interface{}) error {
return decrypt(value.([]byte), &s.Raw)
}
// Value converts an initialized EncryptedRuneSlice value into a value that can safely be stored in the DB
func (s EncryptedRuneSlice) Value() (driver.Value, error) {
return encrypt(s.Raw)
}
// NullEncryptedRuneSlice supports encrypting nullable RuneSlice data
type NullEncryptedRuneSlice struct {
Field
Raw []rune
Empty bool
}
// Scan converts the value from the DB into a usable NullEncryptedRuneSlice value
func (s *NullEncryptedRuneSlice) Scan(value interface{}) error {
if value == nil {
s.Raw = []rune{}
s.Empty = true
return nil
}
return decrypt(value.([]byte), &s.Raw)
}
// Value converts an initialized NullEncryptedRuneSlice value into a value that can safely be stored in the DB
func (s NullEncryptedRuneSlice) Value() (driver.Value, error) {
if s.Empty {
return nil, nil
}
return encrypt(s.Raw)
}
// SignedRuneSlice supports signing RuneSlice data
type SignedRuneSlice struct {
Field
Raw []rune
Valid bool
}
// Scan converts the value from the DB into a usable SignedRuneSlice value
func (s *SignedRuneSlice) Scan(value interface{}) (err error) {
s.Valid, err = verify(value.([]byte), &s.Raw)
return
}
// Value converts an initialized SignedRuneSlice value into a value that can safely be stored in the DB
func (s SignedRuneSlice) Value() (driver.Value, error) {
return sign(s.Raw)
}
// NullSignedRuneSlice supports signing nullable RuneSlice data
type NullSignedRuneSlice struct {
Field
Raw []rune
Empty bool
Valid bool
}
// Scan converts the value from the DB into a usable NullSignedRuneSlice value
func (s *NullSignedRuneSlice) Scan(value interface{}) (err error) {
if value == nil {
s.Raw = []rune{}
s.Empty = true
s.Valid = true
return nil
}
s.Valid, err = verify(value.([]byte), &s.Raw)
return
}
// Value converts an initialized NullSignedRuneSlice value into a value that can safely be stored in the DB
func (s NullSignedRuneSlice) Value() (driver.Value, error) {
if s.Empty {
return nil, nil
}
return sign(s.Raw)
}
// SignedEncryptedRuneSlice supports signing and encrypting RuneSlice data
type SignedEncryptedRuneSlice struct {
Field
Raw []rune
Valid bool
}
// Scan converts the value from the DB into a usable SignedEncryptedRuneSlice value
func (s *SignedEncryptedRuneSlice) Scan(value interface{}) (err error) {
s.Valid, err = decryptVerify(value.([]byte), &s.Raw)
return
}
// Value converts an initialized SignedEncryptedRuneSlice value into a value that can safely be stored in the DB
func (s SignedEncryptedRuneSlice) Value() (driver.Value, error) {
return encryptSign(s.Raw)
}
// NullSignedEncryptedRuneSlice supports signing and encrypting nullable RuneSlice data
type NullSignedEncryptedRuneSlice struct {
Field
Raw []rune
Empty bool
Valid bool
}
// Scan converts the value from the DB into a usable NullSignedEncryptedRuneSlice value
func (s *NullSignedEncryptedRuneSlice) Scan(value interface{}) (err error) {
if value == nil {
s.Raw = []rune{}
s.Empty = true
s.Valid = true
return nil
}
s.Valid, err = decryptVerify(value.([]byte), &s.Raw)
return
}
// Value converts an initialized NullSignedEncryptedRuneSlice value into a value that can safely be stored in the DB
func (s NullSignedEncryptedRuneSlice) Value() (driver.Value, error) {
if s.Empty {
return nil, nil
}
return encryptSign(s.Raw)
}