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

45 lines
934 B
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"
"v2ray.com/core/common"
2018-09-03 03:55:02 -04:00
"v2ray.com/core/common/compare"
2018-07-04 11:48:48 -04:00
. "v2ray.com/core/proxy/mtproto"
. "v2ray.com/ext/assert"
)
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)
2018-09-03 03:55:02 -04:00
if err := compare.BytesEqualWithDetail(bii, b); err != nil {
t.Fatal(err)
}
2018-07-04 11:48:48 -04:00
}
2018-07-05 08:47:46 -04:00
func TestAuthenticationReadWrite(t *testing.T) {
assert := With(t)
a := NewAuthentication()
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[:])
}