refactor: Tokenserver: Rewrite inlined Python code in Rust #1053
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Replaces the inlined Python code with native Rust code. I replaced all of the Python functions with equivalent Rust functions, except for
tokenlib#make_token
andtokenlib#get_derived_secret
, which I added Rust wrappers for.Testing
I tested this by running the Python and Rust versions with the same input data and ensuring that the output was the same.
Python test file: https://gist.github.com/ethowitz/7d6b3590f4aae0c51b2df71297c1d303
Rust test code (I added this to syncstorage-rs's main function for expediency): https://gist.github.com/ethowitz/2ec06b230b2db66de6088ac30a8c9819
Python output:
Rust output:
As you can see, the tokens and derived secrets differ, but these values differ across runs of the same version (e.g. when running the Python version twice, the values differ across the runs). I assume the tokenlib library adds nondeterminism (e.g. a nonce) so the values are different each time.
Issue(s)
Closes #1049