forked from didiercrunch/paillier
-
Notifications
You must be signed in to change notification settings - Fork 2
/
safe_prime_generator_test.go
67 lines (61 loc) · 1.28 KB
/
safe_prime_generator_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
package paillier
import (
"crypto/rand"
"errors"
"reflect"
"testing"
"time"
)
func TestAsyncGenerator(t *testing.T) {
concurrencyLevel := 4
var tests = map[string]struct {
bitLen int
timeout time.Duration
expectedError error
}{
"primes successfully generated": {
bitLen: 512,
timeout: 60 * time.Second,
expectedError: nil,
},
"generator timed out": {
bitLen: 8192,
timeout: 1 * time.Second,
expectedError: errors.New("generator timed out after 1s"),
},
"bit length is 5": {
bitLen: 5,
timeout: 1 * time.Second,
expectedError: errors.New("safe prime size must be at least 6 bits"),
},
"bit length is 6": {
bitLen: 6,
timeout: 60 * time.Second,
expectedError: nil,
},
}
for testName, test := range tests {
t.Run(testName, func(t *testing.T) {
p, q, err := GenerateSafePrime(
test.bitLen,
concurrencyLevel,
test.timeout,
rand.Reader,
)
if test.expectedError != nil {
if !reflect.DeepEqual(test.expectedError, err) {
t.Fatalf(
"Unexpected error\nActual: %v\nExpected: %v",
err,
test.expectedError,
)
}
} else {
if err != nil {
t.Fatal(err)
}
IsSafePrime(p, q, test.bitLen, t)
}
})
}
}