change Hash (and RawValue) hex-string representation to show the least-significant field element as big-endian hex string (#338)

* change Hash (and RawValue) hex-string representation to show the least-significant field element as big-endian hex string

The motivation is that since some commits ago, the hex representation
was changed from little-endian to big-endian, and when cropping the long
strings of hex (hex representation of byte-arrays), the small values
(224 bits or less) were being represented by `0x00000000...`, which is
indistinguishable from the `0` value.
This commit updates this cropped representation to print the last
characters of the string (the less signifcant bytes of the big-endian
representation), so that for example for the integer `5` the
representation would be `0x...00000005`.
This commit is contained in:
arnaucube 2025-07-14 15:27:58 +02:00 committed by GitHub
parent e8468d7fa8
commit 06b84e8dca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -236,13 +236,13 @@ impl fmt::Display for Hash {
if f.alternate() { if f.alternate() {
write!(f, "0x{}", self.encode_hex::<String>()) write!(f, "0x{}", self.encode_hex::<String>())
} else { } else {
// display first hex digit in big endian // display the least significant field element in big endian
write!(f, "0x")?; write!(f, "0x")?;
let v3 = self.0[3].to_canonical_u64(); let v0 = self.0[0].to_canonical_u64();
for i in 0..4 { for i in (0..4).rev() {
write!(f, "{:02x}", (v3 >> ((7 - i) * 8)) & 0xff)?; write!(f, "{:02x}", (v0 >> (i * 8)) & 0xff)?;
} }
write!(f, "") Ok(())
} }
} }
} }