Documentation ¶
Index ¶
- Constants
- Variables
- func DecryptOnce(cipher *Cipher, salt []byte, plainText, cipherText []byte) ([]byte, error)
- func MakeTestPayload(size int) []byte
- func MakeTestSecrets(n int) []string
- func Pack(dst, plaintext []byte, cipher *Cipher) ([]byte, error)
- func SupportedCipherNames() []string
- func Unpack(dst, pkt []byte, cipher *Cipher) ([]byte, error)
- type ChunkReader
- type Cipher
- type Reader
- type SaltGenerator
- type Writer
Constants ¶
const TestCipher = "chacha20-ietf-poly1305"
TestCipher is a preferred cipher to use in testing.
Variables ¶
var ErrShortPacket = errors.New("short packet")
ErrShortPacket is identical to shadowaead.ErrShortPacket
Functions ¶
func DecryptOnce ¶
DecryptOnce will decrypt the cipherText using the cipher and salt, appending the output to plainText.
func MakeTestPayload ¶
MakeTestPayload returns a slice of `size` arbitrary bytes.
func MakeTestSecrets ¶
MakeTestSecrets returns a slice of `n` test passwords. Not secure!
func Pack ¶
Pack encrypts a Shadowsocks-UDP packet and returns a slice containing the encrypted packet. dst must be big enough to hold the encrypted packet. If plaintext and dst overlap but are not aligned for in-place encryption, this function will panic.
func SupportedCipherNames ¶
func SupportedCipherNames() []string
SupportedCipherNames lists the names of the AEAD ciphers that are supported.
func Unpack ¶
Unpack decrypts a Shadowsocks-UDP packet and returns a slice containing the decrypted payload or an error. If dst is present, it is used to store the plaintext, and must have enough capacity. If dst is nil, decryption proceeds in-place. This function is needed because shadowaead.Unpack() embeds its own replay detection, which we do not always want, especially on memory-constrained clients.
Types ¶
type ChunkReader ¶
type ChunkReader interface { // ReadChunk reads the next chunk and returns its payload. The caller must // complete its use of the returned buffer before the next call. // The buffer is nil iff there is an error. io.EOF indicates a close. ReadChunk() ([]byte, error) }
ChunkReader is similar to io.Reader, except that it controls its own buffer granularity.
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher encapsulates a Shadowsocks AEAD spec and a secret
type Reader ¶
Reader is an io.Reader that also implements io.WriterTo to allow for piping the data without extra allocations and copies.
type SaltGenerator ¶
SaltGenerator generates unique salts to use in Shadowsocks connections.
var RandomSaltGenerator SaltGenerator = randomSaltGenerator{}
RandomSaltGenerator is a basic SaltGenerator.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is an io.Writer that also implements io.ReaderFrom to allow for piping the data without extra allocations and copies. The LazyWrite and Flush methods allow a header to be added but delayed until the first write, for concatenation. All methods except Flush must be called from a single thread.
func NewShadowsocksWriter ¶
NewShadowsocksWriter creates a Writer that encrypts the given Writer using the shadowsocks protocol with the given shadowsocks cipher.
func (*Writer) LazyWrite ¶
LazyWrite queues p to be written, but doesn't send it until Flush() is called, a non-lazy write is made, or the buffer is filled.
func (*Writer) SetSaltGenerator ¶
func (sw *Writer) SetSaltGenerator(saltGenerator SaltGenerator)
SetSaltGenerator sets the salt generator to be used. Must be called before the first write.