Use errors from io

This commit is contained in:
Andy Wang 2020-04-08 14:59:09 +01:00
parent 01e5d15d20
commit 1de5045003
3 changed files with 4 additions and 3 deletions

View File

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

View File

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

View File

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