Add a random token generator fn#27
Open
uniphil wants to merge 2 commits into
Open
Conversation
The existing code manually builds up tokens in a couple places, with some casts and indexing in the process. This change extracts token generation from an alphabet to a helper function, updates the types to avoid casting, and refactors it to use `choose_multiple` from rand0.8's `SliceRandom` to avoid direct indexing. Ultimately it's only a bit more than a cosmetic change, so feel free to close/reject if you prefer keeping a flatter style with fewer helper functions. --- Note that `rand 0.9` has been out since January and it might be worth updating. From uses I've spotted, AIP is only affected by names changing in 0.9 (like `rand::thread_rng()` becomes just `rand::rng()`), so it's pretty mechanical to update. I'd be happy to follow up with that if you want!
Contributor
|
Thanks for the PR. I think that function should probably go away in favor of the atproto_oauth::pkce::generate() method. That said, I'm using "0.8" in atproto-identity-rs. If you're interested, I'd happily accept a PR there to bump to "0.9". |
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.
The existing code in the
simple-websiteexample manually builds up tokens in a couple places, with a type cast and indexing in the process.This change extracts token generation to a helper function, updates the types to avoid casting, and refactors it to use
choose_multiplefrom rand0.8'sSliceRandomto avoid direct indexing.Ultimately it's only a bit more than a cosmetic change, so feel free to close/reject if you prefer keeping a flatter style with fewer helper functions.
Note that
rand 0.9has been out since January and it might be worth updating. From uses I've spotted, AIP is only affected by names changing (likerand::thread_rng()becomes justrand::rng()), so it's pretty mechanical to update. I'd be happy to follow up with that if you want!