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

38 lines
803 B
Go
Raw Permalink Normal View History

2020-11-25 11:01:53 +00:00
package kcp_test
import (
"testing"
"github.com/google/go-cmp/cmp"
2020-12-04 01:36:16 +00:00
"github.com/xtls/xray-core/common"
. "github.com/xtls/xray-core/transport/internet/kcp"
2020-11-25 11:01:53 +00:00
)
func TestSimpleAuthenticator(t *testing.T) {
cache := make([]byte, 512)
payload := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
auth := NewSimpleAuthenticator()
b := auth.Seal(cache[:0], nil, payload, nil)
c, err := auth.Open(cache[:0], nil, b, nil)
common.Must(err)
if r := cmp.Diff(c, payload); r != "" {
t.Error(r)
}
}
func TestSimpleAuthenticator2(t *testing.T) {
cache := make([]byte, 512)
payload := []byte{'a', 'b'}
auth := NewSimpleAuthenticator()
b := auth.Seal(cache[:0], nil, payload, nil)
c, err := auth.Open(cache[:0], nil, b, nil)
common.Must(err)
if r := cmp.Diff(c, payload); r != "" {
t.Error(r)
}
}