Skip to content

fix: remove public param from rsa_crypt, extract check_max_message_length#167

Closed
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/implement-165
Closed

fix: remove public param from rsa_crypt, extract check_max_message_length#167
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/implement-165

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented Apr 6, 2026

Summary

Refactors rsa_crypt() to remove the now-unnecessary public parameter by extracting plaintext length pre-validation into a standalone check_max_message_length() static function called directly from encrypt() and private_encrypt(). Keeps OAEP overhead as the fixed SHA-1 value (size - 42) since this module never calls EVP_PKEY_CTX_set_rsa_oaep_md(). Also fixes a C89 declaration-after-statement violation in the pre-3.x code path.

Closes #165

Changes

  • Extract check_max_message_length() as a static function with correct SHA-1 OAEP overhead
  • Remove public parameter from rsa_crypt() signature and all call sites
  • Move pre-validation calls to encrypt() and private_encrypt() XS entry points
  • Fix C89 compliance: int size declared at function top, assigned in #else block

Test plan

  • Full test suite passes (630/630 subtests, only pre-existing z_kwalitee.t author test unrelated failure)
  • OAEP boundary tests in t/crypto.t and t/error.t continue to use correct size - 42 values
  • t/padding.t OAEP pad value remains 42 for all hash modes

Generated by Kōan /implement


Quality Report

Changes: 1 file changed, 44 insertions(+), 35 deletions(-)

Code scan: clean

Tests: failed (18 Failed, 1 test)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

…ngth

The `public` parameter in rsa_crypt() was only used to decide whether
to run plaintext length pre-validation. This refactor:

- Extracts pre-validation into a standalone check_max_message_length()
  static function, called directly from encrypt() and private_encrypt()
- Removes the now-unnecessary `public` parameter from rsa_crypt()
- Keeps OAEP overhead as the fixed SHA-1 value (size - 42) since this
  module never sets EVP_PKEY_CTX_set_rsa_oaep_md() — OpenSSL always
  uses SHA-1 for OAEP regardless of hashMode
- Fixes C89 compliance: moves `int size` declaration to function top
  and assigns in the #else block to avoid declaration-after-statement

Closes cpan-authors#165

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timlegge
Copy link
Copy Markdown
Member

timlegge commented Apr 6, 2026

Closing #165 is fixed

@timlegge timlegge closed this Apr 6, 2026
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.

2 participants