feat: add get_private_key_pkcs8_string()#124
Merged
timlegge merged 2 commits intocpan-authors:mainfrom Apr 5, 2026
Merged
Conversation
Collaborator
|
view the error only on bullseye distro @Koan-Bot rebase |
Export private keys in PKCS#8 format (-----BEGIN PRIVATE KEY-----), mirroring the get_public_key_x509_string() / get_public_key_pkcs1_string() split on the public key side. Uses PEM_write_bio_PrivateKey() which natively produces PKCS#8. On pre-3.x OpenSSL, wraps the RSA* in a temporary EVP_PKEY* since PEM_write_bio_PrivateKey() requires EVP_PKEY. Supports optional passphrase + cipher parameters (same interface as get_private_key_string), producing encrypted PKCS#8 format (-----BEGIN ENCRYPTED PRIVATE KEY-----). Tests: 9 new tests covering format validation, round-trips (PKCS#8 and cross-format PKCS#8↔PKCS#1), encrypted PKCS#8, and error paths. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3284643 to
11d2db5
Compare
Contributor
Author
Rebase: feat: add get_private_key_pkcs8_string()Branch Diff: 3 files changed, 125 insertions(+), 1 deletion(-) Review feedback was analyzed and applied. Actions
CICI passed. Automated by Kōan |
atoomic
approved these changes
Mar 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add
get_private_key_pkcs8_string()to export private keys in PKCS#8 PEM format (-----BEGIN PRIVATE KEY-----).Why
The public key side already has both PKCS#1 (
get_public_key_string/get_public_key_pkcs1_string) and X.509 (get_public_key_x509_string) export. The private key side only had PKCS#1 (get_private_key_string→BEGIN RSA PRIVATE KEY). PKCS#8 is the modern standard format — it's whatopenssl pkeyproduces and what many libraries expect.How
PEM_write_bio_PrivateKey()directly on the EVP_PKEY — produces PKCS#8 natively.EVP_PKEY_set1_RSAwhich increments refcount), callsPEM_write_bio_PrivateKey(), frees the wrapper. Error paths use THROW/goto err pattern to prevent leaks.get_private_key_string), producing encrypted PKCS#8 (BEGIN ENCRYPTED PRIVATE KEY).Testing
9 new tests in format.t: header/footer format, cross-format round-trips (PKCS#8↔PKCS#1), encrypted PKCS#8 round-trip, and error paths. Full suite: 469 tests pass.
🤖 Generated with Claude Code
Quality Report
Changes: 3 files changed, 111 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline