I have a JSON object:
{"content":{"foo":1,"bar":2},"signature":"3f5ab1..."}
Deserialising this into a custom type already works fine, using:
let s: SignedContent = serde_json::from_str(string)?;
What I want is {"foo":1,"bar":2} as a &[u8] slice, so that I can check the signature.
(I am aware of the issues around canonical JSON representations, and have mitigations in place.)
Currently I am wastefully re-serialising the Content object (within the SignedContent object) into a string and getting the octets from that.
Is there a more efficient way?
Looks like a job for
serde_json::value::RawValue(which is available with the "raw_value" feature).With usage being:
You can then use
content.get()to get the raw&str.