1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -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) { func (w *AuthenticationWriter) seal(b *buf.Buffer) (*buf.Buffer, error) {
encryptedSize := int(b.Len()) + w.auth.Overhead() encryptedSize := int(b.Len()) + w.auth.Overhead()
paddingSize := 0 var paddingSize int
if w.padding != nil { if w.padding != nil {
paddingSize = int(w.padding.NextPaddingLen()) paddingSize = int(w.padding.NextPaddingLen())
} }
@ -228,13 +228,7 @@ func (w *AuthenticationWriter) seal(b *buf.Buffer) (*buf.Buffer, error) {
return nil, err return nil, err
} }
if paddingSize > 0 { if paddingSize > 0 {
if err := eb.AppendSupplier(func(bb []byte) (int, error) { common.Must(eb.AppendSupplier(buf.ReadFullFrom(rand.Reader, int32(paddingSize))))
common.Must2(rand.Read(bb[:paddingSize]))
return paddingSize, nil
}); err != nil {
eb.Release()
return nil, err
}
} }
return eb, nil return eb, nil