-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
77 lines (67 loc) · 1.44 KB
/
message_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"bytes"
"testing"
"github.com/tehmaze-labs/secrets/key"
"golang.org/x/crypto/nacl/secretbox"
)
var text = `They're taking the hobbits to Isengard!
They're taking the hobbits to Isengard!
They're taking the hobbits to Isengard!
They're taking the hobbits to Isengard!
They're taking the hobbits to Isengard!
They're taking the hobbits to Isengard!
They're taking the hobbits to Isengard!
What did you say?
The hobbits
The hobbits
The hobbits
The hobbits
To Isengard!
To Isengard!
The hobbits
The hobbits
The hobbits
The hobbits
`
func TestSecret(t *testing.T) {
sKey, err := key.NewPrivateKey()
if err != nil {
t.Error(err)
return
}
rKeys := []*key.Key{}
rPubs := []*key.Key{}
for i := 0; i < 8; i++ {
rKey, err := key.NewPrivateKey()
if err != nil {
t.Error(err)
return
}
rKeys = append(rKeys, rKey)
rPubs = append(rPubs, rKey.AsPublicKey())
}
message := []byte(text)
for i, secret := range NewGroupSecret(message, sKey, rPubs) {
out, err := secret.Marshal()
if err != nil {
t.Error(err)
return
}
//fmt.Fprintf(os.Stderr, string(out))
if len(message) < secretbox.Overhead {
t.Errorf("%d bytes message smaller than overhead %d", len(message), secretbox.Overhead)
return
}
output, err := secret.Decrypt(rKeys[i])
if err != nil {
t.Error(err)
return
}
if !bytes.Equal(output, message) {
t.Error("corrupt")
return
}
//t.Logf("good, got %q", string(output))
}
}