Skip to content

Commit f716f99

Browse files
committed
natives: duplicate aliasing.go in x/crypto revisted
Same as fcd349a. x/crypto internally moved the AnyOverlap from x/crypto/internal/subtle/ to /x/crypto/internal/alias/.
1 parent 08314bf commit f716f99

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

compiler/natives/src/crypto/internal/subtle/aliasing.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
package subtle
55

66
// This file duplicated is these two locations:
7-
// - src/crypto/internal/subtle/
8-
// - src/golang.org/x/crypto/internal/subtle/
7+
// - src/crypto/internal/subtle/aliasing.go
8+
// - src/golang.org/x/crypto/internal/subtle/aliasing.go
9+
// - src/golang.org/x/crypto/internal/alias/alias.go
910

1011
import "github.com/gopherjs/gopherjs/js"
1112

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build js
2+
// +build js
3+
4+
package alias
5+
6+
// This file duplicated is these two locations:
7+
// - src/crypto/internal/subtle/aliasing.go
8+
// - src/golang.org/x/crypto/internal/subtle/aliasing.go
9+
// - src/golang.org/x/crypto/internal/alias/alias.go
10+
11+
import "github.com/gopherjs/gopherjs/js"
12+
13+
// AnyOverlap reports whether x and y share memory at any (not necessarily
14+
// corresponding) index. The memory beyond the slice length is ignored.
15+
func AnyOverlap(x, y []byte) bool {
16+
// GopherJS: We can't rely on pointer arithmetic, so use GopherJS slice internals.
17+
return len(x) > 0 && len(y) > 0 &&
18+
js.InternalObject(x).Get("$array") == js.InternalObject(y).Get("$array") &&
19+
js.InternalObject(x).Get("$offset").Int() <= js.InternalObject(y).Get("$offset").Int()+len(y)-1 &&
20+
js.InternalObject(y).Get("$offset").Int() <= js.InternalObject(x).Get("$offset").Int()+len(x)-1
21+
}

compiler/natives/src/golang.org/x/crypto/internal/subtle/aliasing.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
package subtle
55

66
// This file duplicated is these two locations:
7-
// - src/crypto/internal/subtle/
8-
// - src/golang.org/x/crypto/internal/subtle/
7+
// - src/crypto/internal/subtle/aliasing.go
8+
// - src/golang.org/x/crypto/internal/subtle/aliasing.go
9+
// - src/golang.org/x/crypto/internal/alias/alias.go
910

1011
import "github.com/gopherjs/gopherjs/js"
1112

0 commit comments

Comments
 (0)