mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
refactor
This commit is contained in:
parent
7f1e9c85c9
commit
693702350d
@ -3,15 +3,15 @@ package crypto
|
|||||||
import (
|
import (
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
|
|
||||||
|
"v2ray.com/core/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewAesDecryptionStream creates a new AES encryption stream based on given key and IV.
|
// NewAesDecryptionStream creates a new AES encryption stream based on given key and IV.
|
||||||
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
|
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
|
||||||
func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
|
func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
|
||||||
aesBlock, err := aes.NewCipher(key)
|
aesBlock, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
common.Must(err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return cipher.NewCFBDecrypter(aesBlock, iv)
|
return cipher.NewCFBDecrypter(aesBlock, iv)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,8 +19,6 @@ func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
|
|||||||
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
|
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
|
||||||
func NewAesEncryptionStream(key []byte, iv []byte) cipher.Stream {
|
func NewAesEncryptionStream(key []byte, iv []byte) cipher.Stream {
|
||||||
aesBlock, err := aes.NewCipher(key)
|
aesBlock, err := aes.NewCipher(key)
|
||||||
if err != nil {
|
common.Must(err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return cipher.NewCFBEncrypter(aesBlock, iv)
|
return cipher.NewCFBEncrypter(aesBlock, iv)
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,14 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"v2ray.com/core/common"
|
||||||
. "v2ray.com/core/common/crypto"
|
. "v2ray.com/core/common/crypto"
|
||||||
"v2ray.com/core/testing/assert"
|
"v2ray.com/core/testing/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustDecodeHex(s string) []byte {
|
func mustDecodeHex(s string) []byte {
|
||||||
b, err := hex.DecodeString(s)
|
b, err := hex.DecodeString(s)
|
||||||
if err != nil {
|
common.Must(err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,15 +4,14 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"v2ray.com/core/common"
|
||||||
. "v2ray.com/core/common/net"
|
. "v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/testing/assert"
|
"v2ray.com/core/testing/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseCIDR(str string) *net.IPNet {
|
func parseCIDR(str string) *net.IPNet {
|
||||||
_, ipNet, err := net.ParseCIDR(str)
|
_, ipNet, err := net.ParseCIDR(str)
|
||||||
if err != nil {
|
common.Must(err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return ipNet
|
return ipNet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,17 +81,14 @@ var (
|
|||||||
func genTestBinaryPath() {
|
func genTestBinaryPath() {
|
||||||
testBinaryPathGen.Do(func() {
|
testBinaryPathGen.Do(func() {
|
||||||
var tempDir string
|
var tempDir string
|
||||||
err := retry.Timed(5, 100).On(func() error {
|
common.Must(retry.Timed(5, 100).On(func() error {
|
||||||
dir, err := ioutil.TempDir("", "v2ray")
|
dir, err := ioutil.TempDir("", "v2ray")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tempDir = dir
|
tempDir = dir
|
||||||
return nil
|
return nil
|
||||||
})
|
}))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
file := filepath.Join(tempDir, "v2ray.test")
|
file := filepath.Join(tempDir, "v2ray.test")
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
file += ".exe"
|
file += ".exe"
|
||||||
|
@ -11,6 +11,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"v2ray.com/core/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var protocMap = map[string]string{
|
var protocMap = map[string]string{
|
||||||
@ -64,7 +66,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := filepath.Walk(reporoot, func(path string, info os.FileInfo, err error) error {
|
common.Must(filepath.Walk(reporoot, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return err
|
return err
|
||||||
@ -90,8 +92,5 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
}))
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"v2ray.com/core/app/router"
|
"v2ray.com/core/app/router"
|
||||||
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/errors"
|
"v2ray.com/core/common/errors"
|
||||||
"v2ray.com/core/tools/geoip"
|
"v2ray.com/core/tools/geoip"
|
||||||
|
|
||||||
@ -26,9 +27,7 @@ const (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
resp, err := http.Get(apnicFile)
|
resp, err := http.Get(apnicFile)
|
||||||
if err != nil {
|
common.Must(err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
panic(errors.New("unexpected status ", resp.StatusCode))
|
panic(errors.New("unexpected status ", resp.StatusCode))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user