started to implement the key generator

This commit is contained in:
didier.amyot committed 2014-07-29 11:45:23 -04:00
1 parent ad4510711e
commit 776c73b91c
7 files changed
+233 -2

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
package main
import (
"crypto/rsa"
"math/big"
"testing"
)
func b(x int64) *big.Int {
return big.NewInt(x)
}
func TestGetDefaultRSAPublicKey(t *testing.T) {
key := &rsa.PublicKey{b(31 * 11), 3}
pk := GetDefaultRSAPublicKey(key)
niceKey, ok := pk.Key.(*RSAPublicKey)
if !ok {
t.Error("bad key type")
return
}
if big.NewInt(31*11).Cmp(niceKey.N) != 0 {
t.Error("bad N")
}
if 3 != niceKey.E {
t.Error("bad e")
}
}
func TestGetDefaultRSAPrivateKey(t *testing.T) {
privKey := &rsa.PrivateKey{
rsa.PublicKey{b(3 * 11), 7},
b(3),
[]*big.Int{b(3), b(11)},
rsa.PrecomputedValues{},
}
pk, err := GetDefaultRSAPrivateKey(privKey)
if err != nil {
t.Error(err)
}
niceKey, ok := pk.Key.(*RSAPrivateKey)
if !ok {
t.Error("bad key type")
return
}
if niceKey.D.Int64() != 3 {
t.Error("bad D")
}
if niceKey.E != 7 {
t.Error("bad D")
}
if niceKey.P.Int64() != 3 {
t.Error("bad D")
}
if niceKey.Q.Int64() != 11 {
t.Error("bad D")
}
}