transx/tscipher/cipher.go

34 lines
622 B
Go

package tscipher
import (
"net"
)
type Cipher interface {
Decrypt(data []byte) (decrypted []byte, err error)
Encrypt(data []byte) (encryped []byte, err error)
}
type Carrier struct {
Conn net.Conn
Cipher Cipher
Cache []byte
}
func NewCipher(cipherName string) (cipher Cipher) {
if cipherName == "default" {
return NewChaCha()
}
return nil //TODO:临时这样处理
}
func SendData(carrier *Carrier, nByte int) (n int, err error) {
n, err = carrier.Conn.Write(carrier.Cache[:nByte])
return
}
func ReceiveData(carrier *Carrier) (n int, err error) {
n, err = carrier.Conn.Read(carrier.Cache)
return
}