1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "go.cypherpunks.ru/govpn/v7/internal/subtle"
15 var aliasingTests = []struct {
17 anyOverlap, inexactOverlap bool
19 {a[:], b[:], false, false},
20 {a[:], b[:0], false, false},
21 {a[:], b[:50], false, false},
22 {a[40:50], a[50:60], false, false},
23 {a[40:50], a[60:70], false, false},
24 {a[:51], a[50:], true, true},
25 {a[:], a[:], true, false},
26 {a[:50], a[:60], true, false},
27 {a[:], nil, false, false},
28 {nil, nil, false, false},
29 {a[:], a[:0], false, false},
30 {a[:10], a[:10:20], true, false},
31 {a[:10], a[5:10:20], true, true},
34 func testAliasing(t *testing.T, i int, x, y []byte, anyOverlap, inexactOverlap bool) {
35 any := subtle.AnyOverlap(x, y)
36 if any != anyOverlap {
37 t.Errorf("%d: wrong AnyOverlap result, expected %v, got %v", i, anyOverlap, any)
39 inexact := subtle.InexactOverlap(x, y)
40 if inexact != inexactOverlap {
41 t.Errorf("%d: wrong InexactOverlap result, expected %v, got %v", i, inexactOverlap, any)
45 func TestAliasing(t *testing.T) {
46 for i, tt := range aliasingTests {
47 testAliasing(t, i, tt.x, tt.y, tt.anyOverlap, tt.inexactOverlap)
48 testAliasing(t, i, tt.y, tt.x, tt.anyOverlap, tt.inexactOverlap)