Skip to content

Commit 05b4aa3

Browse files
committed
x509{,util}: support X25519 public key parsing
1 parent 9bc27bb commit 05b4aa3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

x509/x509.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
// - Support for parsing RSASES-OAEP public keys from certificates
4040
// - Ed25519 support:
4141
// - Support for parsing and marshaling Ed25519 keys
42+
// - X25519 support:
43+
// - Support for parsing X25519 keys
4244
// - General improvements:
4345
// - Export and use OID values throughout.
4446
// - Export OIDFromNamedCurve().
@@ -321,6 +323,7 @@ const (
321323
ECDSA
322324
Ed25519
323325
RSAESOAEP
326+
X25519
324327
)
325328

326329
var publicKeyAlgoName = [...]string{
@@ -329,6 +332,7 @@ var publicKeyAlgoName = [...]string{
329332
ECDSA: "ECDSA",
330333
Ed25519: "Ed25519",
331334
RSAESOAEP: "RSAESOAEP",
335+
X25519: "X25519",
332336
}
333337

334338
func (algo PublicKeyAlgorithm) String() string {
@@ -584,6 +588,7 @@ var (
584588
OIDPublicKeyECDSA = asn1.ObjectIdentifier{1, 2, 840, 10045, 2, 1}
585589
OIDPublicKeyRSAObsolete = asn1.ObjectIdentifier{2, 5, 8, 1, 1}
586590
OIDPublicKeyEd25519 = oidSignatureEd25519
591+
OIDPublicKeyX25519 = asn1.ObjectIdentifier{1, 3, 101, 110}
587592
)
588593

589594
func getPublicKeyAlgorithmFromOID(oid asn1.ObjectIdentifier) PublicKeyAlgorithm {
@@ -598,6 +603,8 @@ func getPublicKeyAlgorithmFromOID(oid asn1.ObjectIdentifier) PublicKeyAlgorithm
598603
return RSAESOAEP
599604
case oid.Equal(OIDPublicKeyEd25519):
600605
return Ed25519
606+
case oid.Equal(OIDPublicKeyX25519):
607+
return X25519
601608
}
602609
return UnknownPublicKeyAlgorithm
603610
}
@@ -1451,6 +1458,8 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo, nfe *NonFat
14511458
return pub, nil
14521459
case Ed25519:
14531460
return ed25519.PublicKey(asn1Data), nil
1461+
case X25519:
1462+
return asn1Data, nil
14541463
default:
14551464
return nil, nil
14561465
}

x509util/x509util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ func publicKeyAlgorithmToString(algo x509.PublicKeyAlgorithm) string {
106106
return "id-ecPublicKey"
107107
case x509.Ed25519:
108108
return "Ed25519"
109+
case x509.X25519:
110+
return "X25519"
109111
default:
110112
return strconv.Itoa(int(algo))
111113
}
@@ -180,6 +182,9 @@ func publicKeyToString(_ x509.PublicKeyAlgorithm, pub interface{}) string {
180182
case ed25519.PublicKey:
181183
buf.WriteString(" pub:\n")
182184
appendHexData(&buf, []byte(pub), 15, " ")
185+
case []byte:
186+
buf.WriteString(" pub:\n")
187+
appendHexData(&buf, pub, 15, " ")
183188
default:
184189
buf.WriteString(fmt.Sprintf(" %T: %v", pub, pub))
185190
}

0 commit comments

Comments
 (0)