1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

optimize padding reading

This commit is contained in:
Darien Raymond 2018-07-30 20:08:50 +02:00
parent f37e2ace9c
commit d615adab36
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -210,7 +210,7 @@ func NewAuthenticationWriter(auth Authenticator, sizeParser ChunkSizeEncoder, wr
func (w *AuthenticationWriter) seal(b *buf.Buffer) (*buf.Buffer, error) {
encryptedSize := int(b.Len()) + w.auth.Overhead()
paddingSize := 0
var paddingSize int
if w.padding != nil {
paddingSize = int(w.padding.NextPaddingLen())
}
@ -228,13 +228,7 @@ func (w *AuthenticationWriter) seal(b *buf.Buffer) (*buf.Buffer, error) {
return nil, err
}
if paddingSize > 0 {
if err := eb.AppendSupplier(func(bb []byte) (int, error) {
common.Must2(rand.Read(bb[:paddingSize]))
return paddingSize, nil
}); err != nil {
eb.Release()
return nil, err
}
common.Must(eb.AppendSupplier(buf.ReadFullFrom(rand.Reader, int32(paddingSize))))
}
return eb, nil