crypt_test.go 777 B

123456789101112131415161718192021222324252627282930313233343536
  1. package kcp_test
  2. import (
  3. "testing"
  4. "v2ray.com/core/testing/assert"
  5. . "v2ray.com/core/transport/internet/kcp"
  6. )
  7. func TestSimpleAuthenticator(t *testing.T) {
  8. assert := assert.On(t)
  9. cache := make([]byte, 512)
  10. payload := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
  11. auth := NewSimpleAuthenticator()
  12. b := auth.Seal(cache[:0], nil, payload, nil)
  13. c, err := auth.Open(cache[:0], nil, b, nil)
  14. assert.Error(err).IsNil()
  15. assert.Bytes(c).Equals(payload)
  16. }
  17. func TestSimpleAuthenticator2(t *testing.T) {
  18. assert := assert.On(t)
  19. cache := make([]byte, 512)
  20. payload := []byte{'a', 'b'}
  21. auth := NewSimpleAuthenticator()
  22. b := auth.Seal(cache[:0], nil, payload, nil)
  23. c, err := auth.Open(cache[:0], nil, b, nil)
  24. assert.Error(err).IsNil()
  25. assert.Bytes(c).Equals(payload)
  26. }