-
Notifications
You must be signed in to change notification settings - Fork 60
More convenience methods for boxed integer resizing #809
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
@tarcieri any comments on that? The other inconvenience in RustCrypto/RSA#506 is that the constant-time division requires both arguments to be the same size, but the variable time division has no such restriction. I'm looking into that, will be in another PR. |
I think "resize" is fine over "resized".
Why not just have the trait borrow
Maybe mark them as deprecated and we can try to migrate to
Can start with that, sure
This seems fine at first glance although I'd be curious if there might be some issues that pop up on 32-bit with this that don't on 64-bit |
To save on allocations when the new length happens to be the same as the old one, or in some cases when it's smaller (depends on the allocator). |
That would actually make the behavior more uniform across platforms. Imagine you have a 100-bit integer and you call |
An alternative |
This PR attempts to simplify some scenarios that were encountered during the work on RustCrypto/RSA#506.
BoxedUint::shorten()
/widen()
methods, introduce theResize
trait with more convenience methods. Implemented forBoxedUint
,NonZero<BoxedUint>
,Odd<BoxedUint>
, and their references.BoxedUint::shorten()
andwiden()
are marked as deprecated.Note that
try_resize
fails ifself.bits() > at_least_bits_precision
, unlike the more relaxedshorten()
behavior.