1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-30 11:05:24 +00:00
v2fly/proxy/mtproto/auth_test.go

54 lines
1.1 KiB
Go
Raw Normal View History

2018-07-04 15:48:48 +00:00
package mtproto_test
import (
2018-07-05 12:47:46 +00:00
"bytes"
2018-07-04 15:48:48 +00:00
"crypto/rand"
"testing"
2019-01-06 23:12:04 +00:00
"github.com/google/go-cmp/cmp"
2021-02-16 20:31:50 +00:00
"github.com/v2fly/v2ray-core/v4/common"
. "github.com/v2fly/v2ray-core/v4/proxy/mtproto"
2018-07-04 15:48:48 +00:00
)
func TestInverse(t *testing.T) {
2018-09-03 07:55:02 +00:00
const size = 64
2018-07-04 15:48:48 +00:00
b := make([]byte, 64)
2018-09-03 07:55:02 +00:00
for b[0] == b[size-1] {
common.Must2(rand.Read(b))
}
2018-07-04 15:48:48 +00:00
bi := Inverse(b)
2018-09-03 07:55:02 +00:00
if b[0] == bi[0] {
t.Fatal("seems bytes are not inversed: ", b[0], "vs", bi[0])
}
2018-07-04 15:48:48 +00:00
bii := Inverse(bi)
2019-01-06 23:12:04 +00:00
if r := cmp.Diff(bii, b); r != "" {
t.Fatal(r)
2018-09-03 07:55:02 +00:00
}
2018-07-04 15:48:48 +00:00
}
2018-07-05 12:47:46 +00:00
func TestAuthenticationReadWrite(t *testing.T) {
a := NewAuthentication(DefaultSessionContext())
2018-07-05 12:47:46 +00:00
b := bytes.NewReader(a.Header[:])
a2, err := ReadAuthentication(b)
2019-02-02 21:19:30 +00:00
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)
}
2018-07-05 12:47:46 +00:00
2019-02-02 21:19:30 +00:00
if r := cmp.Diff(a.DecodingNonce[:], a2.EncodingNonce[:]); r != "" {
t.Error("encoding nonce: ", r)
}
2018-07-05 12:47:46 +00:00
}