package obfuscated2
import (
"io"
"github.com/go-faster/errors"
"github.com/gotd/td/internal/mtproxy"
)
type Obfuscated2 struct {
rand io .Reader
conn io .ReadWriter
keys
}
func NewObfuscated2 (r io .Reader , conn io .ReadWriter ) *Obfuscated2 {
return &Obfuscated2 {
rand : r ,
conn : conn ,
}
}
func (o *Obfuscated2 ) Handshake (protocol [4 ]byte , dc int , s mtproxy .Secret ) error {
k , err := generateKeys (o .rand , protocol , s .Secret , dc )
if err != nil {
return errors .Wrap (err , "generate keys" )
}
o .keys = k
if _ , err := o .conn .Write (o .header ); err != nil {
return errors .Wrap (err , "write obfuscated header" )
}
return nil
}
func (o *Obfuscated2 ) Write (b []byte ) (n int , err error ) {
cpyB := append ([]byte (nil ), b ...)
o .encrypt .XORKeyStream (cpyB , b )
return o .conn .Write (cpyB )
}
func (o *Obfuscated2 ) Read (b []byte ) (int , error ) {
n , err := o .conn .Read (b )
if err != nil {
return n , err
}
if n > 0 {
o .decrypt .XORKeyStream (b , b )
}
return n , err
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .