mirror of
https://github.com/cbeuw/Cloak.git
synced 2024-11-15 18:13:29 +00:00
Use errors from io
This commit is contained in:
parent
01e5d15d20
commit
1de5045003
@ -3,7 +3,6 @@
|
||||
package multiplex
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@ -43,7 +42,7 @@ func (d *datagramBuffer) Read(target []byte) (int, error) {
|
||||
}
|
||||
data := d.buf[0]
|
||||
if len(target) < len(data) {
|
||||
return 0, errors.New("buffer is too small")
|
||||
return 0, io.ErrShortBuffer
|
||||
}
|
||||
d.buf = d.buf[1:]
|
||||
copy(target, data)
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/cbeuw/Cloak/internal/util"
|
||||
"golang.org/x/crypto/chacha20poly1305"
|
||||
"golang.org/x/crypto/salsa20"
|
||||
"io"
|
||||
)
|
||||
|
||||
type Obfser func(*Frame, []byte) (int, error)
|
||||
@ -57,7 +58,7 @@ func MakeObfs(salsaKey [32]byte, payloadCipher cipher.AEAD, hasRecordLayer bool)
|
||||
// usefulLen is the amount of bytes that will be eventually sent off
|
||||
usefulLen := rlLen + HEADER_LEN + len(f.Payload) + int(extraLen)
|
||||
if len(buf) < usefulLen {
|
||||
return 0, errors.New("buffer is too small")
|
||||
return 0, io.ErrShortBuffer
|
||||
|
||||
}
|
||||
// we do as much in-place as possible to save allocation
|
||||
|
@ -3,6 +3,7 @@ package multiplex
|
||||
import "io"
|
||||
|
||||
type recvBuffer interface {
|
||||
// Read calls' err must be nil | io.EOF | io.ErrShortBuffer
|
||||
io.ReadCloser
|
||||
Write(Frame) (toBeClosed bool, err error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user