v2ray-core/transport/internet/kcp/crypt_test.go

37 lines
777 B
Go
Raw Normal View History

2016-06-17 14:51:41 +00:00
package kcp_test
import (
"testing"
2016-08-20 18:55:45 +00:00
"v2ray.com/core/testing/assert"
. "v2ray.com/core/transport/internet/kcp"
2016-06-17 14:51:41 +00:00
)
func TestSimpleAuthenticator(t *testing.T) {
assert := assert.On(t)
2016-12-08 15:27:41 +00:00
cache := make([]byte, 512)
2016-06-17 14:51:41 +00:00
2016-12-08 15:27:41 +00:00
payload := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
2016-06-17 14:51:41 +00:00
2016-12-08 15:27:41 +00:00
auth := NewSimpleAuthenticator()
b := auth.Seal(cache[:0], nil, payload, nil)
c, err := auth.Open(cache[:0], nil, b, nil)
assert.Error(err).IsNil()
assert.Bytes(c).Equals(payload)
}
func TestSimpleAuthenticator2(t *testing.T) {
assert := assert.On(t)
2016-12-08 15:27:41 +00:00
cache := make([]byte, 512)
2016-12-08 15:27:41 +00:00
payload := []byte{'a', 'b'}
auth := NewSimpleAuthenticator()
2016-12-08 15:27:41 +00:00
b := auth.Seal(cache[:0], nil, payload, nil)
c, err := auth.Open(cache[:0], nil, b, nil)
assert.Error(err).IsNil()
assert.Bytes(c).Equals(payload)
2016-06-17 14:51:41 +00:00
}