github.com/EagleQL/Xray-core@v1.4.3/proxy/shadowsocks/config_test.go (about) 1 package shadowsocks_test 2 3 import ( 4 "crypto/rand" 5 "testing" 6 7 "github.com/google/go-cmp/cmp" 8 9 "github.com/xtls/xray-core/common" 10 "github.com/xtls/xray-core/common/buf" 11 "github.com/xtls/xray-core/proxy/shadowsocks" 12 ) 13 14 func TestAEADCipherUDP(t *testing.T) { 15 rawAccount := &shadowsocks.Account{ 16 CipherType: shadowsocks.CipherType_AES_128_GCM, 17 Password: "test", 18 } 19 account, err := rawAccount.AsAccount() 20 common.Must(err) 21 22 cipher := account.(*shadowsocks.MemoryAccount).Cipher 23 24 key := make([]byte, cipher.KeySize()) 25 common.Must2(rand.Read(key)) 26 27 payload := make([]byte, 1024) 28 common.Must2(rand.Read(payload)) 29 30 b1 := buf.New() 31 common.Must2(b1.ReadFullFrom(rand.Reader, cipher.IVSize())) 32 common.Must2(b1.Write(payload)) 33 common.Must(cipher.EncodePacket(key, b1)) 34 35 common.Must(cipher.DecodePacket(key, b1)) 36 if diff := cmp.Diff(b1.Bytes(), payload); diff != "" { 37 t.Error(diff) 38 } 39 }