From a4cd36500b8c2f25827afb8baae4fb539bc88256 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Fri, 26 May 2023 07:57:45 -0700 Subject: [PATCH] crypto/tls: avoid referencing potentially unused symbols in init A reference to a function in a "var _ = ..." init-time initialization keeps the symbol live. Move references to Config.EncryptTicket and Config.DecryptTicket into tests. These references increase the size of an unused import of crypto/tls by about 1MiB. Change-Id: I6d62a6dcbd73e22972a217afcda7395e909b52cc Reviewed-on: https://go-review.googlesource.com/c/go/+/498595 Reviewed-by: Filippo Valsorda Run-TryBot: Damien Neil Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot --- src/crypto/tls/ticket.go | 4 ---- src/crypto/tls/ticket_test.go | 8 ++++++++ 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 src/crypto/tls/ticket_test.go diff --git a/src/crypto/tls/ticket.go b/src/crypto/tls/ticket.go index 1a94c04eee372d..1a3d0c7cfdef25 100644 --- a/src/crypto/tls/ticket.go +++ b/src/crypto/tls/ticket.go @@ -301,8 +301,6 @@ func (c *Config) EncryptTicket(cs ConnectionState, ss *SessionState) ([]byte, er return c.encryptTicket(stateBytes, ticketKeys) } -var _ = &Config{WrapSession: (&Config{}).EncryptTicket} - func (c *Config) encryptTicket(state []byte, ticketKeys []ticketKey) ([]byte, error) { if len(ticketKeys) == 0 { return nil, errors.New("tls: internal error: session ticket keys unavailable") @@ -348,8 +346,6 @@ func (c *Config) DecryptTicket(identity []byte, cs ConnectionState) (*SessionSta return s, nil } -var _ = &Config{UnwrapSession: (&Config{}).DecryptTicket} - func (c *Config) decryptTicket(encrypted []byte, ticketKeys []ticketKey) []byte { if len(encrypted) < aes.BlockSize+sha256.Size { return nil diff --git a/src/crypto/tls/ticket_test.go b/src/crypto/tls/ticket_test.go new file mode 100644 index 00000000000000..f925451cef0340 --- /dev/null +++ b/src/crypto/tls/ticket_test.go @@ -0,0 +1,8 @@ +// Copyright 2023 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. + +package tls + +var _ = &Config{WrapSession: (&Config{}).EncryptTicket} +var _ = &Config{UnwrapSession: (&Config{}).DecryptTicket}