v2ray-core/proxy/mtproto/auth_test.go

45 lines
957 B
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"
"v2ray.com/core/common"
2018-09-03 07:55:02 +00:00
"v2ray.com/core/common/compare"
2018-07-04 15:48:48 +00:00
. "v2ray.com/core/proxy/mtproto"
. "v2ray.com/ext/assert"
)
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)
2018-09-03 07:55:02 +00:00
if err := compare.BytesEqualWithDetail(bii, b); err != nil {
t.Fatal(err)
}
2018-07-04 15:48:48 +00:00
}
2018-07-05 12:47:46 +00:00
func TestAuthenticationReadWrite(t *testing.T) {
assert := With(t)
a := NewAuthentication(DefaultSessionContext())
2018-07-05 12:47:46 +00:00
b := bytes.NewReader(a.Header[:])
a2, err := ReadAuthentication(b)
assert(err, IsNil)
assert(a.EncodingKey[:], Equals, a2.DecodingKey[:])
assert(a.EncodingNonce[:], Equals, a2.DecodingNonce[:])
assert(a.DecodingKey[:], Equals, a2.EncodingKey[:])
assert(a.DecodingNonce[:], Equals, a2.EncodingNonce[:])
}