mirror of
https://github.com/slackhq/nebula.git
synced 2025-12-06 02:30:57 -08:00
helper functions to more correctly marshal curve 25519 public keys
This commit is contained in:
parent
f8837928a9
commit
6798c3f7af
4 changed files with 26 additions and 0 deletions
|
|
@ -58,6 +58,9 @@ type Certificate interface {
|
|||
// PublicKey is the raw bytes to be used in asymmetric cryptographic operations.
|
||||
PublicKey() []byte
|
||||
|
||||
// PublicKeyPem is the value of PublicKey marshalled to PEM
|
||||
PublicKeyPem() []byte
|
||||
|
||||
// Curve identifies which curve was used for the PublicKey and Signature.
|
||||
Curve() Curve
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,10 @@ func (c *certificateV1) PublicKey() []byte {
|
|||
return c.details.publicKey
|
||||
}
|
||||
|
||||
func (c *certificateV1) PublicKeyPem() []byte {
|
||||
return marshalCertPublicKeyToPEM(c)
|
||||
}
|
||||
|
||||
func (c *certificateV1) Signature() []byte {
|
||||
return c.signature
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,10 @@ func (c *certificateV2) PublicKey() []byte {
|
|||
return c.publicKey
|
||||
}
|
||||
|
||||
func (c *certificateV2) PublicKeyPem() []byte {
|
||||
return marshalCertPublicKeyToPEM(c)
|
||||
}
|
||||
|
||||
func (c *certificateV2) Signature() []byte {
|
||||
return c.signature
|
||||
}
|
||||
|
|
|
|||
15
cert/pem.go
15
cert/pem.go
|
|
@ -54,6 +54,21 @@ func UnmarshalCertificateFromPEM(b []byte) (Certificate, []byte, error) {
|
|||
|
||||
}
|
||||
|
||||
func marshalCertPublicKeyToPEM(c Certificate) []byte {
|
||||
switch c.Curve() {
|
||||
case Curve_CURVE25519:
|
||||
if c.IsCA() {
|
||||
return pem.EncodeToMemory(&pem.Block{Type: Ed25519PublicKeyBanner, Bytes: c.PublicKey()})
|
||||
} else {
|
||||
return pem.EncodeToMemory(&pem.Block{Type: X25519PublicKeyBanner, Bytes: c.PublicKey()})
|
||||
}
|
||||
case Curve_P256:
|
||||
return MarshalPublicKeyToPEM(Curve_P256, c.PublicKey())
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func MarshalPublicKeyToPEM(curve Curve, b []byte) []byte {
|
||||
switch curve {
|
||||
case Curve_CURVE25519:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue