crypt_test.go 834 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package kcp_test
  2. import (
  3. "crypto/rand"
  4. "testing"
  5. "github.com/v2ray/v2ray-core/common/alloc"
  6. "github.com/v2ray/v2ray-core/testing/assert"
  7. . "github.com/v2ray/v2ray-core/transport/internet/kcp"
  8. )
  9. func TestSimpleAuthenticator(t *testing.T) {
  10. assert := assert.On(t)
  11. buffer := alloc.NewBuffer().Clear()
  12. buffer.AppendBytes('a', 'b', 'c', 'd', 'e', 'f', 'g')
  13. auth := NewSimpleAuthenticator()
  14. auth.Seal(buffer)
  15. assert.Bool(auth.Open(buffer)).IsTrue()
  16. assert.Bytes(buffer.Value).Equals([]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'})
  17. }
  18. func BenchmarkSimpleAuthenticator(b *testing.B) {
  19. buffer := alloc.NewBuffer().Clear()
  20. buffer.Slice(0, 1024)
  21. rand.Read(buffer.Value)
  22. auth := NewSimpleAuthenticator()
  23. b.SetBytes(int64(buffer.Len()))
  24. b.ResetTimer()
  25. for i := 0; i < b.N; i++ {
  26. auth.Seal(buffer)
  27. auth.Open(buffer)
  28. }
  29. }