-
Notifications
You must be signed in to change notification settings - Fork 76
Implement from_str_radix_vartime for Uint, BoxedUint
#603
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
Implement from_str_radix_vartime for Uint, BoxedUint
#603
Conversation
Signed-off-by: Andrew Whitehead <[email protected]>
Signed-off-by: Andrew Whitehead <[email protected]>
|
Is this already fully working or still a WIP? |
|
It's fully working. I have encoding done too (to_string_radix_vartime), but I didn't want to submit too many changes at once. |
|
That will be a must, was about to start working on a solution for it locally but it's great to know this is being added 🙏🏻 |
|
When do you estimate both from and to methods will be available? |
|
@ndavd I have a lot on my plate right now and higher priority issues to work on, even in this crate. It will also be going into a prerelease, and we likely won't have a final release out for several months. |
| /// Possible errors in variable-time integer decoding methods. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub enum DecodeError { | ||
| /// The input value was empty. | ||
| Empty, | ||
|
|
||
| /// The input was not consistent with the format restrictions. | ||
| InvalidDigit, | ||
|
|
||
| /// Input size is too small to fit in the given precision. | ||
| InputSize, | ||
|
|
||
| /// The deserialized number is larger than the given precision. | ||
| Precision, | ||
| } | ||
|
|
||
| impl fmt::Display for DecodeError { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| Self::Empty => write!(f, "empty value provided"), | ||
| Self::InvalidDigit => { | ||
| write!(f, "invalid digit character") | ||
| } | ||
| Self::InputSize => write!(f, "input size is too small to fit in the given precision"), | ||
| Self::Precision => write!( | ||
| f, | ||
| "the deserialized number is larger than the given precision" | ||
| ), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| impl std::error::Error for DecodeError {} |
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.
Seems like an odd place for this. Perhaps we should extract an errors.rs. But I'll save that for another PR.
from_str_radix_vartime for Uint, BoxedUint
This adds fallible parsing for binary, decimal, and hex integers (and any base from 2 to 36).
The format of these numbers generally matches the
from_str_radixmethods of the standard library. One exception is that underscores may used as spacers, as in+1_000_000for example. This is consistent with thenum_bigintcrate.The
DecodeErrorenum is promoted from the uint.boxed module and reused.