mirror of https://github.com/v2ray/v2ray-core
better error handling in AuthenticationReader
parent
919b749578
commit
5f2eb09226
|
@ -36,10 +36,16 @@ func NewAuthenticationReader(aead cipher.AEAD, reader io.Reader, ivGen BytesGene
|
|||
}
|
||||
|
||||
func (v *AuthenticationReader) NextChunk() error {
|
||||
if v.buffer.Len() < 2 {
|
||||
return errInsufficientBuffer
|
||||
}
|
||||
size := int(serial.BytesToUint16(v.buffer.BytesTo(2)))
|
||||
if size > v.buffer.Len()-2 {
|
||||
return errInsufficientBuffer
|
||||
}
|
||||
if size == v.aead.Overhead() {
|
||||
return io.EOF
|
||||
}
|
||||
cipherChunk := v.buffer.BytesRange(2, size+2)
|
||||
plainChunk, err := v.aead.Open(cipherChunk, v.ivGen(), cipherChunk, v.extraGen())
|
||||
if err != nil {
|
||||
|
@ -67,9 +73,11 @@ func (v *AuthenticationReader) Read(b []byte) (int, error) {
|
|||
|
||||
err := v.NextChunk()
|
||||
if err == errInsufficientBuffer {
|
||||
v.buffer.FillFrom(v.reader)
|
||||
} else if err != nil {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
_, err = v.buffer.FillFrom(v.reader)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
totalBytes := 0
|
||||
|
|
Loading…
Reference in New Issue