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:
parent
f37e2ace9c
commit
d615adab36
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user