Skip to content

Commit

Permalink
go-ipfs-config: error if bit size specified with ed25519 keys (ipfs#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
petar committed Jul 14, 2020
1 parent f348f9b commit cac1d0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ func CreateIdentity(out io.Writer, opts []options.KeyGenerateOption) (Identity,
sk = priv
pk = pub
case "ed25519":
if settings.Size != -1 {
return ident, fmt.Errorf("number of key bits does not apply when using ed25519 keys")
}
fmt.Fprintf(out, "generating ED25519 keypair...")
priv, pub, err := ci.GenerateEd25519Key(rand.Reader)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions config/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ func TestCreateIdentity(t *testing.T) {
t.Fatal("unexpected type:", pk.Type())
}
}

func TestCreateIdentityOptions(t *testing.T) {
var w bytes.Buffer

// ed25519 keys with bit size must fail.
_, err := CreateIdentity(&w, []options.KeyGenerateOption{
options.Key.Type(options.Ed25519Key),
options.Key.Size(2048),
})
if err == nil {
t.Errorf("ed25519 keys cannot have a custom bit size")
}
}

0 comments on commit cac1d0f

Please sign in to comment.