@@ -18,6 +18,7 @@ import (
1818 "bytes"
1919 "math"
2020 "reflect"
21+ "slices"
2122 "testing"
2223
2324 "github.com/google/der-ascii/internal"
@@ -231,33 +232,23 @@ func TestDecodeInteger(t *testing.T) {
231232 }
232233}
233234
234- func eqUint32s (a , b []uint32 ) bool {
235- if len (a ) != len (b ) {
236- return false
237- }
238- for i := range a {
239- if a [i ] != b [i ] {
240- return false
241- }
242- }
243- return true
244- }
245-
246235var decodeObjectIdentifierTests = []struct {
247236 in []byte
248- out []uint32
237+ out []uint64
249238 ok bool
250239}{
251- {[]byte {1 }, []uint32 {0 , 1 }, true },
252- {[]byte {42 , 3 , 4 , 0x7f , 0x81 , 0x00 , 0x81 , 0x01 }, []uint32 {1 , 2 , 3 , 4 , 127 , 128 , 129 }, true },
253- {[]byte {81 }, []uint32 {2 , 1 }, true },
254- {[]byte {0x8f , 0xff , 0xff , 0xff , 0x7f }, []uint32 {2 , math .MaxUint32 - 80 }, true },
240+ {[]byte {1 }, []uint64 {0 , 1 }, true },
241+ {[]byte {42 , 3 , 4 , 0x7f , 0x81 , 0x00 , 0x81 , 0x01 }, []uint64 {1 , 2 , 3 , 4 , 127 , 128 , 129 }, true },
242+ {[]byte {81 }, []uint64 {2 , 1 }, true },
243+ {[]byte {0x8f , 0xff , 0xff , 0xff , 0x7f }, []uint64 {2 , math .MaxUint32 - 80 }, true },
244+ {[]byte {0x81 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0x7f }, []uint64 {2 , math .MaxUint64 - 80 }, true },
255245 // Empty.
256246 {[]byte {}, nil , false },
257247 // Incomplete component.
258248 {[]byte {0xff }, nil , false },
259249 // Overflow.
260- {[]byte {0x9f , 0xff , 0xff , 0xff , 0x7f }, nil , false },
250+ {[]byte {0x82 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x00 }, nil , false },
251+ {[]byte {0x83 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0x7f }, nil , false },
261252}
262253
263254func TestDecodeObjectIdentifier (t * testing.T ) {
@@ -269,26 +260,28 @@ func TestDecodeObjectIdentifier(t *testing.T) {
269260 }
270261 } else if ! ok {
271262 t .Errorf ("%d. decodeObjectIdentifier(%v) unexpectedly failed." , i , tt .in )
272- } else if ! eqUint32s (out , tt .out ) {
263+ } else if ! slices . Equal (out , tt .out ) {
273264 t .Errorf ("%d. decodeObjectIdentifier(%v) = %v wanted %v." , i , tt .in , out , tt .out )
274265 }
275266 }
276267}
277268
278269var decodeRelativeOIDTests = []struct {
279270 in []byte
280- out []uint32
271+ out []uint64
281272 ok bool
282273}{
283- {[]byte {1 }, []uint32 {1 }, true },
284- {[]byte {1 , 2 , 3 , 4 , 0x7f , 0x81 , 0x00 , 0x81 , 0x01 }, []uint32 {1 , 2 , 3 , 4 , 127 , 128 , 129 }, true },
285- {[]byte {0x8f , 0xff , 0xff , 0xff , 0x7f }, []uint32 {math .MaxUint32 }, true },
274+ {[]byte {1 }, []uint64 {1 }, true },
275+ {[]byte {1 , 2 , 3 , 4 , 0x7f , 0x81 , 0x00 , 0x81 , 0x01 }, []uint64 {1 , 2 , 3 , 4 , 127 , 128 , 129 }, true },
276+ {[]byte {0x8f , 0xff , 0xff , 0xff , 0x7f }, []uint64 {math .MaxUint32 }, true },
277+ {[]byte {0x81 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0x7f }, []uint64 {math .MaxUint64 }, true },
286278 // Empty.
287279 {[]byte {}, nil , false },
288280 // Incomplete component.
289281 {[]byte {0xff }, nil , false },
290282 // Overflow.
291- {[]byte {0x9f , 0xff , 0xff , 0xff , 0x7f }, nil , false },
283+ {[]byte {0x82 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x80 , 0x00 }, nil , false },
284+ {[]byte {0x83 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0x7f }, nil , false },
292285}
293286
294287func TestDecodeRelativeOID (t * testing.T ) {
@@ -300,7 +293,7 @@ func TestDecodeRelativeOID(t *testing.T) {
300293 }
301294 } else if ! ok {
302295 t .Errorf ("%d. decodeRelativeOID(%v) unexpectedly failed." , i , tt .in )
303- } else if ! eqUint32s (out , tt .out ) {
296+ } else if ! slices . Equal (out , tt .out ) {
304297 t .Errorf ("%d. decodeRelativeOID(%v) = %v wanted %v." , i , tt .in , out , tt .out )
305298 }
306299 }
0 commit comments