Skip to content

Commit c1c9869

Browse files
committed
Show Ed25519 in the public-key log field.
1 parent 5a6517c commit c1c9869

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

api/api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto"
66
"crypto/dsa" //nolint
77
"crypto/ecdsa"
8+
"crypto/ed25519"
89
"crypto/rsa"
910
"crypto/x509"
1011
"encoding/asn1"
@@ -437,14 +438,15 @@ func parseCursor(r *http.Request) (cursor string, limit int, err error) {
437438
return
438439
}
439440

440-
// TODO: add support for Ed25519 once it's supported
441441
func fmtPublicKey(cert *x509.Certificate) string {
442442
var params string
443443
switch pk := cert.PublicKey.(type) {
444444
case *ecdsa.PublicKey:
445445
params = pk.Curve.Params().Name
446446
case *rsa.PublicKey:
447447
params = strconv.Itoa(pk.Size() * 8)
448+
case ed25519.PublicKey:
449+
return cert.PublicKeyAlgorithm.String()
448450
case *dsa.PublicKey:
449451
params = strconv.Itoa(pk.Q.BitLen() * 8)
450452
default:

api/api_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto"
77
"crypto/dsa" //nolint
88
"crypto/ecdsa"
9+
"crypto/ed25519"
910
"crypto/elliptic"
1011
"crypto/rand"
1112
"crypto/rsa"
@@ -1285,6 +1286,10 @@ func Test_fmtPublicKey(t *testing.T) {
12851286
if err != nil {
12861287
t.Fatal(err)
12871288
}
1289+
edPub, edPriv, err := ed25519.GenerateKey(rand.Reader)
1290+
if err != nil {
1291+
t.Fatal(err)
1292+
}
12881293
var dsa2048 dsa.PrivateKey
12891294
if err := dsa.GenerateParameters(&dsa2048.Parameters, rand.Reader, dsa.L2048N256); err != nil {
12901295
t.Fatal(err)
@@ -1304,6 +1309,7 @@ func Test_fmtPublicKey(t *testing.T) {
13041309
}{
13051310
{"p256", args{p256.Public(), p256, nil}, "ECDSA P-256"},
13061311
{"rsa1024", args{rsa1024.Public(), rsa1024, nil}, "RSA 1024"},
1312+
{"ed25519", args{edPub, edPriv, nil}, "Ed25519"},
13071313
{"dsa2048", args{cert: &x509.Certificate{PublicKeyAlgorithm: x509.DSA, PublicKey: &dsa2048.PublicKey}}, "DSA 2048"},
13081314
{"unknown", args{cert: &x509.Certificate{PublicKeyAlgorithm: x509.ECDSA, PublicKey: []byte("12345678")}}, "ECDSA unknown"},
13091315
}

0 commit comments

Comments
 (0)