all: gofmt -w -r 'interface{} -> any' src

And then revert the bootstrap cmd directories and certain testdata.
And adjust tests as needed.

Not reverting the changes in std that are bootstrapped,
because some of those changes would appear in API docs,
and we want to use any consistently.
Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories
when preparing the bootstrap copy.

A few files changed as a result of running gofmt -w
not because of interface{} -> any but because they
hadn't been updated for the new //go:build lines.

Fixes #49884.

Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09
Reviewed-on: https://go-review.googlesource.com/c/go/+/368254
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Russ Cox 2021-12-01 12:15:45 -05:00
parent b0a9ca52e9
commit 503cd752b4
9 changed files with 23 additions and 23 deletions

View file

@ -140,7 +140,7 @@ type cipherSuite struct {
ka func(version uint16) keyAgreement
// flags is a bitmask of the suite* values, above.
flags int
cipher func(key, iv []byte, isRead bool) interface{}
cipher func(key, iv []byte, isRead bool) any
mac func(key []byte) hash.Hash
aead func(key, fixedNonce []byte) aead
}
@ -399,12 +399,12 @@ func aesgcmPreferred(ciphers []uint16) bool {
return false
}
func cipherRC4(key, iv []byte, isRead bool) interface{} {
func cipherRC4(key, iv []byte, isRead bool) any {
cipher, _ := rc4.NewCipher(key)
return cipher
}
func cipher3DES(key, iv []byte, isRead bool) interface{} {
func cipher3DES(key, iv []byte, isRead bool) any {
block, _ := des.NewTripleDESCipher(key)
if isRead {
return cipher.NewCBCDecrypter(block, iv)
@ -412,7 +412,7 @@ func cipher3DES(key, iv []byte, isRead bool) interface{} {
return cipher.NewCBCEncrypter(block, iv)
}
func cipherAES(key, iv []byte, isRead bool) interface{} {
func cipherAES(key, iv []byte, isRead bool) any {
block, _ := aes.NewCipher(key)
if isRead {
return cipher.NewCBCDecrypter(block, iv)

View file

@ -1466,7 +1466,7 @@ func defaultConfig() *Config {
return &emptyConfig
}
func unexpectedMessageError(wanted, got interface{}) error {
func unexpectedMessageError(wanted, got any) error {
return fmt.Errorf("tls: received unexpected handshake message of type %T when waiting for %T", got, wanted)
}

16
conn.go
View file

@ -163,16 +163,16 @@ func (c *Conn) NetConn() net.Conn {
type halfConn struct {
sync.Mutex
err error // first permanent error
version uint16 // protocol version
cipher interface{} // cipher algorithm
err error // first permanent error
version uint16 // protocol version
cipher any // cipher algorithm
mac hash.Hash
seq [8]byte // 64-bit sequence number
scratchBuf [13]byte // to avoid allocs; interface method args escape
nextCipher interface{} // next encryption state
nextMac hash.Hash // next MAC algorithm
nextCipher any // next encryption state
nextMac hash.Hash // next MAC algorithm
trafficSecret []byte // current TLS 1.3 traffic secret
}
@ -197,7 +197,7 @@ func (hc *halfConn) setErrorLocked(err error) error {
// prepareCipherSpec sets the encryption and MAC states
// that a subsequent changeCipherSpec will use.
func (hc *halfConn) prepareCipherSpec(version uint16, cipher interface{}, mac hash.Hash) {
func (hc *halfConn) prepareCipherSpec(version uint16, cipher any, mac hash.Hash) {
hc.version = version
hc.nextCipher = cipher
hc.nextMac = mac
@ -935,7 +935,7 @@ func (c *Conn) flush() (int, error) {
// outBufPool pools the record-sized scratch buffers used by writeRecordLocked.
var outBufPool = sync.Pool{
New: func() interface{} {
New: func() any {
return new([]byte)
},
}
@ -1011,7 +1011,7 @@ func (c *Conn) writeRecord(typ recordType, data []byte) (int, error) {
// readHandshake reads the next handshake message from
// the record layer.
func (c *Conn) readHandshake() (interface{}, error) {
func (c *Conn) readHandshake() (any, error) {
for c.hand.Len() < 4 {
if err := c.readRecord(); err != nil {
return nil, err

View file

@ -37,7 +37,7 @@ var (
ed25519Key = flag.Bool("ed25519", false, "Generate an Ed25519 key")
)
func publicKey(priv interface{}) interface{} {
func publicKey(priv any) any {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &k.PublicKey
@ -57,7 +57,7 @@ func main() {
log.Fatalf("Missing required --host parameter")
}
var priv interface{}
var priv any
var err error
switch *ecdsaCurve {
case "":

View file

@ -657,7 +657,7 @@ func (hs *clientHandshakeState) establishKeys() error {
clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
keysFromMasterSecret(c.vers, hs.suite, hs.masterSecret, hs.hello.random, hs.serverHello.random, hs.suite.macLen, hs.suite.keyLen, hs.suite.ivLen)
var clientCipher, serverCipher interface{}
var clientCipher, serverCipher any
var clientHash, serverHash hash.Hash
if hs.suite.cipher != nil {
clientCipher = hs.suite.cipher(clientKey, clientIV, false /* not for reading */)

View file

@ -134,7 +134,7 @@ type clientTest struct {
cert []byte
// key, if not nil, contains either a *rsa.PrivateKey, ed25519.PrivateKey or
// *ecdsa.PrivateKey which is the private key for the reference server.
key interface{}
key any
// extensions, if not nil, contains a list of extension data to be returned
// from the ServerHello. The data should be in standard TLS format with
// a 2-byte uint16 type, 2-byte data length, followed by the extension data.
@ -171,7 +171,7 @@ func (test *clientTest) connFromCommand() (conn *recordingConn, child *exec.Cmd,
certPath := tempFile(string(cert))
defer os.Remove(certPath)
var key interface{} = testRSAPrivateKey
var key any = testRSAPrivateKey
if test.key != nil {
key = test.key
}

View file

@ -14,7 +14,7 @@ import (
"time"
)
var tests = []interface{}{
var tests = []any{
&clientHelloMsg{},
&serverHelloMsg{},
&finishedMsg{},

View file

@ -681,7 +681,7 @@ func (hs *serverHandshakeState) establishKeys() error {
clientMAC, serverMAC, clientKey, serverKey, clientIV, serverIV :=
keysFromMasterSecret(c.vers, hs.suite, hs.masterSecret, hs.clientHello.random, hs.hello.random, hs.suite.macLen, hs.suite.keyLen, hs.suite.ivLen)
var clientCipher, serverCipher interface{}
var clientCipher, serverCipher any
var clientHash, serverHash hash.Hash
if hs.suite.aead == nil {

View file

@ -249,7 +249,7 @@ func TestTLS12OnlyCipherSuites(t *testing.T) {
}
c, s := localPipe(t)
replyChan := make(chan interface{})
replyChan := make(chan any)
go func() {
cli := Client(c, testConfig)
cli.vers = clientHello.vers
@ -304,7 +304,7 @@ func TestTLSPointFormats(t *testing.T) {
}
c, s := localPipe(t)
replyChan := make(chan interface{})
replyChan := make(chan any)
go func() {
cli := Client(c, testConfig)
cli.vers = clientHello.vers
@ -600,7 +600,7 @@ func (test *serverTest) connFromCommand() (conn *recordingConn, child *exec.Cmd,
return nil, nil, err
}
connChan := make(chan interface{}, 1)
connChan := make(chan any, 1)
go func() {
tcpConn, err := l.Accept()
if err != nil {