20
tscipher/chacha.go
Normal file
20
tscipher/chacha.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package tscipher
|
||||
|
||||
type ChaCha struct {
|
||||
}
|
||||
|
||||
func (*ChaCha) Decrypt(data []byte) (decrypted []byte, err error) {
|
||||
decrypted = data
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
|
||||
func (*ChaCha) Encrypt(data []byte) (encryped []byte, err error) {
|
||||
encryped = data
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
|
||||
func NewChaCha() (cipher Cipher) {
|
||||
return &ChaCha{}
|
||||
}
|
||||
33
tscipher/cipher.go
Normal file
33
tscipher/cipher.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
5
tscipher/communication.go
Normal file
5
tscipher/communication.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package tscipher
|
||||
|
||||
import (
|
||||
// "github.com/TransX/cipher"
|
||||
)
|
||||
Reference in New Issue
Block a user