Skip to content

Commit

Permalink
Replace interface{} with any
Browse files Browse the repository at this point in the history
Satisfy a go lint. As of Go 1.18, any is the preferred spelling of
interface{}.

Also remove an instance of redundant types in
util/fipstools/acvp/acvptool/acvp.go because my editor warned about it.
(A []map[string]any{map[string]any{...}, map[string]any{...}} literal
can omit the inner copy of the type because it's implicit from the outer
one.)

Change-Id: I2251b2285c16c19bc779fa41d1011f7fa1392563
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/59465
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
(cherry picked from commit 77b6f2593543474bf5d2fb4821dfe31b32c7fc22)
  • Loading branch information
davidben authored and torben-hansen committed Jun 29, 2023
1 parent e469b75 commit 6a90c15
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 89 deletions.
8 changes: 4 additions & 4 deletions ssl/test/runner/cipher_suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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(version uint16, macKey []byte) macFunction
aead func(version uint16, key, fixedNonce []byte) *tlsAead
}
Expand Down Expand Up @@ -155,19 +155,19 @@ func ivLen3DES(vers uint16) int {

type nullCipher struct{}

func cipherNull(key, iv []byte, isRead bool) interface{} {
func cipherNull(key, iv []byte, isRead bool) any {
return nullCipher{}
}

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)
}
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)
Expand Down
8 changes: 4 additions & 4 deletions ssl/test/runner/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2182,11 +2182,11 @@ type lruSessionCache struct {

type lruSessionCacheEntry struct {
sessionKey string
state interface{}
state any
}

// Put adds the provided (sessionKey, cs) pair to the cache.
func (c *lruSessionCache) Put(sessionKey string, cs interface{}) {
func (c *lruSessionCache) Put(sessionKey string, cs any) {
c.Lock()
defer c.Unlock()

Expand Down Expand Up @@ -2214,7 +2214,7 @@ func (c *lruSessionCache) Put(sessionKey string, cs interface{}) {

// Get returns the value associated with a given key. It returns (nil,
// false) if no value is found.
func (c *lruSessionCache) Get(sessionKey string) (interface{}, bool) {
func (c *lruSessionCache) Get(sessionKey string) (any, bool) {
c.Lock()
defer c.Unlock()

Expand Down Expand Up @@ -2328,7 +2328,7 @@ func initDefaultCipherSuites() {
}
}

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)
}

Expand Down
8 changes: 4 additions & 4 deletions ssl/test/runner/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ type halfConn struct {
version uint16 // protocol version
wireVersion uint16 // wire version
isDTLS bool
cipher interface{} // cipher algorithm
cipher any // cipher algorithm
mac macFunction
seq [8]byte // 64-bit sequence number
outSeq [8]byte // Mapped sequence number
bfree *block // list of free blocks

nextCipher interface{} // next encryption state
nextCipher any // next encryption state
nextMac macFunction // next MAC algorithm
nextSeq [6]byte // next epoch's starting sequence number in DTLS

Expand All @@ -207,7 +207,7 @@ func (hc *halfConn) error() error {

// prepareCipherSpec sets the encryption and MAC states
// that a subsequent changeCipherSpec will use.
func (hc *halfConn) prepareCipherSpec(version uint16, cipher interface{}, mac macFunction) {
func (hc *halfConn) prepareCipherSpec(version uint16, cipher any, mac macFunction) {
hc.wireVersion = version
protocolVersion, ok := wireToVersion(version, hc.isDTLS)
if !ok {
Expand Down Expand Up @@ -1336,7 +1336,7 @@ func (c *Conn) doReadHandshake() ([]byte, error) {
// readHandshake reads the next handshake message from
// the record layer.
// c.in.Mutex < L; c.out.Mutex < L.
func (c *Conn) readHandshake() (interface{}, error) {
func (c *Conn) readHandshake() (any, error) {
data, err := c.doReadHandshake()
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions ssl/test/runner/handshake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ func (hs *clientHandshakeState) encryptClientHello(hello, innerHello *clientHell
return nil
}

func (hs *clientHandshakeState) checkECHConfirmation(msg interface{}, hello *clientHelloMsg, finishedHash *finishedHash) bool {
func (hs *clientHandshakeState) checkECHConfirmation(msg any, hello *clientHelloMsg, finishedHash *finishedHash) bool {
var offset int
var raw, label []byte
if hrr, ok := msg.(*helloRetryRequestMsg); ok {
Expand All @@ -950,7 +950,7 @@ func (hs *clientHandshakeState) checkECHConfirmation(msg interface{}, hello *cli
return bytes.Equal(confirmation, raw[offset:offset+echAcceptConfirmationLength])
}

func (hs *clientHandshakeState) doTLS13Handshake(msg interface{}) error {
func (hs *clientHandshakeState) doTLS13Handshake(msg any) error {
c := hs.c

// The first message may be a ServerHello or HelloRetryRequest.
Expand Down Expand Up @@ -1897,7 +1897,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(c.vers))
var clientCipher, serverCipher interface{}
var clientCipher, serverCipher any
var clientHash, serverHash macFunction
if hs.suite.cipher != nil {
clientCipher = hs.suite.cipher(clientKey, clientIV, false /* not for reading */)
Expand Down
2 changes: 1 addition & 1 deletion ssl/test/runner/handshake_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,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(c.vers))

var clientCipher, serverCipher interface{}
var clientCipher, serverCipher any
var clientHash, serverHash macFunction

if hs.suite.aead == nil {
Expand Down
2 changes: 1 addition & 1 deletion ssl/test/runner/prf.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ var (

// deriveTrafficAEAD derives traffic keys and constructs an AEAD given a traffic
// secret.
func deriveTrafficAEAD(version uint16, suite *cipherSuite, secret []byte, side trafficDirection) interface{} {
func deriveTrafficAEAD(version uint16, suite *cipherSuite, secret []byte, side trafficDirection) any {
key := hkdfExpandLabel(suite.hash(), secret, keyTLS13, nil, suite.keyLen)
iv := hkdfExpandLabel(suite.hash(), secret, ivTLS13, nil, suite.ivLen(version))

Expand Down
2 changes: 1 addition & 1 deletion ssl/test/runner/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (e *ed25519Signer) verifyMessage(key crypto.PublicKey, msg, sig []byte) err
return nil
}

func getSigner(version uint16, key interface{}, config *Config, sigAlg signatureAlgorithm, isVerify bool) (signer, error) {
func getSigner(version uint16, key any, config *Config, sigAlg signatureAlgorithm, isVerify bool) (signer, error) {
// TLS 1.1 and below use legacy signature algorithms.
if version < VersionTLS12 || (!isVerify && config.Bugs.AlwaysSignAsLegacyVersion) {
if config.Bugs.SigningAlgorithmForLegacyVersions == 0 || isVerify {
Expand Down
24 changes: 12 additions & 12 deletions util/convert_wycheproof/convert_wycheproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ type wycheproofTest struct {
Header []string `json:"header"`
// encoding/json does not support collecting unused keys, so we leave
// everything past this point as generic.
TestGroups []map[string]interface{} `json:"testGroups"`
TestGroups []map[string]any `json:"testGroups"`
}

func sortedKeys(m map[string]interface{}) []string {
func sortedKeys(m map[string]any) []string {
keys := make([]string, 0, len(m))
for k, _ := range m {
keys = append(keys, k)
Expand All @@ -45,8 +45,8 @@ func sortedKeys(m map[string]interface{}) []string {
return keys
}

func printAttribute(w io.Writer, key string, valueI interface{}, isInstruction bool) error {
switch value := valueI.(type) {
func printAttribute(w io.Writer, key string, valueAny any, isInstruction bool) error {
switch value := valueAny.(type) {
case float64:
if float64(int(value)) != value {
panic(key + "was not an integer.")
Expand All @@ -73,14 +73,14 @@ func printAttribute(w io.Writer, key string, valueI interface{}, isInstruction b
return err
}
}
case map[string]interface{}:
case map[string]any:
for _, k := range sortedKeys(value) {
if err := printAttribute(w, key+"."+k, value[k], isInstruction); err != nil {
return err
}
}
default:
panic(fmt.Sprintf("Unknown type for %q: %T", key, valueI))
panic(fmt.Sprintf("Unknown type for %q: %T", key, valueAny))
}
return nil
}
Expand Down Expand Up @@ -154,9 +154,9 @@ func convertWycheproof(f io.Writer, jsonPath string) error {
}
}
fmt.Fprintf(f, "\n")
tests := group["tests"].([]interface{})
for _, testI := range tests {
test := testI.(map[string]interface{})
tests := group["tests"].([]any)
for _, testAny := range tests {
test := testAny.(map[string]any)
if _, err := fmt.Fprintf(f, "# tcId = %d\n", int(test["tcId"].(float64))); err != nil {
return err
}
Expand All @@ -173,10 +173,10 @@ func convertWycheproof(f io.Writer, jsonPath string) error {
return err
}
}
if flagsI, ok := test["flags"]; ok {
if flagsAny, ok := test["flags"]; ok {
var flags []string
for _, flagI := range flagsI.([]interface{}) {
flag := flagI.(string)
for _, flagAny := range flagsAny.([]any) {
flag := flagAny.(string)
flags = append(flags, flag)
}
if len(flags) != 0 {
Expand Down
20 changes: 10 additions & 10 deletions util/fipstools/acvp/acvptool/acvp.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func isCommentLine(line []byte) bool {
return false
}

func jsonFromFile(out interface{}, filename string) error {
func jsonFromFile(out any, filename string) error {
in, err := os.Open(filename)
if err != nil {
return err
Expand Down Expand Up @@ -131,7 +131,7 @@ func TOTP(secret []byte) string {
type Middle interface {
Close()
Config() ([]byte, error)
Process(algorithm string, vectorSet []byte) (interface{}, error)
Process(algorithm string, vectorSet []byte) (any, error)
}

func loadCachedSessionTokens(server *acvp.Server, cachePath string) error {
Expand Down Expand Up @@ -198,7 +198,7 @@ func looksLikeVectorSetHeader(element json.RawMessage) bool {

// processFile reads a file containing vector sets, at least in the format
// preferred by our lab, and writes the results to stdout.
func processFile(filename string, supportedAlgos []map[string]interface{}, middle Middle) error {
func processFile(filename string, supportedAlgos []map[string]any, middle Middle) error {
jsonBytes, err := os.ReadFile(filename)
if err != nil {
return err
Expand Down Expand Up @@ -267,7 +267,7 @@ func processFile(filename string, supportedAlgos []map[string]interface{}, middl
return fmt.Errorf("while processing vector set #%d: %s", i+1, err)
}

group := map[string]interface{}{
group := map[string]any{
"vsId": commonFields.ID,
"testGroups": replyGroups,
"algorithm": algo,
Expand Down Expand Up @@ -540,13 +540,13 @@ func main() {
log.Fatalf("failed to get config from middle: %s", err)
}

var supportedAlgos []map[string]interface{}
var supportedAlgos []map[string]any
if err := json.Unmarshal(configBytes, &supportedAlgos); err != nil {
log.Fatalf("failed to parse configuration from Middle: %s", err)
}

if *dumpRegcap {
nonTestAlgos := make([]map[string]interface{}, 0, len(supportedAlgos))
nonTestAlgos := make([]map[string]any, 0, len(supportedAlgos))
for _, algo := range supportedAlgos {
if value, ok := algo["acvptoolTestOnly"]; ok {
testOnly, ok := value.(bool)
Expand All @@ -560,9 +560,9 @@ func main() {
nonTestAlgos = append(nonTestAlgos, algo)
}

regcap := []map[string]interface{}{
map[string]interface{}{"acvVersion": "1.0"},
map[string]interface{}{"algorithms": nonTestAlgos},
regcap := []map[string]any{
{"acvVersion": "1.0"},
{"algorithms": nonTestAlgos},
}
regcapBytes, err := json.MarshalIndent(regcap, "", " ")
if err != nil {
Expand Down Expand Up @@ -637,7 +637,7 @@ func main() {
}
}

var algorithms []map[string]interface{}
var algorithms []map[string]any
for _, supportedAlgo := range supportedAlgos {
algoInterface, ok := supportedAlgo["algorithm"]
if !ok {
Expand Down
40 changes: 20 additions & 20 deletions util/fipstools/acvp/acvptool/acvp/acvp.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func parseReplyToBytes(in io.Reader) ([]byte, error) {
// parseReply parses the contents of an ACVP reply (after removing the header
// element) into out. See the documentation of the encoding/json package for
// details of the parsing.
func parseReply(out interface{}, in io.Reader) error {
func parseReply(out any, in io.Reader) error {
if out == nil {
// No reply expected.
return nil
Expand Down Expand Up @@ -379,7 +379,7 @@ func (server *Server) newRequestWithToken(method, endpoint string, body io.Reade
return req, nil
}

func (server *Server) Get(out interface{}, endPoint string) error {
func (server *Server) Get(out any, endPoint string) error {
req, err := server.newRequestWithToken("GET", endPoint, nil)
if err != nil {
return err
Expand Down Expand Up @@ -417,7 +417,7 @@ func (server *Server) GetBytes(endPoint string) ([]byte, error) {
return parseReplyToBytes(resp.Body)
}

func (server *Server) write(method string, reply interface{}, endPoint string, contents []byte) error {
func (server *Server) write(method string, reply any, endPoint string, contents []byte) error {
var buf bytes.Buffer
buf.WriteString(requestPrefix)
buf.Write(contents)
Expand All @@ -442,19 +442,19 @@ func (server *Server) write(method string, reply interface{}, endPoint string, c
return parseReply(reply, resp.Body)
}

func (server *Server) postMessage(reply interface{}, endPoint string, request interface{}) error {
func (server *Server) postMessage(reply any, endPoint string, request any) error {
contents, err := json.Marshal(request)
if err != nil {
return err
}
return server.write("POST", reply, endPoint, contents)
}

func (server *Server) Post(out interface{}, endPoint string, contents []byte) error {
func (server *Server) Post(out any, endPoint string, contents []byte) error {
return server.write("POST", out, endPoint, contents)
}

func (server *Server) Put(out interface{}, endPoint string, contents []byte) error {
func (server *Server) Put(out any, endPoint string, contents []byte) error {
return server.write("PUT", out, endPoint, contents)
}

Expand All @@ -481,7 +481,7 @@ var (

// GetPaged returns an array of records of some type using one or more requests to the server. See
// https://pages.nist.gov/ACVP/draft-fussell-acvp-spec.html#paging_response
func (server *Server) GetPaged(out interface{}, endPoint string, condition Query) error {
func (server *Server) GetPaged(out any, endPoint string, condition Query) error {
output := reflect.ValueOf(out)
if output.Kind() != reflect.Ptr {
panic(fmt.Sprintf("GetPaged output parameter of non-pointer type %T", out))
Expand Down Expand Up @@ -618,22 +618,22 @@ type OperationalEnvironment struct {
Dependencies []Dependency `json:"dependencies,omitempty"`
}

type Dependency map[string]interface{}
type Dependency map[string]any

type Algorithm map[string]interface{}
type Algorithm map[string]any

type TestSession struct {
URL string `json:"url,omitempty"`
ACVPVersion string `json:"acvpVersion,omitempty"`
Created string `json:"createdOn,omitempty"`
Expires string `json:"expiresOn,omitempty"`
VectorSetURLs []string `json:"vectorSetUrls,omitempty"`
AccessToken string `json:"accessToken,omitempty"`
Algorithms []map[string]interface{} `json:"algorithms,omitempty"`
EncryptAtRest bool `json:"encryptAtRest,omitempty"`
IsSample bool `json:"isSample,omitempty"`
Publishable bool `json:"publishable,omitempty"`
Passed bool `json:"passed,omitempty"`
URL string `json:"url,omitempty"`
ACVPVersion string `json:"acvpVersion,omitempty"`
Created string `json:"createdOn,omitempty"`
Expires string `json:"expiresOn,omitempty"`
VectorSetURLs []string `json:"vectorSetUrls,omitempty"`
AccessToken string `json:"accessToken,omitempty"`
Algorithms []map[string]any `json:"algorithms,omitempty"`
EncryptAtRest bool `json:"encryptAtRest,omitempty"`
IsSample bool `json:"isSample,omitempty"`
Publishable bool `json:"publishable,omitempty"`
Passed bool `json:"passed,omitempty"`
}

type Vectors struct {
Expand Down
Loading

0 comments on commit 6a90c15

Please sign in to comment.