make key type deterministic with seed

This commit is contained in:
AJ ONeal 2020-08-02 00:11:50 +00:00
parent da712abbb2
commit bc7e9740d8
2 changed files with 9 additions and 4 deletions

View File

@ -41,13 +41,18 @@ func getOpts(r *http.Request) (*options, error) {
seed, _ = binary.ReadVarint(bytes.NewReader(b[0:8]))
}
var n int
if 0 != seed {
rndReader = rand.New(rand.NewSource(seed))
rnd := rand.New(rand.NewSource(seed))
rndReader = rnd
n = rnd.Intn(2)
} else {
n = rand.Intn(2)
}
kty, _ := tok["kty"].(string)
if "" == kty {
if 0 == rand.Intn(2) {
if 0 == n {
kty = "RSA"
} else {
kty = "EC"

View File

@ -121,7 +121,7 @@ func TestGenWithSeed(t *testing.T) {
res, err := client.Do(&http.Request{
Method: "POST",
URL: urlstr,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"seed":"test"}`))),
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"seed":"c"}`))),
})
if nil != err {
//t.Fatal(err)
@ -141,7 +141,7 @@ func TestGenWithSeed(t *testing.T) {
res, err = client.Do(&http.Request{
Method: "POST",
URL: urlstr,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"seed":"test"}`))),
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"seed":"c"}`))),
})
if nil != err {
//t.Fatal(err)