@cryptotaxi247 / kubo / commits / da979299d

go-ipfs-config: error if bit size specified with ed25519 keys (#105)

Petar Maymounkov committed Jul 14, 2020 at 09:50 UTC da979299da9b12a2808c28af5650cae53708d4cf
2 files changed +16
config/init.go
+3
@@ -200,6 +200,9 @@ func CreateIdentity(out io.Writer, opts []options.KeyGenerateOption) (Identity,
200 sk = priv
201 pk = pub
202 case "ed25519":
203 + if settings.Size != -1 {
204 + return ident, fmt.Errorf("number of key bits does not apply when using ed25519 keys")
205 + }
206 fmt.Fprintf(out, "generating ED25519 keypair...")
207 priv, pub, err := ci.GenerateEd25519Key(rand.Reader)
208 if err != nil {
config/init_test.go
+13
@@ -34,3 +34,16 @@ func TestCreateIdentity(t *testing.T) {
34 t.Fatal("unexpected type:", pk.Type())
35 }
36 }
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 +}