Commit f3048ab7 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Juan Batiz-Benet

refactor(init) extract bits flag

parent 630b88d2
...@@ -42,7 +42,16 @@ var initCmd = &cmds.Command{ ...@@ -42,7 +42,16 @@ var initCmd = &cmds.Command{
return return
} }
err := foo(res, req, dspath, force) arg, found = req.Option("b")
nBitsForKeypair, ok := arg.(int) // TODO param
if found && !ok {
res.SetError(errors.New("failed to get bits flag"), cmds.ErrNormal)
return
} else if !found {
nBitsForKeypair = 4096
}
err := foo(res, req, dspath, force, nBitsForKeypair)
if err != nil { if err != nil {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
...@@ -50,7 +59,7 @@ var initCmd = &cmds.Command{ ...@@ -50,7 +59,7 @@ var initCmd = &cmds.Command{
}, },
} }
func foo(res cmds.Response, req cmds.Request, dspath string, force bool) error { func foo(res cmds.Response, req cmds.Request, dspath string, force bool, nBitsForKeypair int) error {
ctx := req.Context() ctx := req.Context()
u.POut("initializing ipfs node at %s\n", ctx.ConfigRoot) u.POut("initializing ipfs node at %s\n", ctx.ConfigRoot)
...@@ -104,19 +113,13 @@ func foo(res cmds.Response, req cmds.Request, dspath string, force bool) error { ...@@ -104,19 +113,13 @@ func foo(res cmds.Response, req cmds.Request, dspath string, force bool) error {
IPNS: "/ipns", IPNS: "/ipns",
} }
arg, found = req.Option("b") // TODO guard
nbits, ok := arg.(int) // TODO param if nBitsForKeypair < 1024 {
if found && !ok {
return errors.New("failed to get bits flag")
} else if !found {
nbits = 4096
}
if nbits < 1024 {
return errors.New("Bitsize less than 1024 is considered unsafe.") return errors.New("Bitsize less than 1024 is considered unsafe.")
} }
u.POut("generating key pair\n") u.POut("generating key pair\n")
sk, pk, err := ci.GenerateKeyPair(ci.RSA, nbits) sk, pk, err := ci.GenerateKeyPair(ci.RSA, nBitsForKeypair)
if err != nil { if err != nil {
return err return err
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment