mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-02 16:21:05 +00:00
migrate to std lib
This commit is contained in:
18 files changed
+72
-180
No files matched your search
@@ -4,12 +4,14 @@ import (
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/bytespool"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common/vio"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -48,11 +50,11 @@ func HeaderKeyGenerator(key []byte, iv []byte) func() []byte {
|
||||
}
|
||||
|
||||
func ChunkKeyGenerator(iv []byte) func() []byte {
|
||||
chunkID := 0
|
||||
chunkID := uint32(0)
|
||||
return func() []byte {
|
||||
newKey := make([]byte, 0, len(iv)+4)
|
||||
newKey = append(newKey, iv...)
|
||||
newKey = serial.IntToBytes(chunkID, newKey)
|
||||
newKey := make([]byte, len(iv)+4)
|
||||
copy(newKey, iv)
|
||||
binary.BigEndian.PutUint32(newKey[len(iv):], newKey)
|
||||
chunkID++
|
||||
return newKey
|
||||
}
|
||||
@@ -71,7 +73,7 @@ func NewChunkReader(reader io.Reader, auth *Authenticator) *ChunkReader {
|
||||
}
|
||||
|
||||
func (v *ChunkReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||
size, err := serial.ReadUint16(v.reader)
|
||||
size, err := vio.ReadUint16(v.reader)
|
||||
if err != nil {
|
||||
return nil, newError("failed to read size")
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package encoding
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"hash/fnv"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
@@ -59,7 +60,7 @@ func (*FnvAuthenticator) Seal(dst, nonce, plaintext, additionalData []byte) []by
|
||||
|
||||
// Open implements AEAD.Open().
|
||||
func (*FnvAuthenticator) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
|
||||
if serial.BytesToUint32(ciphertext[:4]) != Authenticate(ciphertext[4:]) {
|
||||
if binary.BigEndian.Uint32(ciphertext[:4]) != Authenticate(ciphertext[4:]) {
|
||||
return dst, newError("invalid authentication")
|
||||
}
|
||||
return append(dst, ciphertext[4:]...), nil
|
||||
@@ -94,12 +95,12 @@ func (*ShakeSizeParser) SizeBytes() int32 {
|
||||
|
||||
func (s *ShakeSizeParser) next() uint16 {
|
||||
common.Must2(s.shake.Read(s.buffer[:]))
|
||||
return serial.BytesToUint16(s.buffer[:])
|
||||
return binary.BigEndian.Uint16(s.buffer[:])
|
||||
}
|
||||
|
||||
func (s *ShakeSizeParser) Decode(b []byte) (uint16, error) {
|
||||
mask := s.next()
|
||||
size := serial.BytesToUint16(b)
|
||||
size := binary.BigEndian.Uint16(b)
|
||||
return mask ^ size, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package encoding
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
@@ -57,7 +58,7 @@ func UnmarshalCommand(cmdID byte, data []byte) (protocol.ResponseCommand, error)
|
||||
return nil, newError("insufficient length")
|
||||
}
|
||||
expectedAuth := Authenticate(data[4:])
|
||||
actualAuth := serial.BytesToUint32(data[:4])
|
||||
actualAuth := binary.BigEndian.Uint32(data[:4])
|
||||
if expectedAuth != actualAuth {
|
||||
return nil, newError("invalid auth")
|
||||
}
|
||||
@@ -134,7 +135,7 @@ func (f *CommandSwitchAccountFactory) Unmarshal(data []byte) (interface{}, error
|
||||
if len(data) < alterIDStart+2 {
|
||||
return nil, newError("insufficient length.")
|
||||
}
|
||||
cmd.AlterIds = serial.BytesToUint16(data[alterIDStart : alterIDStart+2])
|
||||
cmd.AlterIds = binary.BigEndian.Uint16(data[alterIDStart : alterIDStart+2])
|
||||
levelStart := alterIDStart + 2
|
||||
if len(data) < levelStart+1 {
|
||||
return nil, newError("insufficient length.")
|
||||
|
||||
@@ -2,6 +2,7 @@ package encoding
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
"sync"
|
||||
@@ -15,7 +16,6 @@ import (
|
||||
"v2ray.com/core/common/crypto"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common/task"
|
||||
"v2ray.com/core/proxy/vmess"
|
||||
)
|
||||
@@ -191,7 +191,7 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
|
||||
fnv1a := fnv.New32a()
|
||||
common.Must2(fnv1a.Write(buffer.BytesTo(-4)))
|
||||
actualHash := fnv1a.Sum32()
|
||||
expectedHash := serial.BytesToUint32(buffer.BytesFrom(-4))
|
||||
expectedHash := binary.BigEndian.Uint32(buffer.BytesFrom(-4))
|
||||
|
||||
if actualHash != expectedHash {
|
||||
return nil, newError("invalid auth")
|
||||
|
||||
Reference in new issue
Block a user