Skip to content

Commit

Permalink
feat: add support for public RSA key in RSAKey
Browse files Browse the repository at this point in the history
Generates public key PEM in addition to private key PEM.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Jan 21, 2021
1 parent bda0e9c commit 562c3b6
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions x509/x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ type Ed25519Key struct {

// RSAKey represents an RSA key.
type RSAKey struct {
keyRSA *rsa.PrivateKey
KeyPEM []byte
keyRSA *rsa.PrivateKey
KeyPEM []byte
PublicKeyPEM []byte
}

// ECDSAKey represents an ECDSA key.
Expand Down Expand Up @@ -370,9 +371,20 @@ func NewRSAKey() (key *RSAKey, err error) {
Bytes: keyBytes,
})

publicKeyBytes, err := x509.MarshalPKIXPublicKey(&keyRSA.PublicKey)
if err != nil {
return
}

publicKeyPEM := pem.EncodeToMemory(&pem.Block{
Type: "PUBLIC KEY",
Bytes: publicKeyBytes,
})

key = &RSAKey{
keyRSA: keyRSA,
KeyPEM: keyPEM,
keyRSA: keyRSA,
KeyPEM: keyPEM,
PublicKeyPEM: publicKeyPEM,
}

return key, nil
Expand Down

0 comments on commit 562c3b6

Please sign in to comment.