1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-26 13:56:12 -04:00
This commit is contained in:
Darien Raymond 2017-02-14 22:45:36 +01:00
parent 16d803ba1d
commit 7199ffcaa2
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -118,7 +118,7 @@ func NewAuthenticationReader(auth Authenticator, reader io.Reader, sizeMask Uint
} }
} }
func (v *AuthenticationReader) NextChunk(mask uint16) error { func (v *AuthenticationReader) nextChunk(mask uint16) error {
if v.buffer.Len() < 2 { if v.buffer.Len() < 2 {
return errInsufficientBuffer return errInsufficientBuffer
} }
@ -133,7 +133,7 @@ func (v *AuthenticationReader) NextChunk(mask uint16) error {
return io.EOF return io.EOF
} }
if size < v.auth.Overhead() { if size < v.auth.Overhead() {
return errors.New("AuthenticationReader: invalid packet size:", size) return errors.New("Crypto:AuthenticationReader: invalid packet size:", size)
} }
cipherChunk := v.buffer.BytesRange(2, size+2) cipherChunk := v.buffer.BytesRange(2, size+2)
plainChunk, err := v.auth.Open(cipherChunk[:0], cipherChunk) plainChunk, err := v.auth.Open(cipherChunk[:0], cipherChunk)
@ -145,7 +145,7 @@ func (v *AuthenticationReader) NextChunk(mask uint16) error {
return nil return nil
} }
func (v *AuthenticationReader) CopyChunk(b []byte) int { func (v *AuthenticationReader) copyChunk(b []byte) int {
if len(v.chunk) == 0 { if len(v.chunk) == 0 {
return 0 return 0
} }
@ -158,7 +158,7 @@ func (v *AuthenticationReader) CopyChunk(b []byte) int {
return nBytes return nBytes
} }
func (v *AuthenticationReader) EnsureChunk() error { func (v *AuthenticationReader) ensureChunk() error {
atHead := false atHead := false
if v.buffer.IsEmpty() { if v.buffer.IsEmpty() {
v.buffer.Clear() v.buffer.Clear()
@ -167,7 +167,7 @@ func (v *AuthenticationReader) EnsureChunk() error {
mask := v.sizeMask.Next() mask := v.sizeMask.Next()
for { for {
err := v.NextChunk(mask) err := v.nextChunk(mask)
if err != errInsufficientBuffer { if err != errInsufficientBuffer {
return err return err
} }
@ -187,16 +187,16 @@ func (v *AuthenticationReader) EnsureChunk() error {
func (v *AuthenticationReader) Read(b []byte) (int, error) { func (v *AuthenticationReader) Read(b []byte) (int, error) {
if len(v.chunk) > 0 { if len(v.chunk) > 0 {
nBytes := v.CopyChunk(b) nBytes := v.copyChunk(b)
return nBytes, nil return nBytes, nil
} }
err := v.EnsureChunk() err := v.ensureChunk()
if err != nil { if err != nil {
return 0, err return 0, err
} }
return v.CopyChunk(b), nil return v.copyChunk(b), nil
} }
type AuthenticationWriter struct { type AuthenticationWriter struct {