-
Notifications
You must be signed in to change notification settings - Fork 9
/
encrypt_event_test.go
47 lines (41 loc) · 1.25 KB
/
encrypt_event_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
package eventencryptor_test
import (
"math/rand"
"github.com/inklabs/rangedb/pkg/crypto/aes"
"github.com/inklabs/rangedb/pkg/crypto/cryptotest"
"github.com/inklabs/rangedb/pkg/crypto/eventencryptor"
"github.com/inklabs/rangedb/pkg/crypto/provider/inmemorykeystore"
)
func ExampleEventEncryptor_Encrypt() {
// Given
seededRandReader := rand.New(rand.NewSource(100))
aesEncryptor := aes.NewGCM()
aesEncryptor.SetRandReader(seededRandReader)
keyStore := inmemorykeystore.New()
eventEncryptor := eventencryptor.New(keyStore, aesEncryptor)
eventEncryptor.SetRandReader(seededRandReader)
event := &cryptotest.CustomerSignedUp{
ID: "fe65ac8d8c3a45e9b3cee407f10ee518",
Name: "John Doe",
Email: "[email protected]",
Status: "active",
}
// When
PrintError(eventEncryptor.Encrypt(event))
PrintEvent(event)
PrintError(eventEncryptor.Decrypt(event))
PrintEvent(event)
// Output:
// {
// "ID": "fe65ac8d8c3a45e9b3cee407f10ee518",
// "Name": "Lp5pGK8QGYw3NJyJVBsW49HESSf+NEraAQoBmpLXboZvsN/L",
// "Email": "o1H9t1BClYc5UcyUV+Roe3wz5gwRZRjgBI/xzwZs8ueQGQ5L8uGnbrTGrh8=",
// "Status": "active"
// }
// {
// "ID": "fe65ac8d8c3a45e9b3cee407f10ee518",
// "Name": "John Doe",
// "Email": "[email protected]",
// "Status": "active"
// }
}