-
Notifications
You must be signed in to change notification settings - Fork 0
/
sss_test.go
43 lines (40 loc) · 978 Bytes
/
sss_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
package gosss
import (
"bytes"
"math/rand"
"testing"
)
var examplePrivateMessage = []byte("Lorem ipsum.")
func TestHideRecoverMessage(t *testing.T) {
config := &Config{
Shares: 33,
Min: 22,
}
totalShares, err := HideMessage(examplePrivateMessage, config)
if err != nil {
t.Errorf("unexpected error: %v", err)
return
}
// get some shares randomly of the total and recover the message
shares := []string{}
chosen := map[string]int{}
for len(chosen) < config.Min {
// random number between 0 and 35
idx := rand.Intn(config.Shares)
_, ok := chosen[totalShares[idx]]
for ok {
idx = rand.Intn(config.Shares)
_, ok = chosen[totalShares[idx]]
}
chosen[totalShares[idx]] = idx
shares = append(shares, totalShares[idx])
}
message, err := RecoverMessage(shares, config)
if err != nil {
t.Errorf("unexpected error: %v", err)
return
}
if !bytes.Equal(message, examplePrivateMessage) {
t.Errorf("unexpected message: %s", message)
}
}