github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/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  
     8  	"github.com/v2fly/v2ray-core/v5/common"
     9  	. "github.com/v2fly/v2ray-core/v5/transport/internet/kcp"
    10  )
    11  
    12  func TestSimpleAuthenticator(t *testing.T) {
    13  	cache := make([]byte, 512)
    14  
    15  	payload := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
    16  
    17  	auth := NewSimpleAuthenticator()
    18  	b := auth.Seal(cache[:0], nil, payload, nil)
    19  	c, err := auth.Open(cache[:0], nil, b, nil)
    20  	common.Must(err)
    21  	if r := cmp.Diff(c, payload); r != "" {
    22  		t.Error(r)
    23  	}
    24  }
    25  
    26  func TestSimpleAuthenticator2(t *testing.T) {
    27  	cache := make([]byte, 512)
    28  
    29  	payload := []byte{'a', 'b'}
    30  
    31  	auth := NewSimpleAuthenticator()
    32  	b := auth.Seal(cache[:0], nil, payload, nil)
    33  	c, err := auth.Open(cache[:0], nil, b, nil)
    34  	common.Must(err)
    35  	if r := cmp.Diff(c, payload); r != "" {
    36  		t.Error(r)
    37  	}
    38  }