github.com/v2fly/v2ray-core/v4@v4.45.2/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 10 "github.com/v2fly/v2ray-core/v4/common" 11 . "github.com/v2fly/v2ray-core/v4/proxy/mtproto" 12 ) 13 14 func TestInverse(t *testing.T) { 15 const size = 64 16 b := make([]byte, 64) 17 for b[0] == b[size-1] { 18 common.Must2(rand.Read(b)) 19 } 20 21 bi := Inverse(b) 22 if b[0] == bi[0] { 23 t.Fatal("seems bytes are not inversed: ", b[0], "vs", bi[0]) 24 } 25 26 bii := Inverse(bi) 27 if r := cmp.Diff(bii, b); r != "" { 28 t.Fatal(r) 29 } 30 } 31 32 func TestAuthenticationReadWrite(t *testing.T) { 33 a := NewAuthentication(DefaultSessionContext()) 34 b := bytes.NewReader(a.Header[:]) 35 a2, err := ReadAuthentication(b) 36 common.Must(err) 37 38 if r := cmp.Diff(a.EncodingKey[:], a2.DecodingKey[:]); r != "" { 39 t.Error("decoding key: ", r) 40 } 41 42 if r := cmp.Diff(a.EncodingNonce[:], a2.DecodingNonce[:]); r != "" { 43 t.Error("decoding nonce: ", r) 44 } 45 46 if r := cmp.Diff(a.DecodingKey[:], a2.EncodingKey[:]); r != "" { 47 t.Error("encoding key: ", r) 48 } 49 50 if r := cmp.Diff(a.DecodingNonce[:], a2.EncodingNonce[:]); r != "" { 51 t.Error("encoding nonce: ", r) 52 } 53 }