Skip to content

Commit

Permalink
Make serde encoding match new decoding rules
Browse files Browse the repository at this point in the history
  • Loading branch information
recmo committed Apr 19, 2023
1 parent 66ba42a commit e35abc8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/modular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ mod tests {
type U = Uint<BITS, LIMBS>;
// TODO: Increase cases when perf is better.
let mut config = Config::default();
// BUG: Proptest still runs 5 cases even if we set it to 1.
config.cases = min(config.cases, if BITS > 500 { 1 } else { 3 });
proptest!(config, |(a: U, b: U, c: U, m: U)| {
// TODO: a^(b+c) = a^b * a^c. Which requires carmichael fn.
Expand Down
2 changes: 2 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use thiserror::Error;

// FEATURE: Respect width parameter in formatters.

// TODO: Do we want to write `0` for `BITS == 0`.

impl<const BITS: usize, const LIMBS: usize> Display for Uint<BITS, LIMBS> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
// Base convert 19 digits at a time
Expand Down
4 changes: 4 additions & 0 deletions src/support/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ impl<const BITS: usize, const LIMBS: usize> Serialize for Uint<BITS, LIMBS> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let bytes = self.to_be_bytes_vec();
if serializer.is_human_readable() {
// Special case for zero, which encodes as `0x0`.
if BITS == 0 {
return serializer.serialize_str("0x0");
}
// OPT: Allocation free method.
let mut result = String::with_capacity(2 * Self::BYTES + 2);
result.push_str("0x");
Expand Down

0 comments on commit e35abc8

Please sign in to comment.