Browse Source

migrate int to int32

pull/984/merge
Darien Raymond 7 years ago
parent
commit
7bafd7a1ab
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 4
      common/crypto/auth.go
  2. 12
      common/crypto/chunk.go
  3. 2
      proxy/vmess/encoding/auth.go

4
common/crypto/auth.go

@ -205,7 +205,7 @@ func (w *AuthenticationWriter) seal(b *buf.Buffer) (*buf.Buffer, error) {
eb := buf.New()
common.Must(eb.Reset(func(bb []byte) (int, error) {
w.sizeParser.Encode(uint16(encryptedSize), bb[:0])
return w.sizeParser.SizeBytes(), nil
return int(w.sizeParser.SizeBytes()), nil
}))
if err := eb.AppendSupplier(func(bb []byte) (int, error) {
_, err := w.auth.Seal(bb[:0], b.Bytes())
@ -221,7 +221,7 @@ 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()
payloadSize := buf.Size - int32(w.auth.Overhead()) - w.sizeParser.SizeBytes()
mb2Write := buf.NewMultiBufferCap(int32(len(mb) + 10))
for {

12
common/crypto/chunk.go

@ -10,19 +10,19 @@ import (
// ChunkSizeDecoder is a utility class to decode size value from bytes.
type ChunkSizeDecoder interface {
SizeBytes() int
SizeBytes() int32
Decode([]byte) (uint16, error)
}
// ChunkSizeEncoder is a utility class to encode size value into bytes.
type ChunkSizeEncoder interface {
SizeBytes() int
SizeBytes() int32
Encode(uint16, []byte) []byte
}
type PlainChunkSizeParser struct{}
func (PlainChunkSizeParser) SizeBytes() int {
func (PlainChunkSizeParser) SizeBytes() int32 {
return 2
}
@ -38,8 +38,8 @@ type AEADChunkSizeParser struct {
Auth *AEADAuthenticator
}
func (p *AEADChunkSizeParser) SizeBytes() int {
return 2 + p.Auth.Overhead()
func (p *AEADChunkSizeParser) SizeBytes() int32 {
return 2 + int32(p.Auth.Overhead())
}
func (p *AEADChunkSizeParser) Encode(size uint16, b []byte) []byte {
@ -125,7 +125,7 @@ func (w *ChunkStreamWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
b := buf.New()
common.Must(b.Reset(func(buffer []byte) (int, error) {
w.sizeEncoder.Encode(uint16(slice.Len()), buffer[:0])
return w.sizeEncoder.SizeBytes(), nil
return int(w.sizeEncoder.SizeBytes()), nil
}))
mb2Write.Append(b)
mb2Write.AppendMulti(slice)

2
proxy/vmess/encoding/auth.go

@ -88,7 +88,7 @@ func NewShakeSizeParser(nonce []byte) *ShakeSizeParser {
}
}
func (*ShakeSizeParser) SizeBytes() int {
func (*ShakeSizeParser) SizeBytes() int32 {
return 2
}

Loading…
Cancel
Save