crypto/tls: use method values

Currently fails with a compiler error, though.

R=golang-dev, agl, rsc
CC=golang-dev
https://golang.org/cl/7933043
This commit is contained in:
Brad Fitzpatrick 2013-03-20 23:53:38 -04:00 committed by Russ Cox
parent b9ddc2767a
commit 4b14a48417
2 changed files with 19 additions and 17 deletions

View File

@ -204,7 +204,24 @@ type Config struct {
// connections using that key are compromised. // connections using that key are compromised.
SessionTicketKey [32]byte SessionTicketKey [32]byte
serverInitOnce sync.Once serverInitOnce sync.Once // guards calling (*Config).serverInit
}
func (c *Config) serverInit() {
if c.SessionTicketsDisabled {
return
}
// If the key has already been set then we have nothing to do.
for _, b := range c.SessionTicketKey {
if b != 0 {
return
}
}
if _, err := io.ReadFull(c.rand(), c.SessionTicketKey[:]); err != nil {
c.SessionTicketsDisabled = true
}
} }
func (c *Config) rand() io.Reader { func (c *Config) rand() io.Reader {

View File

@ -33,22 +33,7 @@ func (c *Conn) serverHandshake() error {
// If this is the first server handshake, we generate a random key to // If this is the first server handshake, we generate a random key to
// encrypt the tickets with. // encrypt the tickets with.
config.serverInitOnce.Do(func() { config.serverInitOnce.Do(config.serverInit)
if config.SessionTicketsDisabled {
return
}
// If the key has already been set then we have nothing to do.
for _, b := range config.SessionTicketKey {
if b != 0 {
return
}
}
if _, err := io.ReadFull(config.rand(), config.SessionTicketKey[:]); err != nil {
config.SessionTicketsDisabled = true
}
})
hs := serverHandshakeState{ hs := serverHandshakeState{
c: c, c: c,