@@ -38,10 +38,10 @@ func GenerateTestdata() *cobra.Command {
38
38
}
39
39
40
40
enc := & testEncoder {
41
- w : w ,
42
- e : 1 ,
43
- d : 1 ,
44
- v : 1 ,
41
+ w : w ,
42
+ etCounter : 1 ,
43
+ dtCounter : 1 ,
44
+ vtCounter : 1 ,
45
45
}
46
46
enc .start ()
47
47
CreateJSONTests (* enc )
@@ -72,25 +72,25 @@ func RunJSONTests() *cobra.Command {
72
72
}
73
73
74
74
type testEncoder struct {
75
- w io.Writer
76
- i int
77
- e int
78
- d int
79
- v int
75
+ w io.Writer
76
+ idCounter int
77
+ etCounter int
78
+ dtCounter int
79
+ vtCounter int
80
80
}
81
81
82
82
func (enc * testEncoder ) addTest (tc * testCase ) {
83
- tc .ID = fmt .Sprint (enc .i )
83
+ tc .ID = fmt .Sprint (enc .idCounter )
84
84
switch tc .TestType {
85
- case ENCRYPTION :
86
- tc .Name = fmt .Sprintf ("%s %d" , ENCRYPTION , enc .e )
87
- enc .e ++
88
- case DECRYPTION :
89
- tc .Name = fmt .Sprintf ("%s %d" , DECRYPTION , enc .d )
90
- enc .d ++
91
- case VERIFICATION :
92
- tc .Name = fmt .Sprintf ("%s %d" , VERIFICATION , enc .v )
93
- enc .v ++
85
+ case encryption :
86
+ tc .Name = fmt .Sprintf ("%s %d" , encryption , enc .etCounter )
87
+ enc .etCounter ++
88
+ case decryption :
89
+ tc .Name = fmt .Sprintf ("%s %d" , decryption , enc .dtCounter )
90
+ enc .dtCounter ++
91
+ case verification :
92
+ tc .Name = fmt .Sprintf ("%s %d" , verification , enc .vtCounter )
93
+ enc .vtCounter ++
94
94
default :
95
95
panic (fmt .Errorf ("unknown test type" ))
96
96
}
@@ -102,16 +102,22 @@ func (enc *testEncoder) addTest(tc *testCase) {
102
102
}
103
103
104
104
var buf bytes.Buffer
105
- if enc .i > 0 {
106
- buf .WriteString (",\n " )
105
+ if enc .idCounter > 0 {
106
+ if _ , err := buf .WriteString (",\n " ); err != nil {
107
+ panic (err )
108
+ }
109
+ }
110
+ if _ , err := buf .WriteString (indent ); err != nil {
111
+ panic (err )
112
+ }
113
+ if _ , err := buf .Write (encoded ); err != nil {
114
+ panic (err )
107
115
}
108
- buf .WriteString (indent )
109
- buf .Write (encoded )
110
116
if _ , err := buf .WriteTo (enc .w ); err != nil {
111
117
panic (err )
112
118
}
113
119
114
- enc .i ++
120
+ enc .idCounter ++
115
121
}
116
122
117
123
func (enc * testEncoder ) start () {
@@ -149,11 +155,11 @@ func (tc *testCase) UnmarshalJSON(b []byte) error {
149
155
return err
150
156
}
151
157
switch tc .TestType {
152
- case ENCRYPTION :
158
+ case encryption :
153
159
tc .Test = new (encryptionTest )
154
- case DECRYPTION :
160
+ case decryption :
155
161
tc .Test = new (decryptionTest )
156
- case VERIFICATION :
162
+ case verification :
157
163
tc .Test = new (verificationTest )
158
164
default :
159
165
return fmt .Errorf ("invalid test type %q" , tc .Test )
@@ -169,9 +175,9 @@ func (tc *testCase) UnmarshalJSON(b []byte) error {
169
175
}
170
176
171
177
const (
172
- ENCRYPTION = "encryption"
173
- DECRYPTION = "decryption"
174
- VERIFICATION = "verification"
178
+ encryption = "encryption"
179
+ decryption = "decryption"
180
+ verification = "verification"
175
181
)
176
182
177
183
type encryptionTest struct {
@@ -234,11 +240,11 @@ func ReadTestcases(filename string) []error {
234
240
}
235
241
236
242
const (
237
- RANDOM = "random"
238
- FIXED = "fixed"
239
- TAMPERED = "tampered"
240
- VERIFYING = "verifying"
241
- NONVERIFYING = "nonverifying"
243
+ random = "random"
244
+ fixed = "fixed"
245
+ tampered = "tampered"
246
+ verifying = "verifying"
247
+ nonVerifying = "nonverifying"
242
248
)
243
249
244
250
var testSpecs = []struct {
@@ -249,62 +255,62 @@ var testSpecs = []struct {
249
255
{
250
256
"A zero byte message." ,
251
257
make ([]byte , 0 ),
252
- RANDOM ,
258
+ random ,
253
259
},
254
260
{
255
261
"A 1 byte message." ,
256
262
make ([]byte , 1 ),
257
- RANDOM ,
263
+ random ,
258
264
},
259
265
{
260
266
"A 31 byte message." ,
261
267
make ([]byte , 31 ),
262
- RANDOM ,
268
+ random ,
263
269
},
264
270
{
265
271
"A 32 byte message." ,
266
272
make ([]byte , 32 ),
267
- RANDOM ,
273
+ random ,
268
274
},
269
275
{
270
276
"A 33 byte message." ,
271
277
make ([]byte , 33 ),
272
- RANDOM ,
278
+ random ,
273
279
},
274
280
{
275
281
"A 319 byte message." ,
276
282
make ([]byte , 319 ),
277
- RANDOM ,
283
+ random ,
278
284
},
279
285
{
280
286
"A 320 byte message." ,
281
287
make ([]byte , 320 ),
282
- RANDOM ,
288
+ random ,
283
289
},
284
290
{
285
291
"A 321 byte message." ,
286
292
make ([]byte , 321 ),
287
- RANDOM ,
293
+ random ,
288
294
},
289
295
{
290
296
"The message 'A message'" ,
291
297
[]byte ("A message" ),
292
- FIXED ,
293
- }, /*
294
- {
295
- "An illegal modification of the encrypted message 'A message'",
296
- []byte("A message"),
297
- TAMPERED ,
298
- },*/
298
+ fixed ,
299
+ },
300
+ /* {
301
+ "An illegal modification of the encrypted message 'A message'",
302
+ []byte("A message"),
303
+ tampered ,
304
+ },*/
299
305
{
300
306
"Verification of a random 32 byte epochID" ,
301
307
make ([]byte , 32 ),
302
- VERIFYING ,
308
+ verifying ,
303
309
},
304
310
{
305
311
"A failed verification" ,
306
312
make ([]byte , 32 ),
307
- NONVERIFYING ,
313
+ nonVerifying ,
308
314
},
309
315
}
310
316
@@ -315,9 +321,9 @@ func CreateJSONTests(enc testEncoder) {
315
321
testSpec := testSpecs [i ]
316
322
317
323
switch testSpec .style {
318
- case RANDOM , FIXED :
324
+ case random , fixed :
319
325
320
- if testSpec .style == RANDOM {
326
+ if testSpec .style == random {
321
327
_ , err = rand .Read (testSpec .payload )
322
328
}
323
329
if err != nil {
@@ -330,7 +336,7 @@ func CreateJSONTests(enc testEncoder) {
330
336
testcase := testCase {
331
337
testCaseMeta : testCaseMeta {
332
338
Description : testSpec .description ,
333
- TestType : ENCRYPTION ,
339
+ TestType : encryption ,
334
340
},
335
341
Test : et ,
336
342
}
@@ -343,7 +349,7 @@ func CreateJSONTests(enc testEncoder) {
343
349
testcase = testCase {
344
350
testCaseMeta : testCaseMeta {
345
351
Description : testSpec .description ,
346
- TestType : DECRYPTION ,
352
+ TestType : decryption ,
347
353
},
348
354
Test : & dt ,
349
355
}
@@ -353,7 +359,7 @@ func CreateJSONTests(enc testEncoder) {
353
359
}
354
360
enc .addTest (& testcase )
355
361
356
- case TAMPERED :
362
+ case tampered :
357
363
et , err := createEncryptionTest (keygen , testSpec .payload )
358
364
if err != nil {
359
365
panic (err )
@@ -365,18 +371,18 @@ func CreateJSONTests(enc testEncoder) {
365
371
testcase := testCase {
366
372
testCaseMeta : testCaseMeta {
367
373
Description : testSpec .description ,
368
- TestType : DECRYPTION ,
374
+ TestType : decryption ,
369
375
},
370
376
Test : & dt ,
371
377
}
372
378
if err := verifyTestCase (& testcase ); err != nil {
373
379
panic (err )
374
380
}
375
381
enc .addTest (& testcase )
376
- case VERIFYING , NONVERIFYING :
382
+ case verifying , nonVerifying :
377
383
var err error
378
384
var vt verificationTest
379
- if testSpec .style == VERIFYING {
385
+ if testSpec .style == verifying {
380
386
vt , err = createVerificationTest (keygen , testSpec .payload )
381
387
} else {
382
388
vt , err = createFailedVerificationTest (keygen , testSpec .payload )
@@ -387,7 +393,7 @@ func CreateJSONTests(enc testEncoder) {
387
393
testcase := testCase {
388
394
testCaseMeta : testCaseMeta {
389
395
Description : testSpec .description ,
390
- TestType : VERIFICATION ,
396
+ TestType : verification ,
391
397
},
392
398
Test : & vt ,
393
399
}
0 commit comments