mirror of
https://github.com/SagerNet/sing-shadowsocks.git
synced 2025-04-03 20:07:40 +03:00
Draft: Encrypted Protocol Extension
This commit is contained in:
parent
cd8ec2833c
commit
e3a6eb8580
8 changed files with 341 additions and 53 deletions
|
@ -197,6 +197,12 @@ func (r *Reader) Discard(n int) error {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Reader) Buffer() *buf.Buffer {
|
||||
buffer := buf.With(r.buffer)
|
||||
buffer.Resize(r.index, r.cached)
|
||||
return buffer
|
||||
}
|
||||
|
||||
func (r *Reader) Cached() int {
|
||||
return r.cached
|
||||
}
|
||||
|
@ -243,7 +249,7 @@ func (r *Reader) ReadWithLength(length uint16) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *Reader) ReadChunk(chunk []byte) error {
|
||||
func (r *Reader) ReadExternalChunk(chunk []byte) error {
|
||||
bb, err := r.cipher.Open(r.buffer[:0], r.nonce, chunk, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -254,6 +260,16 @@ func (r *Reader) ReadChunk(chunk []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *Reader) ReadChunk(buffer *buf.Buffer, chunk []byte) error {
|
||||
bb, err := r.cipher.Open(buffer.Index(buffer.Len()), r.nonce, chunk, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
increaseNonce(r.nonce)
|
||||
buffer.Extend(len(bb))
|
||||
return nil
|
||||
}
|
||||
|
||||
type Writer struct {
|
||||
upstream io.Writer
|
||||
cipher cipher.AEAD
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue