github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/lib/net/tls/api.go (about)

     1  package tls
     2  
     3  import (
     4  	"crypto/tls"
     5  	"crypto/x509"
     6  	"net"
     7  )
     8  
     9  // Dialer defines a dialer that can be use to create connections.
    10  type Dialer interface {
    11  	Dial(network, address string) (net.Conn, error)
    12  }
    13  
    14  type TlsDialer struct {
    15  	config *tls.Config
    16  	dialer Dialer
    17  }
    18  
    19  // NewDialer creates a Dialer that will use the provided dialer to create TLS
    20  // connections. If the provided dialer is nil the default dialer is used. The
    21  // TLS configuration to use is given by config, which is cloned. If config is
    22  // nil the default configuration is used. A new (TLS) dialer is returned.
    23  func NewDialer(dialer Dialer, config *tls.Config) *TlsDialer {
    24  	return newDialer(dialer, config)
    25  }
    26  
    27  // Dial will dial an address and returns a TLS connection.
    28  func (d *TlsDialer) Dial(network, address string) (net.Conn, error) {
    29  	return d.dial(network, address)
    30  }
    31  
    32  // NewTestCertificate will return a self-signed certificate for IP address
    33  // 127.0.0.1 that may be used for testing purposes.
    34  func NewTestCertificate() (tls.Certificate, *x509.Certificate, error) {
    35  	return newTestCertificate()
    36  }