FILE / ScuroNeko/mtg

mtglib/internal/obfuscation/conn.go

Исходный файл и его история в репозитории.
FILE fefc479f94ba9ce39138d7f8c4f57e02fe5fc1b5
Files
mtg/mtglib/internal/obfuscation/conn.go
T
2026-02-23 10:12:25 +01:00

35 lines
609 B
Go

package obfuscation
import (
"crypto/cipher"
"github.com/9seconds/mtg/v2/essentials"
)
type conn struct {
essentials.Conn
sendCipher cipher.Stream
recvCipher cipher.Stream
}
func (c conn) Read(p []byte) (int, error) {
n, err := c.Conn.Read(p)
if err != nil {
return n, err
}
c.recvCipher.XORKeyStream(p, p[:n])
return n, nil
}
func (c conn) Write(p []byte) (int, error) {
// yes, this is a bit violent and goes against a contract in io.Writer
// but we do it to avoid creating a new buffer just to perform this
// encryption.
c.sendCipher.XORKeyStream(p, p)
return c.Conn.Write(p)
}