mirror of https://github.com/XTLS/Xray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
package mtproto_test |
|
|
|
import ( |
|
"bytes" |
|
"crypto/rand" |
|
"testing" |
|
|
|
"github.com/google/go-cmp/cmp" |
|
"github.com/xtls/xray-core/common" |
|
. "github.com/xtls/xray-core/proxy/mtproto" |
|
) |
|
|
|
func TestInverse(t *testing.T) { |
|
const size = 64 |
|
b := make([]byte, 64) |
|
for b[0] == b[size-1] { |
|
common.Must2(rand.Read(b)) |
|
} |
|
|
|
bi := Inverse(b) |
|
if b[0] == bi[0] { |
|
t.Fatal("seems bytes are not inversed: ", b[0], "vs", bi[0]) |
|
} |
|
|
|
bii := Inverse(bi) |
|
if r := cmp.Diff(bii, b); r != "" { |
|
t.Fatal(r) |
|
} |
|
} |
|
|
|
func TestAuthenticationReadWrite(t *testing.T) { |
|
a := NewAuthentication(DefaultSessionContext()) |
|
b := bytes.NewReader(a.Header[:]) |
|
a2, err := ReadAuthentication(b) |
|
common.Must(err) |
|
|
|
if r := cmp.Diff(a.EncodingKey[:], a2.DecodingKey[:]); r != "" { |
|
t.Error("decoding key: ", r) |
|
} |
|
|
|
if r := cmp.Diff(a.EncodingNonce[:], a2.DecodingNonce[:]); r != "" { |
|
t.Error("decoding nonce: ", r) |
|
} |
|
|
|
if r := cmp.Diff(a.DecodingKey[:], a2.EncodingKey[:]); r != "" { |
|
t.Error("encoding key: ", r) |
|
} |
|
|
|
if r := cmp.Diff(a.DecodingNonce[:], a2.EncodingNonce[:]); r != "" { |
|
t.Error("encoding nonce: ", r) |
|
} |
|
}
|
|
|