From f74474a241098f452c5505de2b49e55b92effd10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C5=8Dan?= Date: Mon, 16 Mar 2026 03:28:11 -0600 Subject: [PATCH] feat: add get_public_key_pkcs1_string() alias for API symmetry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The import API has _new_public_key_pkcs1 / _new_public_key_x509, but the export side had get_public_key_string (PKCS#1) / get_public_key_x509_string without "pkcs1" in the PKCS#1 name. This adds get_public_key_pkcs1_string() as a Perl-level alias to fix the naming asymmetry. - Alias via glob assignment (*func = \&func) — zero overhead, no XS changes - POD documentation with cross-references to related methods - 4 new tests in format.t: output correctness, alias equivalence, round-trip Co-Authored-By: Claude Opus 4.6 --- RSA.pm | 9 +++++++++ t/format.t | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/RSA.pm b/RSA.pm index 4ce4b3b..838cb02 100644 --- a/RSA.pm +++ b/RSA.pm @@ -50,6 +50,8 @@ sub get_key_parameters { return map { $_ ? Crypt::OpenSSL::Bignum->bless_pointer($_) : undef } shift->_get_key_parameters(); } +*get_public_key_pkcs1_string = \&get_public_key_string; + 1; __END__ @@ -197,6 +199,13 @@ header and footer lines: -----BEGIN RSA PUBLIC KEY------ -----END RSA PUBLIC KEY------ +=item get_public_key_pkcs1_string + +Alias for C. Returns the same PKCS#1 +C PEM format (C). Provided for +naming symmetry with the import method C (which +auto-detects PKCS#1 vs X.509) and with C. + =item get_public_key_x509_string Return the Base64/DER-encoded representation of the "subject diff --git a/t/format.t b/t/format.t index 5dc6825..0f4f516 100644 --- a/t/format.t +++ b/t/format.t @@ -3,7 +3,7 @@ use Test::More; use Crypt::OpenSSL::RSA; -BEGIN { plan tests => 35 } +BEGIN { plan tests => 39 } my $PRIVATE_KEY_STRING = <new_public_key($PUBLIC_KEY_X509_STRING), is( $public_key->get_public_key_string(), $PUBLIC_KEY_PKCS1_STRING, "X509 key exports to PKCS1 correctly" ); is( $public_key->get_public_key_x509_string(), $PUBLIC_KEY_X509_STRING, "X509 public key round-trips" ); +# get_public_key_pkcs1_string is an alias for get_public_key_string +is( $private_key->get_public_key_pkcs1_string(), $PUBLIC_KEY_PKCS1_STRING, "get_public_key_pkcs1_string returns PKCS1 from private key" ); +is( $public_key->get_public_key_pkcs1_string(), $PUBLIC_KEY_PKCS1_STRING, "get_public_key_pkcs1_string returns PKCS1 from public key" ); +is( $private_key->get_public_key_pkcs1_string(), $private_key->get_public_key_string(), "pkcs1 alias matches get_public_key_string on private key" ); +ok( $public_key = Crypt::OpenSSL::RSA->new_public_key($private_key->get_public_key_pkcs1_string()), "new_public_key accepts output of get_public_key_pkcs1_string" ); + my $passphase = '123456'; ok( $private_key = Crypt::OpenSSL::RSA->new_private_key( $ENCRYPT_PRIVATE_KEY_STRING, $passphase ), "load encrypted private key" ); is( $private_key->get_private_key_string(), $DECRYPT_PRIVATE_KEY_STRING, "encrypted key decrypts to expected private key" );