Skip to content

Add support for Binary and Decimal encodings#246

Closed
andrewwhitehead wants to merge 6 commits into
RustCrypto:masterfrom
andrewwhitehead:feat/decimal
Closed

Add support for Binary and Decimal encodings#246
andrewwhitehead wants to merge 6 commits into
RustCrypto:masterfrom
andrewwhitehead:feat/decimal

Conversation

@andrewwhitehead

@andrewwhitehead andrewwhitehead commented Jun 1, 2023

Copy link
Copy Markdown
Contributor

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

tarcieri commented Aug 7, 2023

Copy link
Copy Markdown
Member

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

tarcieri commented May 7, 2024

Copy link
Copy Markdown
Member

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