FILE / ScuroNeko/mtg

mtglib/internal/obfuscated2/conn.go

Исходный файл и его история в репозитории.
FILE 38ff62fddcab66017c7e1cde08383e2da5a32de5
Files
mtg/mtglib/internal/obfuscated2/conn.go
T

37 lines
545 B
Go

package obfuscated2
import (
"crypto/cipher"
"net"
)
type Conn struct {
net.Conn
Encryptor cipher.Stream
Decryptor cipher.Stream
}
func (c Conn) Read(p []byte) (int, error) {
n, err := c.Conn.Read(p)
if err != nil {
return n, err // nolint: wrapcheck
}
c.Decryptor.XORKeyStream(p, p[:n])
return n, nil
}
func (c Conn) Write(p []byte) (int, error) {
buf := acquireBytesBuffer()
defer releaseBytesBuffer(buf)
buf.Write(p)
payload := buf.Bytes()
c.Encryptor.XORKeyStream(payload, payload)
return c.Conn.Write(payload)
}