-
Notifications
You must be signed in to change notification settings - Fork 87
fix: Remove the MPI constructor which may be misused #410
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
Conversation
src/types/mpi.rs
Outdated
| } | ||
| } | ||
|
|
||
| impl From<&[u8]> for Mpi { |
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 wonder if we should remove this entirely and force direct calls instead
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.
also this is problematic, as this now behaves differently to From<Vec<u8>> as well as the From variants for MpiRef
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 think it's a good idea to remove both Froms since it's not a simple conversion.
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.
Removing all From implementations sounds potentially right to me. We could try out how that would look, in this PR.
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.
Maybe all is a bit too much since there are many (e.g. for BigUint). The other approach would be having from_slice but inside stripping leading zeros (basically renaming from_raw_slice to from_slice).
aad6906 to
d49807a
Compare
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.
this is a good start, we can always remove/change more in follow ups
I'm wondering about two further changes here:
The docs of both If that doesn't sound like a good idea I'd propose alternative design: documenting that |
I like the idea to make the Alternatively: keeping unchecked constructors around, but giving them scarier names, possibly limiting their visibility in the API, and documenting what expectations these put on the caller sounds acceptable to me as well. (I'm not super worried about the performance of always checking, but we could compare benchmark results of always checking in all |
This patch adjusts the MPI constructors to always strip leading zeros so that they are always valid after construction. Fixes: rpgp#401 Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
d49807a to
d4102cc
Compare
Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
This patch removes the MPI constructor which may be used to construct invalid MPIs. It also adjusts the
From<u8>implementation to use a safe variant.@hko-s please see if this is what we discussed. Thanks!
Fixes: #401