2016-06-17 10:51:41 -04:00
|
|
|
package kcp_test
|
|
|
|
|
|
|
|
import (
|
2016-06-17 20:13:35 -04:00
|
|
|
"crypto/rand"
|
2016-06-17 10:51:41 -04:00
|
|
|
"testing"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/common/alloc"
|
|
|
|
"v2ray.com/core/testing/assert"
|
|
|
|
. "v2ray.com/core/transport/internet/kcp"
|
2016-06-17 10:51:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSimpleAuthenticator(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
2016-07-28 10:24:15 -04:00
|
|
|
buffer := alloc.NewLocalBuffer(512).Clear()
|
2016-06-17 10:51:41 -04:00
|
|
|
buffer.AppendBytes('a', 'b', 'c', 'd', 'e', 'f', 'g')
|
|
|
|
|
|
|
|
auth := NewSimpleAuthenticator()
|
|
|
|
auth.Seal(buffer)
|
|
|
|
|
|
|
|
assert.Bool(auth.Open(buffer)).IsTrue()
|
2016-12-05 15:33:24 -05:00
|
|
|
assert.Bytes(buffer.Bytes()).Equals([]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'})
|
2016-06-17 20:13:35 -04:00
|
|
|
}
|
|
|
|
|
2016-06-18 04:58:21 -04:00
|
|
|
func TestSimpleAuthenticator2(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
2016-07-28 10:24:15 -04:00
|
|
|
buffer := alloc.NewLocalBuffer(512).Clear()
|
2016-06-18 04:58:21 -04:00
|
|
|
buffer.AppendBytes('1', '2')
|
|
|
|
|
|
|
|
auth := NewSimpleAuthenticator()
|
|
|
|
auth.Seal(buffer)
|
|
|
|
|
|
|
|
assert.Bool(auth.Open(buffer)).IsTrue()
|
|
|
|
assert.Bytes(buffer.Value).Equals([]byte{'1', '2'})
|
|
|
|
}
|
|
|
|
|
2016-06-17 20:13:35 -04:00
|
|
|
func BenchmarkSimpleAuthenticator(b *testing.B) {
|
2016-07-28 10:24:15 -04:00
|
|
|
buffer := alloc.NewLocalBuffer(2048).Clear()
|
2016-12-05 15:33:24 -05:00
|
|
|
buffer.FillFullFrom(rand.Reader, 1024)
|
2016-06-17 20:13:35 -04:00
|
|
|
|
|
|
|
auth := NewSimpleAuthenticator()
|
|
|
|
b.SetBytes(int64(buffer.Len()))
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
auth.Seal(buffer)
|
|
|
|
auth.Open(buffer)
|
|
|
|
}
|
2016-06-17 10:51:41 -04:00
|
|
|
}
|