mirror of
https://github.com/fumiama/terasu.git
synced 2026-06-05 01:00:23 +08:00
33 lines
903 B
Go
33 lines
903 B
Go
package terasu
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"unsafe"
|
|
)
|
|
|
|
var DefaultFirstFragmentLen uint8 = 3
|
|
|
|
// Use terasu in this TLS conn
|
|
func Use(conn *tls.Conn) *Conn {
|
|
return (*Conn)(conn)
|
|
}
|
|
|
|
// Handshake do terasu handshake in this TLS conn
|
|
func (conn *Conn) Handshake(firstFragmentLen uint8) error {
|
|
expose := (*_trsconn)(unsafe.Pointer(conn))
|
|
fnbak := expose.handshakeFn
|
|
expose.handshakeFn = conn.clientHandshake(firstFragmentLen)
|
|
defer func() { expose.handshakeFn = fnbak }()
|
|
return (*tls.Conn)(conn).Handshake()
|
|
}
|
|
|
|
// Handshake do terasu handshake with ctx in this TLS conn
|
|
func (conn *Conn) HandshakeContext(ctx context.Context, firstFragmentLen uint8) error {
|
|
expose := (*_trsconn)(unsafe.Pointer(conn))
|
|
fnbak := expose.handshakeFn
|
|
expose.handshakeFn = conn.clientHandshake(firstFragmentLen)
|
|
defer func() { expose.handshakeFn = fnbak }()
|
|
return (*tls.Conn)(conn).HandshakeContext(ctx)
|
|
}
|