Enhancement - Standardize Error Returns for Failure Paths#483
Merged
Conversation
…nctions Co-authored-by: porfanid <19299306+porfanid@users.noreply.github.com>
…tialize Co-authored-by: porfanid <19299306+porfanid@users.noreply.github.com>
Donnie-Ice
approved these changes
Jul 28, 2025
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #483 +/- ##
==========================================
- Coverage 82.00% 81.50% -0.50%
==========================================
Files 39 39
Lines 11945 12174 +229
Branches 973 1044 +71
==========================================
+ Hits 9795 9923 +128
- Misses 1778 1847 +69
- Partials 372 404 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
All Submissions:
New Feature Submissions:
Changes to Core Features:
Explanation of Changes
This pull request addresses inconsistent error handling across the CryptoLib codebase by standardizing functions to return
int32_twith proper CRYPTO_LIB_* error codes instead ofvoidor inconsistent return types.Problem Addressed:
Several functions in the codebase that could encounter errors (memory allocation failures, parameter validation, etc.) were returning
voidor not properly checking/propagating errors from sub-functions, making debugging and error handling more challenging.Changes Made:
Core Configuration Functions (
src/core/crypto_config.c):crypto_deep_copy_string(): Changed from returningchar*toint32_twith output parameter patternCrypto_Local_Config(): Changed fromvoidtoint32_tCrypto_Local_Init(): Changed fromvoidtoint32_tCrypto_Calc_CRC_Init_Table(): Changed fromvoidtoint32_tkey_if->key_init()andmc_if->mc_initialize()callsSecurity Association Functions (
src/sa/internal/sa_interface_inmemory.template.c):update_sa_from_ptr(): Changed fromvoidtoint32_twith parameter validationsa_populate(): Changed fromvoidtoint32_twith error propagationHeader Updates (
include/crypto.h):int32_treturn typescrypto_deep_copy_string()signature to use output parameter patternError Handling Improvements:
Why Include These Changes:
How do you test these changes?
Testing Approach:
CRYPTO_LIB_ERR_NULL_BUFFER)CRYPTO_LIB_ERROR)CRYPTO_LIB_ERR_SPI_INDEX_OOB)Example Test Cases:
The changes significantly improve the robustness and debuggability of CryptoLib's error handling while maintaining full backward compatibility.
Solves #482