Closed seanchen1991 closed 1 month ago
Note that the current manually derived Serialize
instance for CommitmentPrefix
is also incorrectly implemented. It uses the Debug
instance of CommitmentPrefix
, but the Debug
implementation serializes a commitment prefix with invalid UTF-8 as "<not valid UTF8: {:?}>"
.
impl fmt::Debug for CommitmentPrefix {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let converted = core::str::from_utf8(self.as_bytes());
match converted {
Ok(s) => write!(f, "{s}"),
Err(_e) => write!(f, "<not valid UTF8: {:?}>", self.as_bytes()),
}
}
}
For safe and correct serialization, we should revert the behavior and serialize it as bytes, not string.
Feature Summary
Raised by @soareschen:
[cfg(feature = "serde")]
impl serde::Serialize for CommitmentPrefix { fn serialize
(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer, { format!("{self:?}").serialize(serializer) } }