Skip to content
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

Add support for Binary and Decimal encodings #246

Closed

Conversation

andrewwhitehead
Copy link
Contributor

@andrewwhitehead andrewwhitehead commented Jun 1, 2023

Decimal serialization (outside of write_decimal_bytes_vartime) is currently only supported when the alloc flag is enabled, as the encoded length is potentially unbounded for Uint<L> and digits are produced in reverse. In practice anything up to U8192 can be encoded without allocating. Note that unlike the other encodings, decimal encoding is not constant-time.

Unresolved questions:

  • Add a trait for encoding numbers as decimal, to match FromDecimal? This is a bit tricky as it would require the alloc feature (or gain additional methods when the feature is enabled).
  • Implement Error for ParseDecimalError? This would require a std flag.
  • Add an error type for encoding errors?

@tarcieri
Copy link
Member

tarcieri commented Aug 7, 2023

Sorry for taking awhile to review this. The implementation is somewhat complex which makes it difficult, but I also have some initial thoughts.

The existing support for hex encoding is implemented in a constant-timeish manner, avoiding branches on the inputs in favor of arithmetic operations.

This implementation appears to branch on the input in several places. That's okay, but the corresponding functions should be marked as *_vartime to reflect that, per this crate's constant-time-by-default policy.

Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
@tarcieri
Copy link
Member

tarcieri commented May 7, 2024

Closing as stale

@tarcieri tarcieri closed this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants