-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtokenizer_verbatim.go
61 lines (48 loc) · 1016 Bytes
/
tokenizer_verbatim.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
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"sync"
uuid "github.com/google/uuid"
)
// verbatimTokenizer implements a pseudo tokenizer that returns the same data
// that it was given.
type verbatimTokenizer struct {
sync.RWMutex
key *keyID
}
func newVerbatimTokenizer() tokenizer {
return &verbatimTokenizer{}
}
func (v *verbatimTokenizer) tokenize(s serializer) (token, error) {
v.RLock()
defer v.RUnlock()
if v.key == nil {
return nil, errNoKey
}
return token(s.bytes()), nil
}
func (v *verbatimTokenizer) tokenizeAndKeyID(s serializer) (token, *keyID, error) {
v.RLock()
defer v.RUnlock()
if v.key == nil {
return nil, nil, errNoKey
}
return token(s.bytes()), v.key, nil
}
func (v *verbatimTokenizer) keyID() *keyID {
v.RLock()
defer v.RUnlock()
return v.key
}
func (v *verbatimTokenizer) resetKey() error {
v.Lock()
defer v.Unlock()
u, err := uuid.NewRandom()
if err != nil {
return err
}
v.key = &keyID{UUID: u}
return nil
}
func (v *verbatimTokenizer) preservesLen() bool {
return true
}