mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
chore: add comments to export functions
This commit is contained in:
1 parent
417ac556f7
commit
8a2e95b17e
9 files changed
+33
-12
No files matched your search
@@ -10,15 +10,18 @@ import (
|
||||
"github.com/nadoo/glider/proxy/ss/cipher/internal/shadowstream"
|
||||
)
|
||||
|
||||
// Cipher interface.
|
||||
type Cipher interface {
|
||||
StreamConnCipher
|
||||
PacketConnCipher
|
||||
}
|
||||
|
||||
// StreamConnCipher is the stream connection cipher.
|
||||
type StreamConnCipher interface {
|
||||
StreamConn(net.Conn) net.Conn
|
||||
}
|
||||
|
||||
// StreamConnCipher is the packet connection cipher.
|
||||
type PacketConnCipher interface {
|
||||
PacketConn(net.PacketConn) net.PacketConn
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"golang.org/x/crypto/hkdf"
|
||||
)
|
||||
|
||||
// Cipher generates a pair of stream ciphers for encryption and decryption.
|
||||
type Cipher interface {
|
||||
KeySize() int
|
||||
SaltSize() int
|
||||
@@ -18,6 +19,7 @@ type Cipher interface {
|
||||
Decrypter(salt []byte) (cipher.AEAD, error)
|
||||
}
|
||||
|
||||
// KeySizeError is an error about the key size.
|
||||
type KeySizeError int
|
||||
|
||||
func (e KeySizeError) Error() string {
|
||||
|
||||
@@ -18,6 +18,7 @@ type Cipher interface {
|
||||
Decrypter(iv []byte) cipher.Stream
|
||||
}
|
||||
|
||||
// KeySizeError is an error about the key size.
|
||||
type KeySizeError int
|
||||
|
||||
func (e KeySizeError) Error() string {
|
||||
@@ -31,6 +32,7 @@ func (b *ctrStream) IVSize() int { return b.BlockSize() }
|
||||
func (b *ctrStream) Decrypter(iv []byte) cipher.Stream { return b.Encrypter(iv) }
|
||||
func (b *ctrStream) Encrypter(iv []byte) cipher.Stream { return cipher.NewCTR(b, iv) }
|
||||
|
||||
// AESCTR returns an aesctr cipher.
|
||||
func AESCTR(key []byte) (Cipher, error) {
|
||||
blk, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
@@ -46,6 +48,7 @@ func (b *cfbStream) IVSize() int { return b.BlockSize() }
|
||||
func (b *cfbStream) Decrypter(iv []byte) cipher.Stream { return cipher.NewCFBDecrypter(b, iv) }
|
||||
func (b *cfbStream) Encrypter(iv []byte) cipher.Stream { return cipher.NewCFBEncrypter(b, iv) }
|
||||
|
||||
// AESCFB returns an aescfb cipher.
|
||||
func AESCFB(key []byte) (Cipher, error) {
|
||||
blk, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
@@ -67,6 +70,7 @@ func (k chacha20ietfkey) Encrypter(iv []byte) cipher.Stream {
|
||||
return ciph
|
||||
}
|
||||
|
||||
// Chacha20IETF returns a Chacha20IETF cipher.
|
||||
func Chacha20IETF(key []byte) (Cipher, error) {
|
||||
if len(key) != chacha.KeySize {
|
||||
return nil, KeySizeError(chacha.KeySize)
|
||||
@@ -74,6 +78,7 @@ func Chacha20IETF(key []byte) (Cipher, error) {
|
||||
return chacha20ietfkey(key), nil
|
||||
}
|
||||
|
||||
// xchacha20
|
||||
type xchacha20key []byte
|
||||
|
||||
func (k xchacha20key) IVSize() int { return chacha.XNonceSize }
|
||||
@@ -86,6 +91,7 @@ func (k xchacha20key) Encrypter(iv []byte) cipher.Stream {
|
||||
return ciph
|
||||
}
|
||||
|
||||
// Xchacha20 returns a Xchacha20 cipher.
|
||||
func Xchacha20(key []byte) (Cipher, error) {
|
||||
if len(key) != chacha.KeySize {
|
||||
return nil, KeySizeError(chacha.KeySize)
|
||||
@@ -93,7 +99,7 @@ func Xchacha20(key []byte) (Cipher, error) {
|
||||
return xchacha20key(key), nil
|
||||
}
|
||||
|
||||
// reference: https://github.com/shadowsocks/shadowsocks-go/blob/master/shadowsocks/encrypt.go
|
||||
// chacah20
|
||||
type chacha20key []byte
|
||||
|
||||
func (k chacha20key) IVSize() int { return chacha.NonceSize }
|
||||
@@ -106,6 +112,7 @@ func (k chacha20key) Encrypter(iv []byte) cipher.Stream {
|
||||
return ciph
|
||||
}
|
||||
|
||||
// ChaCha20 returns a ChaCha20 cipher.
|
||||
func ChaCha20(key []byte) (Cipher, error) {
|
||||
if len(key) != chacha.KeySize {
|
||||
return nil, KeySizeError(chacha.KeySize)
|
||||
@@ -113,6 +120,7 @@ func ChaCha20(key []byte) (Cipher, error) {
|
||||
return chacha20key(key), nil
|
||||
}
|
||||
|
||||
// rc4md5
|
||||
type rc4Md5Key []byte
|
||||
|
||||
func (k rc4Md5Key) IVSize() int { return 16 }
|
||||
@@ -129,6 +137,7 @@ func (k rc4Md5Key) Encrypter(iv []byte) cipher.Stream {
|
||||
return ciph
|
||||
}
|
||||
|
||||
// RC4MD5 returns a RC4MD5 cipher.
|
||||
func RC4MD5(key []byte) (Cipher, error) {
|
||||
return rc4Md5Key(key), nil
|
||||
}
|
||||
Reference in new issue
Block a user