crypto/...: more fixes for bug 2841

1) Remove the Reset() member in crypto/aes and crypto/des (and
   document the change).
2) Turn several empty error structures into vars. Any remaining error
   structures are either non-empty, or will probably become so in the
   future.
3) Implement SetWriteDeadline for TLS sockets. At the moment, the TLS
   status cannot be reused after a Write error, which is probably fine
   for most uses.
4) Make crypto/aes and crypto/des return a cipher.Block.

R=rsc, r
CC=golang-dev
https://golang.org/cl/5625045
This commit is contained in:
Adam Langley 2012-02-13 12:38:45 -05:00
parent afe534d19b
commit b9f16c6d7d

31
conn.go
View File

@ -87,9 +87,9 @@ func (c *Conn) RemoteAddr() net.Addr {
return c.conn.RemoteAddr() return c.conn.RemoteAddr()
} }
// SetDeadline sets the read deadline associated with the connection. // SetDeadline sets the read and write deadlines associated with the connection.
// There is no write deadline. // A zero value for t means Read and Write will not time out.
// A zero value for t means Read will not time out. // After a Write has timed out, the TLS state is corrupt and all future writes will return the same error.
func (c *Conn) SetDeadline(t time.Time) error { func (c *Conn) SetDeadline(t time.Time) error {
return c.conn.SetDeadline(t) return c.conn.SetDeadline(t)
} }
@ -100,10 +100,11 @@ func (c *Conn) SetReadDeadline(t time.Time) error {
return c.conn.SetReadDeadline(t) return c.conn.SetReadDeadline(t)
} }
// SetWriteDeadline exists to satisfy the net.Conn interface // SetWriteDeadline sets the write deadline on the underlying conneciton.
// but is not implemented by TLS. It always returns an error. // A zero value for t means Write will not time out.
// After a Write has timed out, the TLS state is corrupt and all future writes will return the same error.
func (c *Conn) SetWriteDeadline(t time.Time) error { func (c *Conn) SetWriteDeadline(t time.Time) error {
return errors.New("TLS does not support SetWriteDeadline") return c.conn.SetWriteDeadline(t)
} }
// A halfConn represents one direction of the record layer // A halfConn represents one direction of the record layer
@ -726,9 +727,13 @@ func (c *Conn) readHandshake() (interface{}, error) {
} }
// Write writes data to the connection. // Write writes data to the connection.
func (c *Conn) Write(b []byte) (n int, err error) { func (c *Conn) Write(b []byte) (int, error) {
if err = c.Handshake(); err != nil { if c.err != nil {
return return 0, c.err
}
if c.err = c.Handshake(); c.err != nil {
return 0, c.err
} }
c.out.Lock() c.out.Lock()
@ -737,10 +742,10 @@ func (c *Conn) Write(b []byte) (n int, err error) {
if !c.handshakeComplete { if !c.handshakeComplete {
return 0, alertInternalError return 0, alertInternalError
} }
if c.err != nil {
return 0, c.err var n int
} n, c.err = c.writeRecord(recordTypeApplicationData, b)
return c.writeRecord(recordTypeApplicationData, b) return n, c.err
} }
// Read can be made to time out and return a net.Error with Timeout() == true // Read can be made to time out and return a net.Error with Timeout() == true