ceremonyclient/go-libp2p/p2p/net/pnet/protector.go
2023-08-20 23:07:43 -05:00

19 lines
355 B
Go

package pnet
import (
"errors"
"net"
ipnet "github.com/libp2p/go-libp2p/core/pnet"
)
// NewProtectedConn creates a new protected connection
func NewProtectedConn(psk ipnet.PSK, conn net.Conn) (net.Conn, error) {
if len(psk) != 32 {
return nil, errors.New("expected 32 byte PSK")
}
var p [32]byte
copy(p[:], psk)
return newPSKConn(&p, conn)
}