auth_test.go 934 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package mtproto_test
  2. import (
  3. "bytes"
  4. "crypto/rand"
  5. "testing"
  6. "v2ray.com/core/common"
  7. "v2ray.com/core/common/compare"
  8. . "v2ray.com/core/proxy/mtproto"
  9. . "v2ray.com/ext/assert"
  10. )
  11. func TestInverse(t *testing.T) {
  12. const size = 64
  13. b := make([]byte, 64)
  14. for b[0] == b[size-1] {
  15. common.Must2(rand.Read(b))
  16. }
  17. bi := Inverse(b)
  18. if b[0] == bi[0] {
  19. t.Fatal("seems bytes are not inversed: ", b[0], "vs", bi[0])
  20. }
  21. bii := Inverse(bi)
  22. if err := compare.BytesEqualWithDetail(bii, b); err != nil {
  23. t.Fatal(err)
  24. }
  25. }
  26. func TestAuthenticationReadWrite(t *testing.T) {
  27. assert := With(t)
  28. a := NewAuthentication()
  29. b := bytes.NewReader(a.Header[:])
  30. a2, err := ReadAuthentication(b)
  31. assert(err, IsNil)
  32. assert(a.EncodingKey[:], Equals, a2.DecodingKey[:])
  33. assert(a.EncodingNonce[:], Equals, a2.DecodingNonce[:])
  34. assert(a.DecodingKey[:], Equals, a2.EncodingKey[:])
  35. assert(a.DecodingNonce[:], Equals, a2.EncodingNonce[:])
  36. }