From aa6eb3f10b3a85c90ebfae57591e301fcae6d834 Mon Sep 17 00:00:00 2001 From: Samuel Stauffer Date: Wed, 19 Mar 2014 14:10:38 -0700 Subject: Rename DialSSL to DialTLS and remove DialTLS infavor of exporting StartTLS --- conn.go | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/conn.go b/conn.go index ab3f437..0c7ffa3 100644 --- a/conn.go +++ b/conn.go @@ -31,7 +31,7 @@ type messagePacket struct { // Conn represents an LDAP Connection type Conn struct { conn net.Conn - isSSL bool + isTLS bool isClosing bool Debug debugging chanConfirm chan bool @@ -55,31 +55,15 @@ func Dial(network, addr string) (*Conn, *Error) { return conn, nil } -// DialSSL connects to the given address on the given network using net.Dial -// and then sets up SSL connection and returns a new Conn for the connection. -func DialSSL(network, addr string, config *tls.Config) (*Conn, *Error) { - c, err := tls.Dial(network, addr, config) - if err != nil { - return nil, NewError(ErrorNetwork, err) - } - conn := NewConn(c) - conn.isSSL = true - conn.start() - return conn, nil -} - -// DialTLS connects to the given address on the given network using net.Dial -// and then starts a TLS session and returns a new Conn for the connection. +// DialTLS connects to the given address on the given network using tls.Dial +// and then returns a new Conn for the connection. func DialTLS(network, addr string, config *tls.Config) (*Conn, *Error) { - c, err := net.Dial(network, addr) + c, err := tls.Dial(network, addr, config) if err != nil { return nil, NewError(ErrorNetwork, err) } conn := NewConn(c) - if err := conn.startTLS(config); err != nil { - conn.Close() - return nil, NewError(ErrorNetwork, err.Err) - } + conn.isTLS = true conn.start() return conn, nil } @@ -134,10 +118,10 @@ func (l *Conn) nextMessageID() uint64 { } // StartTLS sends the command to start a TLS session and then creates a new TLS Client -func (l *Conn) startTLS(config *tls.Config) *Error { +func (l *Conn) StartTLS(config *tls.Config) *Error { messageID := l.nextMessageID() - if l.isSSL { + if l.isTLS { return NewError(ErrorNetwork, errors.New("ldap: already encrypted")) } @@ -167,7 +151,7 @@ func (l *Conn) startTLS(config *tls.Config) *Error { if packet.Children[1].Children[0].Value.(uint64) == 0 { conn := tls.Client(l.conn, config) - l.isSSL = true + l.isTLS = true l.conn = conn } -- cgit v1.2.3