Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

error if bit size specified with ed25519 keys #105

Merged
merged 3 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 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 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")
}
}