Skip to content

test: expand key_lifecycle.t with parameter derivation coverage#113

Merged
atoomic merged 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/test-new-key-params-coverage
Mar 18, 2026
Merged

test: expand key_lifecycle.t with parameter derivation coverage#113
atoomic merged 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/test-new-key-params-coverage

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

What

Add 22 tests covering previously untested _new_key_from_parameters() code paths.

Why

The parameter derivation branches (derive q from n/p, derive p from n/q, derive d from p/q) and the n/e/d-only private key path had zero test coverage. These paths include BN_CTX allocation, BN_div, and BN_mod_inverse operations that should be verified.

New test cases

  • Derive q from n/p: passes n, e, d, p — q computed via BN_div
  • Derive p from n/q: passes n, e, d, undef, q — p computed via BN_div
  • Derive d from p/q: passes n, e, undef, p, q — d computed via BN_mod_inverse
  • n/e/d only (no CRT params): exercises the else branch in _new_key_from_parameters()
  • Cross-derived key interop: encrypt/decrypt and sign/verify between keys constructed from different parameter subsets
  • Error case: missing n and e triggers expected croak

Also fixes test plan: skip() reports skipped tests which count toward the total, so the plan must be 45 regardless of Bignum availability.

Testing

All 266 tests pass on macOS with OpenSSL 3.6.1. Bignum SKIP block ensures graceful degradation when Crypt::OpenSSL::Bignum is not installed.

🤖 Generated with Claude Code

Add 22 tests for previously untested _new_key_from_parameters() paths:
- Derive q from n/p (BN_div branch)
- Derive p from n/q (BN_div branch)
- Derive d from p/q (BN_mod_inverse branch)
- Private key from n/e/d only (no CRT params — else branch)
- Cross-derived key interop (encrypt/decrypt, sign/verify)
- Error case: missing n and e

Also fixes test plan: skip() reports skipped tests which count toward
the total, so plan must always include all tests (9+14+20+2=45).
Copy link
Copy Markdown
Member

@timlegge timlegge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine approved - tested fine against 0.37 as well

@atoomic atoomic marked this pull request as ready for review March 18, 2026 00:26
@atoomic atoomic merged commit 892eede into cpan-authors:main Mar 18, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants