写到一半发现之前的代码逻辑有问题

Signed-off-by: dmy@lab <dmy@lab.com>
This commit is contained in:
dmy@lab
2015-10-08 20:40:36 +08:00
parent 57e17afaf3
commit fc533656a0
8 changed files with 226 additions and 0 deletions

20
cipher/chacha.go Normal file
View File

@@ -0,0 +1,20 @@
package cipher
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{}
}

23
cipher/cipher.go Normal file
View File

@@ -0,0 +1,23 @@
package cipher
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:临时这样处理
}

15
cipher/communication.go Normal file
View File

@@ -0,0 +1,15 @@
package cipher
import (
// "github.com/TransX/cipher"
)
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
}