diff --git a/common/crypto/auth.go b/common/crypto/auth.go index 28a7c68c3..f6b966678 100644 --- a/common/crypto/auth.go +++ b/common/crypto/auth.go @@ -193,10 +193,6 @@ func (r *AuthenticationReader) ReadMultiBuffer() (buf.MultiBuffer, error) { return mb, nil } -const ( - WriteSize = 1024 -) - type AuthenticationWriter struct { auth Authenticator writer buf.Writer @@ -235,12 +231,13 @@ func (w *AuthenticationWriter) seal(b *buf.Buffer) (*buf.Buffer, error) { func (w *AuthenticationWriter) writeStream(mb buf.MultiBuffer) error { defer mb.Release() + payloadSize := buf.Size - w.auth.Overhead() - w.sizeParser.SizeBytes() mb2Write := buf.NewMultiBufferCap(len(mb) + 10) for { b := buf.New() common.Must(b.Reset(func(bb []byte) (int, error) { - return mb.Read(bb[:WriteSize]) + return mb.Read(bb[:payloadSize]) })) eb, err := w.seal(b) b.Release() diff --git a/common/crypto/auth_test.go b/common/crypto/auth_test.go index 4016dc51b..58d256e42 100644 --- a/common/crypto/auth_test.go +++ b/common/crypto/auth_test.go @@ -43,7 +43,7 @@ func TestAuthenticationReaderWriter(t *testing.T) { }, PlainChunkSizeParser{}, cache, protocol.TransferTypeStream) assert(writer.WriteMultiBuffer(buf.NewMultiBufferValue(payload)), IsNil) - assert(cache.Len(), Equals, 83360) + assert(cache.Len(), Equals, 82658) assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil) assert(err, IsNil)