-
-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proto: Token encode refactors #2110
proto: Token encode refactors #2110
Conversation
649e8af
to
18b5a93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
For symmetry with encode.
This will be useful for NEW_TOKEN usage, as validation tokens will only include IP address and not port.
Prior to this commit, decoding a socket addr from a RetryToken called get_u8 and get_u16, which would have panicked if an encrypted token were minted that terminated after that point. This replaces them with calls that short-circuit, for consistency with other parts of the code there.
This will be useful for NEW_TOKEN usage, as it will make there be more than one call site for this.
ee17203
to
ec65aa5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The weird address
handling was leftover from of an old design where the address was AAD rather than explicitly stored. We migrated away from that because that made it impossible to distinguish invalid tokens from valid tokens with invalid addresses. Glad to see it tidied up.
Organizes encoding payload section versus encrypting section.
Prior to this commit, a RetryToken encodes the client's address as if it were a field, but rather than it actually being a field, it's threaded in to encode, and validated in-place in decode. It's unclear to me why this is. This commit makes the remote address simply a field of the RetryToken struct.
As of the previous commit, RetryToken::decode fails only with the Unusable variant, and validation only occurs in IncomingToken::from_header, which uses InvalidRetryTokenError directly. This allows us to remove ValidationError altogether.
This probably won't affect much, but is slightly more defensive.
ec65aa5
to
560723d
Compare
Please see individual commit messages.
If "Make address a field of RetryToken" is too controversial, I can split it off into a subsequent PR to help the ones before it get through.