@@ -31,8 +31,8 @@ import (
31
31
type Bcrypt struct {}
32
32
33
33
// Config returns the validated hash configuration.
34
- func (b Bcrypt ) Config () (* internal.HashConfig , error ) {
35
- return & internal.HashConfig {HashAlgorithm : "BCRYPT" }, nil
34
+ func (b Bcrypt ) Config () (internal.HashConfig , error ) {
35
+ return internal.HashConfig {"hashAlgorithm" : "BCRYPT" }, nil
36
36
}
37
37
38
38
// StandardScrypt represents the standard scrypt hash algorithm.
@@ -47,14 +47,13 @@ type StandardScrypt struct {
47
47
}
48
48
49
49
// Config returns the validated hash configuration.
50
- func (s StandardScrypt ) Config () (* internal.HashConfig , error ) {
51
- return & internal.HashConfig {
52
- HashAlgorithm : "STANDARD_SCRYPT" ,
53
- DerivedKeyLength : int64 (s .DerivedKeyLength ),
54
- BlockSize : int64 (s .BlockSize ),
55
- Parallelization : int64 (s .Parallelization ),
56
- MemoryCost : int64 (s .MemoryCost ),
57
- ForceSendFields : []string {"BlockSize" , "Parallelization" , "MemoryCost" , "DkLen" },
50
+ func (s StandardScrypt ) Config () (internal.HashConfig , error ) {
51
+ return internal.HashConfig {
52
+ "hashAlgorithm" : "STANDARD_SCRYPT" ,
53
+ "dkLen" : s .DerivedKeyLength ,
54
+ "blockSize" : s .BlockSize ,
55
+ "parallelization" : s .Parallelization ,
56
+ "memoryCost" : s .MemoryCost ,
58
57
}, nil
59
58
}
60
59
@@ -72,7 +71,7 @@ type Scrypt struct {
72
71
}
73
72
74
73
// Config returns the validated hash configuration.
75
- func (s Scrypt ) Config () (* internal.HashConfig , error ) {
74
+ func (s Scrypt ) Config () (internal.HashConfig , error ) {
76
75
if len (s .Key ) == 0 {
77
76
return nil , errors .New ("signer key not specified" )
78
77
}
@@ -82,12 +81,12 @@ func (s Scrypt) Config() (*internal.HashConfig, error) {
82
81
if s .MemoryCost < 1 || s .MemoryCost > 14 {
83
82
return nil , errors .New ("memory cost must be between 1 and 14" )
84
83
}
85
- return & internal.HashConfig {
86
- HashAlgorithm : "SCRYPT" ,
87
- SignerKey : base64 .RawURLEncoding .EncodeToString (s .Key ),
88
- SaltSeparator : base64 .RawURLEncoding .EncodeToString (s .SaltSeparator ),
89
- Rounds : int64 ( s .Rounds ) ,
90
- MemoryCost : int64 ( s .MemoryCost ) ,
84
+ return internal.HashConfig {
85
+ "hashAlgorithm" : "SCRYPT" ,
86
+ "signerKey" : base64 .RawURLEncoding .EncodeToString (s .Key ),
87
+ "saltSeparator" : base64 .RawURLEncoding .EncodeToString (s .SaltSeparator ),
88
+ "rounds" : s .Rounds ,
89
+ "memoryCost" : s .MemoryCost ,
91
90
}, nil
92
91
}
93
92
@@ -100,7 +99,7 @@ type HMACMD5 struct {
100
99
}
101
100
102
101
// Config returns the validated hash configuration.
103
- func (h HMACMD5 ) Config () (* internal.HashConfig , error ) {
102
+ func (h HMACMD5 ) Config () (internal.HashConfig , error ) {
104
103
return hmacConfig ("HMAC_MD5" , h .Key )
105
104
}
106
105
@@ -114,7 +113,7 @@ type HMACSHA1 struct {
114
113
}
115
114
116
115
// Config returns the validated hash configuration.
117
- func (h HMACSHA1 ) Config () (* internal.HashConfig , error ) {
116
+ func (h HMACSHA1 ) Config () (internal.HashConfig , error ) {
118
117
return hmacConfig ("HMAC_SHA1" , h .Key )
119
118
}
120
119
@@ -128,7 +127,7 @@ type HMACSHA256 struct {
128
127
}
129
128
130
129
// Config returns the validated hash configuration.
131
- func (h HMACSHA256 ) Config () (* internal.HashConfig , error ) {
130
+ func (h HMACSHA256 ) Config () (internal.HashConfig , error ) {
132
131
return hmacConfig ("HMAC_SHA256" , h .Key )
133
132
}
134
133
@@ -142,7 +141,7 @@ type HMACSHA512 struct {
142
141
}
143
142
144
143
// Config returns the validated hash configuration.
145
- func (h HMACSHA512 ) Config () (* internal.HashConfig , error ) {
144
+ func (h HMACSHA512 ) Config () (internal.HashConfig , error ) {
146
145
return hmacConfig ("HMAC_SHA512" , h .Key )
147
146
}
148
147
@@ -156,7 +155,7 @@ type MD5 struct {
156
155
}
157
156
158
157
// Config returns the validated hash configuration.
159
- func (h MD5 ) Config () (* internal.HashConfig , error ) {
158
+ func (h MD5 ) Config () (internal.HashConfig , error ) {
160
159
return basicConfig ("MD5" , h .Rounds )
161
160
}
162
161
@@ -170,7 +169,7 @@ type PBKDF2SHA256 struct {
170
169
}
171
170
172
171
// Config returns the validated hash configuration.
173
- func (h PBKDF2SHA256 ) Config () (* internal.HashConfig , error ) {
172
+ func (h PBKDF2SHA256 ) Config () (internal.HashConfig , error ) {
174
173
return basicConfig ("PBKDF2_SHA256" , h .Rounds )
175
174
}
176
175
@@ -184,7 +183,7 @@ type PBKDFSHA1 struct {
184
183
}
185
184
186
185
// Config returns the validated hash configuration.
187
- func (h PBKDFSHA1 ) Config () (* internal.HashConfig , error ) {
186
+ func (h PBKDFSHA1 ) Config () (internal.HashConfig , error ) {
188
187
return basicConfig ("PBKDF_SHA1" , h .Rounds )
189
188
}
190
189
@@ -198,7 +197,7 @@ type SHA1 struct {
198
197
}
199
198
200
199
// Config returns the validated hash configuration.
201
- func (h SHA1 ) Config () (* internal.HashConfig , error ) {
200
+ func (h SHA1 ) Config () (internal.HashConfig , error ) {
202
201
return basicConfig ("SHA1" , h .Rounds )
203
202
}
204
203
@@ -212,7 +211,7 @@ type SHA256 struct {
212
211
}
213
212
214
213
// Config returns the validated hash configuration.
215
- func (h SHA256 ) Config () (* internal.HashConfig , error ) {
214
+ func (h SHA256 ) Config () (internal.HashConfig , error ) {
216
215
return basicConfig ("SHA256" , h .Rounds )
217
216
}
218
217
@@ -226,27 +225,26 @@ type SHA512 struct {
226
225
}
227
226
228
227
// Config returns the validated hash configuration.
229
- func (h SHA512 ) Config () (* internal.HashConfig , error ) {
228
+ func (h SHA512 ) Config () (internal.HashConfig , error ) {
230
229
return basicConfig ("SHA512" , h .Rounds )
231
230
}
232
231
233
- func hmacConfig (name string , key []byte ) (* internal.HashConfig , error ) {
232
+ func hmacConfig (name string , key []byte ) (internal.HashConfig , error ) {
234
233
if len (key ) == 0 {
235
234
return nil , errors .New ("signer key not specified" )
236
235
}
237
- return & internal.HashConfig {
238
- HashAlgorithm : name ,
239
- SignerKey : base64 .RawURLEncoding .EncodeToString (key ),
236
+ return internal.HashConfig {
237
+ "hashAlgorithm" : name ,
238
+ "signerKey" : base64 .RawURLEncoding .EncodeToString (key ),
240
239
}, nil
241
240
}
242
241
243
- func basicConfig (name string , rounds int ) (* internal.HashConfig , error ) {
242
+ func basicConfig (name string , rounds int ) (internal.HashConfig , error ) {
244
243
if rounds < 0 || rounds > 120000 {
245
244
return nil , errors .New ("rounds must be between 0 and 120000" )
246
245
}
247
- return & internal.HashConfig {
248
- HashAlgorithm : name ,
249
- Rounds : int64 (rounds ),
250
- ForceSendFields : []string {"Rounds" },
246
+ return internal.HashConfig {
247
+ "hashAlgorithm" : name ,
248
+ "rounds" : rounds ,
251
249
}, nil
252
250
}
0 commit comments