In my case the story continued for around 2 hours. Yesterday I was trying to implement something from a given SPEC, and tried to match my output (from Rust) with the output from the Python code written by Dr. Fett.
The problem
I had to get the JSON encoding from an ordered Array (in Python it is a simple list), say ["kushal", "das"]
, and get the base64urlencode(sha256sum(JSON_ENCODED_STRING))
in Rust using serde_json.
Easy, isn’t?
Let us see what the encoded string looks like:
"[\"6Ij7tM-a5iVPGboS5tmvVA\",\"John\"]"
And the final checksum is otcxXDbO4_xzK0DXL_DO2INIFXIJdO1PqVM-n_gt-3g
.
But, the reference implementation in Python has the checksum as fUMdn88aaoyKTHrvZd6AuLmPraGhPJ0zF5r_JhxCVZs
.
It took me a few hours to notice the space after comma in the JSON encoded string from Python:
"[\"6Ij7tM-a5iVPGboS5tmvVA\", \"John\"]"
This is due to the following line from JSON spec
Insignificant whitespace is allowed before or after any of the six structural characters.
Yes, I know I should have known better, and read the original spec properly. But, in this case I learned it in the hard way.