@@ -52,8 +52,9 @@ func (s) TestCounterSides(t *testing.T) {
5252
5353func (s ) TestCounterInc (t * testing.T ) {
5454 for _ , test := range []struct {
55- counter []byte
56- want []byte
55+ counter []byte
56+ want []byte
57+ expectInvalid bool
5758 }{
5859 {
5960 counter : []byte {0x00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
@@ -72,19 +73,32 @@ func (s) TestCounterInc(t *testing.T) {
7273 want : []byte {0x43 , 0xff , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
7374 },
7475 {
75- counter : []byte {0xff , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 },
76- want : []byte {0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 },
76+ counter : []byte {0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 },
77+ want : []byte {0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 },
7778 },
7879 {
79- counter : []byte {0xff , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x80 },
80- want : []byte {0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x80 },
80+ counter : []byte {0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x80 },
81+ want : []byte {0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x80 },
82+ },
83+ {
84+ counter : []byte {0xff , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 },
85+ want : []byte {},
86+ expectInvalid : true ,
87+ },
88+ {
89+ counter : []byte {0xff , 0xff , 0xff , 0xff , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x80 },
90+ want : []byte {},
91+ expectInvalid : true ,
8192 },
8293 } {
8394 c := CounterFromValue (test .counter , overflowLenAES128GCM )
8495 c .Inc ()
8596 value , _ := c .Value ()
86- if g , w := value , test .want ; ! bytes .Equal (g , w ) || c .invalid {
87- t .Errorf ("counter(%v).Inc() =\n %v, want\n %v" , test .counter , g , w )
97+ if got , want := c .invalid , test .expectInvalid ; got != want {
98+ t .Errorf ("counter.invalid=%t, want=%t" , got , want )
99+ }
100+ if got , want := value , test .want ; ! bytes .Equal (got , want ) {
101+ t .Errorf ("counter(%v).Inc() =\n %v, want\n %v" , test .counter , got , want )
88102 }
89103 }
90104}
0 commit comments