Draft: Encrypted Protocol Extension

This commit is contained in:
世界 2022-06-15 16:19:52 +08:00
parent cd8ec2833c
commit e3a6eb8580
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
8 changed files with 341 additions and 53 deletions

View file

@ -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