2016-06-17 10:51:41 -04:00
|
|
|
package kcp_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-01-18 09:59:39 -05:00
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
|
|
|
|
"v2ray.com/core/common"
|
2016-08-20 14:55:45 -04:00
|
|
|
. "v2ray.com/core/transport/internet/kcp"
|
2016-06-17 10:51:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSimpleAuthenticator(t *testing.T) {
|
2016-12-08 10:27:41 -05:00
|
|
|
cache := make([]byte, 512)
|
2016-06-17 10:51:41 -04:00
|
|
|
|
2016-12-08 10:27:41 -05:00
|
|
|
payload := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
|
2016-06-17 10:51:41 -04:00
|
|
|
|
2016-12-08 10:27:41 -05:00
|
|
|
auth := NewSimpleAuthenticator()
|
|
|
|
b := auth.Seal(cache[:0], nil, payload, nil)
|
|
|
|
c, err := auth.Open(cache[:0], nil, b, nil)
|
2019-01-18 09:59:39 -05:00
|
|
|
common.Must(err)
|
|
|
|
if r := cmp.Diff(c, payload); r != "" {
|
|
|
|
t.Error(r)
|
|
|
|
}
|
2016-06-17 20:13:35 -04:00
|
|
|
}
|
|
|
|
|
2016-06-18 04:58:21 -04:00
|
|
|
func TestSimpleAuthenticator2(t *testing.T) {
|
2016-12-08 10:27:41 -05:00
|
|
|
cache := make([]byte, 512)
|
2016-06-18 04:58:21 -04:00
|
|
|
|
2016-12-08 10:27:41 -05:00
|
|
|
payload := []byte{'a', 'b'}
|
2016-06-17 20:13:35 -04:00
|
|
|
|
|
|
|
auth := NewSimpleAuthenticator()
|
2016-12-08 10:27:41 -05:00
|
|
|
b := auth.Seal(cache[:0], nil, payload, nil)
|
|
|
|
c, err := auth.Open(cache[:0], nil, b, nil)
|
2019-01-18 09:59:39 -05:00
|
|
|
common.Must(err)
|
|
|
|
if r := cmp.Diff(c, payload); r != "" {
|
|
|
|
t.Error(r)
|
|
|
|
}
|
2016-06-17 10:51:41 -04:00
|
|
|
}
|