ES256: return errors instead of panicking on invalid byte conversions#3722
Open
ES256: return errors instead of panicking on invalid byte conversions#3722
Conversation
Replace the `From<[u8; N]>` / `From<&[u8; N]>` impls on `ES256PublicKey` and `ES256Signature` with `TryFrom`, matching the existing `Commitment` precedent in the multisig module. The previous impls called `from_bytes(...).expect(...)`, which panics on inputs that `p256` rejects (invalid SEC1 tag byte for the public key; zero or out-of-range `r`/`s` scalars for the signature). No current call site feeds untrusted bytes through these impls, but the `TryFrom` form removes the footgun. Also remove the `Default` impl on `ES256Signature`: it attempted to construct a signature from all-zero bytes, which `p256` rejects (panicking with a misleading "Invalid slice length" message). The impl had no callers.
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.
Replace the
From<[u8; N]>/From<&[u8; N]>impls onES256PublicKeyandES256SignaturewithTryFrom, matching the existingCommitmentprecedent in the multisig module. The previous impls calledfrom_bytes(...).expect(...), which panics on inputs thatp256rejects (invalid SEC1 tag byte for the public key; zero or out-of-ranger/sscalars for the signature). No current call site feeds untrusted bytes through these impls, but theTryFromform removes the footgun.Also remove the
Defaultimpl onES256Signature: it attempted to construct a signature from all-zero bytes, whichp256rejects (panicking with a misleading "Invalid slice length" message). The impl had no callers.Pull request checklist
clippyandrustfmtwarnings.