Open
Conversation
`SASL::ScramAlgorithm` and `SASL::ScramAuthenticator` use `salted_password` _at least_ twice: once to compute `client_key` and once to compute `server_key`. It is actually used more than that, since `client_key` and `server_key` are also used multiple times each. Computing `salted_password` is _intentionally_ computationally expensive, so it should be cached. Although `client_key` and `server_key` are far less computationally expensive, they _are_ used multiple times, so they are memoized too. Ultimately, we _could_ memoize most of the methods in `ScramAlgorithm`, but I've decided to keep it simple by only memoizing these three.
Adds `SASL::ScramCache`, a `SASL::ScramAuthenticator#cache` attr, and a `cache` keyword parameter to `SASL::ScramAuthenticator#initialize`. This avoids expensive re-hashing that was done during a single authentication exchange, but can also be re-used across multiple authentication exchanges.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds
SASL::ScramCache, aSASL::ScramAuthenticator#cacheattr, and acachekeyword parameter toSASL::ScramAuthenticator#initialize.This avoids expensive re-hashing that was done during a single authentication exchange. It can also be re-used across multiple authentication exchanges.
When the
cachekwarg contains the client and server keys (or the salted password),passwordis optional. But authentication will fail ifsaltoriterationschange andpasswordhasn't been provided.