github.com/moqsien/xraycore@v1.8.5/transport/internet/kcp/crypt_test.go (about)

     1  package kcp_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/google/go-cmp/cmp"
     7  	"github.com/moqsien/xraycore/common"
     8  	. "github.com/moqsien/xraycore/transport/internet/kcp"
     9  )
    10  
    11  func TestSimpleAuthenticator(t *testing.T) {
    12  	cache := make([]byte, 512)
    13  
    14  	payload := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
    15  
    16  	auth := NewSimpleAuthenticator()
    17  	b := auth.Seal(cache[:0], nil, payload, nil)
    18  	c, err := auth.Open(cache[:0], nil, b, nil)
    19  	common.Must(err)
    20  	if r := cmp.Diff(c, payload); r != "" {
    21  		t.Error(r)
    22  	}
    23  }
    24  
    25  func TestSimpleAuthenticator2(t *testing.T) {
    26  	cache := make([]byte, 512)
    27  
    28  	payload := []byte{'a', 'b'}
    29  
    30  	auth := NewSimpleAuthenticator()
    31  	b := auth.Seal(cache[:0], nil, payload, nil)
    32  	c, err := auth.Open(cache[:0], nil, b, nil)
    33  	common.Must(err)
    34  	if r := cmp.Diff(c, payload); r != "" {
    35  		t.Error(r)
    36  	}
    37  }