github.com/fumiama/terasu@v0.0.0-20240507144117-547a591149c0/terasu.go (about) 1 package terasu 2 3 import ( 4 "context" 5 "crypto/tls" 6 "unsafe" 7 ) 8 9 var DefaultFirstFragmentLen uint8 = 4 10 11 // Use terasu in this TLS conn 12 func Use(conn *tls.Conn) *Conn { 13 return (*Conn)(conn) 14 } 15 16 // Handshake do terasu handshake in this TLS conn 17 func (conn *Conn) Handshake(firstFragmentLen uint8) error { 18 expose := (*_trsconn)(unsafe.Pointer(conn)) 19 fnbak := expose.handshakeFn 20 expose.handshakeFn = conn.clientHandshake(firstFragmentLen) 21 defer func() { expose.handshakeFn = fnbak }() 22 return (*tls.Conn)(conn).Handshake() 23 } 24 25 // Handshake do terasu handshake with ctx in this TLS conn 26 func (conn *Conn) HandshakeContext(ctx context.Context, firstFragmentLen uint8) error { 27 expose := (*_trsconn)(unsafe.Pointer(conn)) 28 fnbak := expose.handshakeFn 29 expose.handshakeFn = conn.clientHandshake(firstFragmentLen) 30 defer func() { expose.handshakeFn = fnbak }() 31 return (*tls.Conn)(conn).HandshakeContext(ctx) 32 }