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

54 lines
1.1 KiB
Go
Raw Normal View History

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