crypto: return clear errors when loading invalid PFX data #49566
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.
This fixes #49562
Without this change, the provided test fails with 'passed a null parameter', telling you nothing about what's actually wrong (since no nulls are present in this test code).
With this change, the test correctly receives a 'Unable to load private key from PFX data' error, telling you exactly what's wrong.
I've also covered the
cert
case here. I have confirmed that the same 'null parameter' error would be unhelpfully thrown ifcert
was null, so I think that's similarly useful. I'm not sure how to actually produce a pfx that would trigger this, so I haven't included a test, and it's possible that this isn't a possible condition (i.e. maybePKCS12_parse
would fail in that case) but it seems likely that it's technically possible and worth covering, and it's very easy to do so.