-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenizer_cryptopan_test.go
49 lines (40 loc) · 1 KB
/
tokenizer_cryptopan_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"errors"
"testing"
)
func TestEmptyCryptoPAnKey(t *testing.T) {
c := newCryptoPAnTokenizer()
v := blob([]byte{1, 2, 3, 4})
_, err := c.tokenize(v)
if !errors.Is(err, errNoKey) {
t.Fatalf("Expected error '%v' but got '%v'.", errNoKey, err)
}
}
func TestCryptoPAnPreservesLen(t *testing.T) {
c := newCryptoPAnTokenizer()
if !c.preservesLen() {
t.Fatalf("Crypto-PAn tokenizer expected to preserve length but it doesn't.")
}
}
func TestBadBlobLen(t *testing.T) {
c := newCryptoPAnTokenizer()
v := blob([]byte{0})
_ = c.resetKey()
_, err := c.tokenize(v)
if !errors.Is(err, errBadBlobLen) {
t.Fatalf("Expected error '%v' but got '%v'.", errBadBlobLen, err)
}
_, _, err = c.tokenizeAndKeyID(v)
if !errors.Is(err, errBadBlobLen) {
t.Fatalf("Expected error '%v' but got '%v'.", errBadBlobLen, err)
}
}
func BenchmarkCryptoPAn(b *testing.B) {
c := newCryptoPAnTokenizer()
_ = c.resetKey()
v := blob([]byte{1, 2, 3, 4})
for i := 0; i < b.N; i++ {
_, _ = c.tokenize(v)
}
}