oficina / fichas Public

Clone
git clone https://amadan.net/oficina/fichas

Plain git — no account needed to clone.

Download

Download this file

1package seal
2
3import "testing"
4
5func BenchmarkOpen(b *testing.B) {
6 s, _ := New(vectorDEK())
7 ct, _ := s.Seal(PurposeValue, []byte("ana@brightwater.example"))
8 b.ResetTimer()
9 for i := 0; i < b.N; i++ {
10 if _, err := s.Open(PurposeValue, ct); err != nil {
11 b.Fatal(err)
12 }
13 }
14}
15
16// The cache must not change a single byte of what is derived or sealed —
17// TestPurposeKeyVectors pins the keys; this pins that a value sealed before
18// the cache existed still opens, from many goroutines at once.
19func TestTheCacheIsSafeUnderConcurrency(t *testing.T) {
20 s, _ := New(vectorDEK())
21 ct, err := s.Seal(PurposeValue, []byte("same"))
22 if err != nil {
23 t.Fatal(err)
24 }
25 done := make(chan error, 64)
26 for g := 0; g < 64; g++ {
27 go func() {
28 for i := 0; i < 200; i++ {
29 got, err := s.Open(PurposeValue, ct)
30 if err != nil || string(got) != "same" {
31 done <- err
32 return
33 }
34 if _, err := s.Seal(PurposeLabel, []byte("x")); err != nil {
35 done <- err
36 return
37 }
38 }
39 done <- nil
40 }()
41 }
42 for g := 0; g < 64; g++ {
43 if err := <-done; err != nil {
44 t.Fatal(err)
45 }
46 }
47}
48