Skip to content

Commit

Permalink
crypto/tls: avoid referencing potentially unused symbols in init
Browse files Browse the repository at this point in the history
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 <filippo@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
neild committed May 26, 2023
1 parent f89d575 commit a4cd365
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/crypto/tls/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/crypto/tls/ticket_test.go
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit a4cd365

Please sign in to comment.