mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-03 06:27:47 +00:00
67b8a341a6
Verified on Arduino Nano33 IoT and nina fw v1.4.5
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
// Package tls is intended to provide a minimal set of compatible interfaces with the
|
|
// Go standard library's tls package.
|
|
package tls
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"tinygo.org/x/drivers/net"
|
|
)
|
|
|
|
// Dial makes a TLS network connection. It tries to provide a mostly compatible interface
|
|
// to tls.Dial().
|
|
// Dial connects to the given network address.
|
|
func Dial(network, address string, config *Config) (*net.TCPSerialConn, error) {
|
|
raddr, err := net.ResolveTCPAddr(network, address)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
hostname := strings.Split(address, ":")[0]
|
|
sendport := strconv.Itoa(raddr.Port)
|
|
if sendport == "0" {
|
|
sendport = "443"
|
|
}
|
|
|
|
// disconnect any old socket
|
|
net.ActiveDevice.DisconnectSocket()
|
|
|
|
// connect new socket
|
|
err = net.ActiveDevice.ConnectSSLSocket(hostname, sendport)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return net.NewTCPSerialConn(net.SerialConn{Adaptor: net.ActiveDevice}, nil, raddr), nil
|
|
}
|
|
|
|
// Config is a placeholder for future compatibility with
|
|
// tls.Config.
|
|
type Config struct {
|
|
}
|