chore: add comments to export functions

This commit is contained in:
nadoo committed 2020-11-06 22:47:33 +08:00
1 parent 417ac556f7
commit 8a2e95b17e
9 files changed
+33 -12

No files matched your search

+1
View File
@@ -73,6 +73,7 @@ func Relay(left, right net.Conn) error {
return nil
}
// Close closes the Conn.
func (c *Conn) Close() error {
pool.PutBufReader(c.r)
return c.Conn.Close()
+3
View File
@@ -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
}
+2 -2
View File
@@ -1,6 +1,6 @@
package obfs
import (
import (
"math/rand"
"github.com/nadoo/glider/proxy/ssr/internal/ssr"
@@ -80,4 +80,4 @@ func (r *randomHead) Decode(data []byte) (decodedData []byte, needSendBack bool,
func (r *randomHead) GetOverhead() int {
return 0
}
}
+2 -2
View File
@@ -218,8 +218,8 @@ func (t *tls12TicketAuth) Encode(data []byte) (encodedData []byte, err error) {
pdata -= 2
l += 2
encodedData[pdata-1] = 0x16 // tls handshake
pdata -= 1
l += 1
// pdata -= 1
// l += 1
t.sendSaver = packData(t.sendSaver, data)
t.handshakeStatus = 1