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

Commit 0b25905

Browse files
authored
error if bit size specified with ed25519 keys (#105)
1 parent 9a18412 commit 0b25905

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

init.go

+3
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ func CreateIdentity(out io.Writer, opts []options.KeyGenerateOption) (Identity,
200200
sk = priv
201201
pk = pub
202202
case "ed25519":
203+
if settings.Size != -1 {
204+
return ident, fmt.Errorf("number of key bits does not apply when using ed25519 keys")
205+
}
203206
fmt.Fprintf(out, "generating ED25519 keypair...")
204207
priv, pub, err := ci.GenerateEd25519Key(rand.Reader)
205208
if err != nil {

init_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,16 @@ func TestCreateIdentity(t *testing.T) {
3434
t.Fatal("unexpected type:", pk.Type())
3535
}
3636
}
37+
38+
func TestCreateIdentityOptions(t *testing.T) {
39+
var w bytes.Buffer
40+
41+
// ed25519 keys with bit size must fail.
42+
_, err := CreateIdentity(&w, []options.KeyGenerateOption{
43+
options.Key.Type(options.Ed25519Key),
44+
options.Key.Size(2048),
45+
})
46+
if err == nil {
47+
t.Errorf("ed25519 keys cannot have a custom bit size")
48+
}
49+
}

0 commit comments

Comments
 (0)