github.com/xraypb/xray-core@v1.6.6/proxy/mtproto/auth_test.go (about) 1 package mtproto_test 2 3 import ( 4 "bytes" 5 "crypto/rand" 6 "testing" 7 8 "github.com/google/go-cmp/cmp" 9 "github.com/xraypb/xray-core/common" 10 . "github.com/xraypb/xray-core/proxy/mtproto" 11 ) 12 13 func TestInverse(t *testing.T) { 14 const size = 64 15 b := make([]byte, 64) 16 for b[0] == b[size-1] { 17 common.Must2(rand.Read(b)) 18 } 19 20 bi := Inverse(b) 21 if b[0] == bi[0] { 22 t.Fatal("seems bytes are not inversed: ", b[0], "vs", bi[0]) 23 } 24 25 bii := Inverse(bi) 26 if r := cmp.Diff(bii, b); r != "" { 27 t.Fatal(r) 28 } 29 } 30 31 func TestAuthenticationReadWrite(t *testing.T) { 32 a := NewAuthentication(DefaultSessionContext()) 33 b := bytes.NewReader(a.Header[:]) 34 a2, err := ReadAuthentication(b) 35 common.Must(err) 36 37 if r := cmp.Diff(a.EncodingKey[:], a2.DecodingKey[:]); r != "" { 38 t.Error("decoding key: ", r) 39 } 40 41 if r := cmp.Diff(a.EncodingNonce[:], a2.DecodingNonce[:]); r != "" { 42 t.Error("decoding nonce: ", r) 43 } 44 45 if r := cmp.Diff(a.DecodingKey[:], a2.EncodingKey[:]); r != "" { 46 t.Error("encoding key: ", r) 47 } 48 49 if r := cmp.Diff(a.DecodingNonce[:], a2.EncodingNonce[:]); r != "" { 50 t.Error("encoding nonce: ", r) 51 } 52 }