diff --git a/pkg/util/array.go b/pkg/util/array.go index 83627fa5e..4fd4589ed 100644 --- a/pkg/util/array.go +++ b/pkg/util/array.go @@ -2,10 +2,6 @@ package util // ArrayReverse returns a reversed version of the given byte slice. func ArrayReverse(b []byte) []byte { - // Protect from big.Ints that have 1 len bytes. - if len(b) < 2 { - return b - } dest := make([]byte, len(b)) for i, j := 0, len(b)-1; i <= j; i, j = i+1, j-1 { dest[i], dest[j] = b[j], b[i] diff --git a/pkg/util/array_test.go b/pkg/util/array_test.go index d763665e4..4f44ac5df 100644 --- a/pkg/util/array_test.go +++ b/pkg/util/array_test.go @@ -30,7 +30,16 @@ var testCases = []struct { func TestArrayReverse(t *testing.T) { for _, tc := range testCases { - have := ArrayReverse(tc.arr) + arg := make([]byte, len(tc.arr)) + copy(arg, tc.arr) + + have := ArrayReverse(arg) require.Equal(t, tc.rev, have) + + // test that argument was copied + for i := range have { + have[i] = ^have[i] + } + require.Equal(t, tc.arr, arg) } }