Add DER export functions for public and private keys#186
Draft
toddr-bot wants to merge 1 commit into
Draft
Conversation
The module supported DER import via new_public_key() and new_private_key() but had no DER export counterparts, forcing users to manually base64-decode PEM output. New methods: - get_public_key_der_string / get_public_key_pkcs1_der_string - get_public_key_x509_der_string - get_private_key_der_string - get_private_key_pkcs8_der_string (with optional passphrase/cipher) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Why
Users who needed DER-encoded keys had to manually strip PEM headers and base64-decode — error-prone and surprising for a module that already handles DER import transparently.
How
Each function follows the pattern of its PEM counterpart:
get_public_key_der_string):i2d_RSAPublicKey_bioon pre-3.x,OSSL_ENCODERwith DER/PKCS1 on 3.xget_public_key_x509_der_string):i2d_RSA_PUBKEY_bio/i2d_PUBKEY_bioget_private_key_der_string):i2d_RSAPrivateKey_bio/i2d_PrivateKey_bioget_private_key_pkcs8_der_string):i2d_PKCS8PrivateKey_bio(with pre-3.x EVP_PKEY wrapper)PKCS#8 DER supports optional passphrase/cipher for encrypted export, matching the PEM version.
Testing
t/der.tcovering:pem_to_der(PEM export)for each format🤖 Generated with Claude Code
Quality Report
Changes: 3 files changed, 254 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline