-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgroup_test.go
41 lines (35 loc) · 930 Bytes
/
group_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
package srp
import (
"math/big"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCreatesNewGroupFromRFC5054Spec(t *testing.T) {
var tests = []struct {
s string
p *big.Int
}{
{Group1024, big.NewInt(2)},
{Group2048, big.NewInt(2)},
{Group4096, big.NewInt(5)},
{Group8192, big.NewInt(19)},
}
// Spec is noted in RFC 5054 Appendix B
minBitSize := 1024
for _, test := range tests {
g, err := NewGroup(test.s)
assert.Equal(t, g.G, test.p)
assert.NoError(t, err)
assert.True(t, g.N.ProbablyPrime(10))
assert.True(t, g.N.BitLen() >= minBitSize)
}
}
func TestErrorForInvalidPrimeHexConversion(t *testing.T) {
g := &Group{Hex: "invalid-hex-value"}
_, err := g.CalcN()
assert.EqualError(t, err, "invalid prime value provided")
}
func TestErrorForInvalidRootPrimitive(t *testing.T) {
_, err := NewGroup("invalid:prime-as-hex")
assert.EqualError(t, err, "invalid primitive root provided")
}