config_test.go 897 B

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