-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdelete_encryption_key_test.go
53 lines (45 loc) · 1.34 KB
/
delete_encryption_key_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
50
51
52
53
package eventencryptor_test
import (
"fmt"
"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 ExampleKeyStore_Delete() {
// 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: "62df778c16f84969a8a5448a9ce00218",
Name: "John Doe",
Email: "[email protected]",
Status: "active",
}
// When
PrintError(eventEncryptor.Encrypt(event))
PrintEvent(event)
PrintError(keyStore.Delete(event.AggregateID()))
err := eventEncryptor.Decrypt(event)
fmt.Printf("error: %v\n", err)
PrintEvent(event)
// Output:
// {
// "ID": "62df778c16f84969a8a5448a9ce00218",
// "Name": "Lp5pGK8QGYw3NJyJVBsW49HESSf+NEraAQoBmpLXboZvsN/L",
// "Email": "o1H9t1BClYc5UcyUV+Roe3wz5gwRZRjgBI/xzwZs8ueQGQ5L8uGnbrTGrh8=",
// "Status": "active"
// }
// error: removed from GDPR request
// {
// "ID": "62df778c16f84969a8a5448a9ce00218",
// "Name": "",
// "Email": "",
// "Status": "active"
// }
}