20
cipher/chacha.go
Normal file
20
cipher/chacha.go
Normal 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
23
cipher/cipher.go
Normal 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
15
cipher/communication.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user