-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change HpkeError::Secp256k1 into the opaque InvalidPublicKey error #511
base: master
Are you sure you want to change the base?
Conversation
Making this into an opaque error will prevent leaking implementation details
1f06933
to
d5077ca
Compare
Pull Request Test Coverage Report for Build 12968934364Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cACK, but undecided about the details of From
impl
@@ -283,7 +283,7 @@ impl From<hpke::HpkeError> for HpkeError { | |||
} | |||
|
|||
impl From<secp256k1::Error> for HpkeError { | |||
fn from(value: secp256k1::Error) -> Self { Self::Secp256k1(value) } | |||
fn from(_: secp256k1::Error) -> Self { Self::InvalidPublicKey } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'd be more comfortable if this match
ed value
.
if InvalidPublicKey
is really only variant we do expect here, i'd also be happy with something that just asserts that value
is secp256k1::Error::InvalidPublicKey
before discarding it
afaict that is the case, because InvalidEllSwift
(the only other variant that seems plausibly relevant) would only be generated from a string encoding, but construct it directly from a fixed size array and i believe every 64 byte array can be interpreted as an EllSwift encoding
if someone objects to maintaining a introducing a panic I'd settle for a comment justifying ignoring the specific variant, and waiting a few years until oops i think that wouldn't actually work. anyway, just something to warn future maintainers in case secp256k1 crate gets more error variants that we should account fornever_patterns
experimental feature hits the project's MSRV ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only so many errors can actually occur at the Secp256k1
layer here. I think matching generally is probably fine. If you want it to be a general catch I'm also ok with naming the error Secp256k1
dropping the internal variant, and making a general statement in Display's implementation. I'd like more information @nothingmuch what other variants beyond InvalidEllSwift
could ever happen or where would discarding the inner var and catching all cause problems?
Maintaining a panic and match on the InvalidPublicKey variant is OK for me but I'm not sure it's strictly necessary.
A Secp256k1 => write!(f, "Secp256k1 key parsing failed),
seems just as suitable and incurs less maintenance burden (over the tiniest maintenance item ever anyhow)
edit: Listen to @nothingmuch. The changes he requested to match on errors or panic must be made to accept this PR
I don't even think |
oh and to spell out the specific scenario where I expect such a bug might arise:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm persuaded by @nothingmuch. The changes he requested to match on errors or panic must be made to accept this PR
Making this into an opaque error will prevent leaking implementation details
Closes #498