aboutsummaryrefslogtreecommitdiff
path: root/src/internal/boringtest/boring_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-04-27 09:02:53 -0400
committerRuss Cox <rsc@golang.org>2022-04-29 14:23:32 +0000
commite845f572ec6163fd3bad0267b5bb4f24d369bd93 (patch)
tree9156df472b1692b5a4ff180bdaf02e98b5f40dbb /src/internal/boringtest/boring_test.go
parenta840bf871e005d948ba6442948997eb3ef2e3c7f (diff)
downloadgo-e845f572ec6163fd3bad0267b5bb4f24d369bd93.tar.gz
go-e845f572ec6163fd3bad0267b5bb4f24d369bd93.zip
[dev.boringcrypto] crypto/ecdsa, crypto/rsa: use boring.Cache
In the original BoringCrypto port, ecdsa and rsa's public and private keys added a 'boring unsafe.Pointer' field to cache the BoringCrypto form of the key. This led to problems with code that “knew” the layout of those structs and in particular that they had no unexported fields. In response, as an awful kludge, I changed the compiler to pretend that field did not exist when laying out reflect data. Because we want to merge BoringCrypto in the main tree, we need a different solution. Using boring.Cache is that solution. For #51940. Change-Id: Ideb2b40b599a1dc223082eda35a5ea9abcc01e30 Reviewed-on: https://go-review.googlesource.com/c/go/+/395883 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
Diffstat (limited to 'src/internal/boringtest/boring_test.go')
-rw-r--r--src/internal/boringtest/boring_test.go47
1 files changed, 0 insertions, 47 deletions
diff --git a/src/internal/boringtest/boring_test.go b/src/internal/boringtest/boring_test.go
deleted file mode 100644
index a6b07eda70..0000000000
--- a/src/internal/boringtest/boring_test.go
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2017 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Like crypto/rsa/boring_test.go but outside the crypto/ tree.
-// Tests what happens if a package outside the crypto/ tree
-// "adopts" a struct definition. This happens in golang.org/x/crypto/ssh.
-
-package boring
-
-import (
- "crypto/rand"
- "crypto/rsa"
- "encoding/asn1"
- "reflect"
- "testing"
-)
-
-type publicKey rsa.PublicKey
-
-func TestBoringASN1Marshal(t *testing.T) {
- k, err := rsa.GenerateKey(rand.Reader, 128)
- if err != nil {
- t.Fatal(err)
- }
- pk := (*publicKey)(&k.PublicKey)
- // This used to fail, because of the unexported 'boring' field.
- // Now the compiler hides it [sic].
- _, err = asn1.Marshal(*pk)
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func TestBoringDeepEqual(t *testing.T) {
- k0, err := rsa.GenerateKey(rand.Reader, 128)
- if err != nil {
- t.Fatal(err)
- }
- k := (*publicKey)(&k0.PublicKey)
- k2 := *k
- rsa.EncryptPKCS1v15(rand.Reader, (*rsa.PublicKey)(&k2), []byte("hello")) // initialize hidden boring field
- if !reflect.DeepEqual(k, &k2) {
- // compiler should be hiding the boring field from reflection
- t.Fatalf("DeepEqual compared boring fields")
- }
-}