use new time API

R=bradfitz, gri, r, dsymonds
CC=golang-dev
https://golang.org/cl/5390042
This commit is contained in:
Russ Cox 2011-11-30 12:01:46 -05:00
parent ff828b16dd
commit 37bb6649e2
4 changed files with 7 additions and 6 deletions

View File

@ -121,7 +121,7 @@ type Config struct {
// Time returns the current time as the number of seconds since the epoch. // Time returns the current time as the number of seconds since the epoch.
// If Time is nil, TLS uses the system time.Seconds. // If Time is nil, TLS uses the system time.Seconds.
Time func() int64 Time func() time.Time
// Certificates contains one or more certificate chains // Certificates contains one or more certificate chains
// to present to the other side of the connection. // to present to the other side of the connection.
@ -175,10 +175,10 @@ func (c *Config) rand() io.Reader {
return r return r
} }
func (c *Config) time() int64 { func (c *Config) time() time.Time {
t := c.Time t := c.Time
if t == nil { if t == nil {
t = time.Seconds t = time.Now
} }
return t() return t()
} }

View File

@ -32,7 +32,7 @@ func (c *Conn) clientHandshake() error {
nextProtoNeg: len(c.config.NextProtos) > 0, nextProtoNeg: len(c.config.NextProtos) > 0,
} }
t := uint32(c.config.time()) t := uint32(c.config.time().Unix())
hello.random[0] = byte(t >> 24) hello.random[0] = byte(t >> 24)
hello.random[1] = byte(t >> 16) hello.random[1] = byte(t >> 16)
hello.random[2] = byte(t >> 8) hello.random[2] = byte(t >> 8)

View File

@ -95,7 +95,7 @@ FindCipherSuite:
hello.vers = vers hello.vers = vers
hello.cipherSuite = suite.id hello.cipherSuite = suite.id
t := uint32(config.time()) t := uint32(config.time().Unix())
hello.random = make([]byte, 32) hello.random = make([]byte, 32)
hello.random[0] = byte(t >> 24) hello.random[0] = byte(t >> 24)
hello.random[1] = byte(t >> 16) hello.random[1] = byte(t >> 16)

View File

@ -15,6 +15,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
"time"
) )
type zeroSource struct{} type zeroSource struct{}
@ -31,7 +32,7 @@ var testConfig *Config
func init() { func init() {
testConfig = new(Config) testConfig = new(Config)
testConfig.Time = func() int64 { return 0 } testConfig.Time = func() time.Time { return time.Unix(0, 0) }
testConfig.Rand = zeroSource{} testConfig.Rand = zeroSource{}
testConfig.Certificates = make([]Certificate, 1) testConfig.Certificates = make([]Certificate, 1)
testConfig.Certificates[0].Certificate = [][]byte{testCertificate} testConfig.Certificates[0].Certificate = [][]byte{testCertificate}