From 37bb6649e27e545d2b9387e0a5c41db51379ed1d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Nov 2011 12:01:46 -0500 Subject: [PATCH] use new time API R=bradfitz, gri, r, dsymonds CC=golang-dev https://golang.org/cl/5390042 --- common.go | 6 +++--- handshake_client.go | 2 +- handshake_server.go | 2 +- handshake_server_test.go | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/common.go b/common.go index e904248..f57d932 100644 --- a/common.go +++ b/common.go @@ -121,7 +121,7 @@ type Config struct { // Time returns the current time as the number of seconds since the epoch. // If Time is nil, TLS uses the system time.Seconds. - Time func() int64 + Time func() time.Time // Certificates contains one or more certificate chains // to present to the other side of the connection. @@ -175,10 +175,10 @@ func (c *Config) rand() io.Reader { return r } -func (c *Config) time() int64 { +func (c *Config) time() time.Time { t := c.Time if t == nil { - t = time.Seconds + t = time.Now } return t() } diff --git a/handshake_client.go b/handshake_client.go index 0f41008..5559c7a 100644 --- a/handshake_client.go +++ b/handshake_client.go @@ -32,7 +32,7 @@ func (c *Conn) clientHandshake() error { 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[1] = byte(t >> 16) hello.random[2] = byte(t >> 8) diff --git a/handshake_server.go b/handshake_server.go index 1fa4585..11ea500 100644 --- a/handshake_server.go +++ b/handshake_server.go @@ -95,7 +95,7 @@ FindCipherSuite: hello.vers = vers hello.cipherSuite = suite.id - t := uint32(config.time()) + t := uint32(config.time().Unix()) hello.random = make([]byte, 32) hello.random[0] = byte(t >> 24) hello.random[1] = byte(t >> 16) diff --git a/handshake_server_test.go b/handshake_server_test.go index bc37979..e00c32c 100644 --- a/handshake_server_test.go +++ b/handshake_server_test.go @@ -15,6 +15,7 @@ import ( "strconv" "strings" "testing" + "time" ) type zeroSource struct{} @@ -31,7 +32,7 @@ var testConfig *Config func init() { testConfig = new(Config) - testConfig.Time = func() int64 { return 0 } + testConfig.Time = func() time.Time { return time.Unix(0, 0) } testConfig.Rand = zeroSource{} testConfig.Certificates = make([]Certificate, 1) testConfig.Certificates[0].Certificate = [][]byte{testCertificate}