Skip to content

refactor(rng): move seed and helper crates to rand 0.10#244

Merged
EffortlessSteven merged 3 commits into
mainfrom
rng-dual-stack
Mar 13, 2026
Merged

refactor(rng): move seed and helper crates to rand 0.10#244
EffortlessSteven merged 3 commits into
mainfrom
rng-dual-stack

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

This is PR 2 in the RNG upgrade lane, stacked on top of #243.

It moves the seed/core/helper layer to the current RNG line while leaving the stable crypto-edge crates on the legacy line that upstream still requires.

What changed

  • add explicit workspace aliases for both RNG lines:
    • legacy: rand 0.8 / rand_core 0.6 / rand_chacha 0.3
    • current: rand10 0.10 / rand_core10 0.10 / rand_chacha10 0.10
  • migrate these crates to the 0.10 line:
    • uselesskey-core-factory
    • uselesskey-core-seed
    • uselesskey-core-base62
    • uselesskey-core-token-shape
    • uselesskey-core-x509-derive
    • uselesskey-hmac
  • update local RNG usage for the rand 0.10 API shape:
    • OsRng -> rand10::rngs::SysRng
    • RngCore -> rand_core10::Rng
    • test doubles updated to TryRng
  • remove now-unused legacy rand dev-deps from uselesskey-core, uselesskey-core-token, and uselesskey-core-x509

Why this split

Stable upstream crypto crates still pin the legacy RNG ABI:

  • rsa 0.9.10
  • ed25519-dalek 2.2.0
  • the stable p256 / p384 / elliptic-curve 0.13 line
  • pgp 0.19.0

So this PR does not try to force full convergence. It moves the parts of the workspace where RNG is an implementation detail, and leaves the crypto-edge island explicit for a follow-up.

Remaining legacy island after this PR

  • uselesskey-rsa
  • uselesskey-ed25519 (transitively constrained)
  • uselesskey-ecdsa
  • uselesskey-pgp
  • uselesskey-x509
  • proptest dev-deps still bring a separate rand 0.9 test-only line

Testing

  • cargo test -p uselesskey-core-seed -p uselesskey-core-factory -p uselesskey-core-base62 -p uselesskey-core-token-shape -p uselesskey-core-x509-derive -p uselesskey-hmac --no-run
  • cargo test -p uselesskey-core-seed -p uselesskey-core-factory -p uselesskey-core-base62 -p uselesskey-core-token-shape -p uselesskey-core-x509-derive -p uselesskey-hmac
  • cargo test -p uselesskey-core -p uselesskey-core-token -p uselesskey-core-x509
  • cargo xtask gate

Follow-up

A separate follow-up PR can migrate local/test-only legacy users such as uselesskey-rustcrypto, uselesskey-bdd-steps, and the fuzz crate without waiting on upstream crypto releases.

@coderabbitai

coderabbitai Bot commented Mar 13, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9992029a-1fda-4f76-a544-7b78b24039e8

📥 Commits

Reviewing files that changed from the base of the PR and between 1243fba and 88cae74.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • fuzz/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (22)
  • Cargo.toml
  • crates/uselesskey-core-base62/Cargo.toml
  • crates/uselesskey-core-base62/src/lib.rs
  • crates/uselesskey-core-factory/Cargo.toml
  • crates/uselesskey-core-factory/src/lib.rs
  • crates/uselesskey-core-seed/Cargo.toml
  • crates/uselesskey-core-seed/src/lib.rs
  • crates/uselesskey-core-token-shape/Cargo.toml
  • crates/uselesskey-core-token-shape/src/lib.rs
  • crates/uselesskey-core-token/Cargo.toml
  • crates/uselesskey-core-x509-derive/Cargo.toml
  • crates/uselesskey-core-x509-derive/src/lib.rs
  • crates/uselesskey-core-x509/Cargo.toml
  • crates/uselesskey-core/Cargo.toml
  • crates/uselesskey-hmac/Cargo.toml
  • crates/uselesskey-hmac/src/secret.rs
  • crates/uselesskey/tests/dep_guard_policy.rs
  • fuzz/fuzz_targets/core_factory_cache.rs
  • fuzz/fuzz_targets/core_token_shape.rs
  • fuzz/fuzz_targets/fuzz_token_shape.rs
  • fuzz/fuzz_targets/token_shape.rs
  • xtask/src/main.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rng-dual-stack
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request initiates a strategic upgrade of the project's random number generation infrastructure. It introduces a dual-version approach for the rand crate, allowing internal seed and helper components to leverage the newer rand 0.10 API while maintaining compatibility with stable external cryptographic libraries that are still dependent on the rand 0.8 line. This phased modernization ensures that core utilities benefit from the latest RNG features without disrupting critical, externally constrained dependencies.

Highlights

  • RNG Version Management: Introduced explicit workspace aliases for both the legacy rand 0.8 and the current rand 0.10 RNG lines, enabling dual-version support within the repository.
  • Crate Migration: Migrated several core utility crates, including uselesskey-core-factory, uselesskey-core-seed, uselesskey-core-base62, uselesskey-core-token-shape, uselesskey-core-x509-derive, and uselesskey-hmac, to utilize the rand 0.10 ecosystem.
  • API Modernization: Updated local RNG usage within the migrated crates to align with the rand 0.10 API, specifically transitioning OsRng to rand10::rngs::SysRng, rand_core::RngCore to rand_core10::Rng, and adapting test doubles to TryRng.
  • Dependency Cleanup: Removed now-unused legacy rand development dependencies from uselesskey-core, uselesskey-core-token, and uselesskey-core-x509.
Changelog
  • Cargo.lock
    • Added rand_core 0.10.0 as a dependency.
    • Added rand 0.10.0 package entry.
    • Added rand_chacha 0.10.0 package entry.
    • Added rand_core 0.10.0 package entry.
    • Removed rand_core 0.6.4 from uselesskey-core dev-dependencies.
    • Updated rand_chacha and rand_core versions for uselesskey-core-base62 to 0.10.0.
    • Updated rand version for uselesskey-core-factory to 0.10.0.
    • Updated rand_chacha and rand_core versions for uselesskey-core-seed to 0.10.0.
    • Removed rand_chacha 0.3.1 and rand_core 0.6.4 from uselesskey-core-token-shape dev-dependencies.
    • Updated rand_chacha and rand_core versions for uselesskey-core-token-shape to 0.10.0.
    • Removed rand_chacha 0.3.1 and rand_core 0.6.4 from uselesskey-core-token dev-dependencies.
    • Updated rand_chacha and rand_core versions for uselesskey-core-x509-derive to 0.10.0.
    • Removed rand_chacha 0.3.1 and rand_core 0.6.4 from uselesskey-core-x509 dev-dependencies.
    • Updated rand_chacha and rand_core versions for uselesskey-hmac to 0.10.0.
  • Cargo.toml
    • Updated comments for RNG dependencies.
    • Added rand10, rand_core10, and rand_chacha10 aliases for rand 0.10.0 versions.
  • crates/uselesskey-core-base62/Cargo.toml
    • Updated rand_chacha and rand_core dependencies to use rand_chacha10 and rand_core10 workspace aliases.
  • crates/uselesskey-core-base62/src/lib.rs
    • Updated use statements to import ChaCha20Rng from rand_chacha10 and Rng, SeedableRng from rand_core10.
    • Changed RngCore trait bound to Rng in random_base62_with_rng function signature.
    • Updated test imports to use rand_chacha10 and rand_core10 and introduced Infallible, TryRng.
    • Refactored ConstantRng and AllMaxRng test structs to implement TryRng instead of RngCore, adapting to the new API.
  • crates/uselesskey-core-factory/Cargo.toml
    • Updated rand_core dependency to rand10 and configured std features for rand10/std and rand10/sys_rng.
  • crates/uselesskey-core-factory/src/lib.rs
    • Updated use statements to import TryRng from rand10 and SysRng from rand10::rngs.
    • Replaced OsRng.fill_bytes with SysRng.try_fill_bytes().expect(...) for random seed generation.
  • crates/uselesskey-core-seed/Cargo.toml
    • Updated rand_chacha and rand_core dependencies to use rand_chacha10 and rand_core10 workspace aliases and adjusted std feature flags.
  • crates/uselesskey-core-seed/src/lib.rs
    • Updated use statements to import ChaCha20Rng from rand_chacha10 and Rng, SeedableRng from rand_core10.
  • crates/uselesskey-core-token-shape/Cargo.toml
    • Updated rand_chacha and rand_core dependencies to use the new rand_chacha10 and rand_core10 workspace aliases.
  • crates/uselesskey-core-token-shape/src/lib.rs
    • Updated use statements to import ChaCha20Rng from rand_chacha10 and Rng, SeedableRng from rand_core10.
  • crates/uselesskey-core-token/Cargo.toml
    • Removed legacy rand_chacha and rand_core development dependencies.
  • crates/uselesskey-core-x509-derive/Cargo.toml
    • Updated rand_chacha and rand_core dependencies to use the new rand_chacha10 and rand_core10 workspace aliases.
  • crates/uselesskey-core-x509-derive/src/lib.rs
    • Updated use statements to import ChaCha20Rng from rand_chacha10 and Rng, SeedableRng from rand_core10.
    • Changed RngCore trait bound to Rng in deterministic_serial_number_with_rng function signature.
  • crates/uselesskey-core-x509/Cargo.toml
    • Removed legacy rand_chacha and rand_core development dependencies.
  • crates/uselesskey-core/Cargo.toml
    • Removed legacy rand_core development dependency.
  • crates/uselesskey-hmac/Cargo.toml
    • Updated rand_chacha and rand_core dependencies to use the new rand_chacha10 and rand_core10 workspace aliases.
  • crates/uselesskey-hmac/src/secret.rs
    • Updated use statements to import ChaCha20Rng from rand_chacha10 and Rng, SeedableRng from rand_core10.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a well-executed refactoring to upgrade several crates to use rand version 0.10, while maintaining compatibility with legacy crates that depend on rand 0.8. The use of workspace aliases to manage the two different rand versions is a clean solution. The code changes correctly adapt to the new rand 0.10 API, including updating test utilities to use TryRng. I've found one minor opportunity for improvement by removing a duplicated test helper, but overall the changes are solid.

Comment on lines 87 to +110
struct ConstantRng;

impl RngCore for ConstantRng {
fn next_u32(&mut self) -> u32 {
u32::from_le_bytes([255, 255, 255, 255])
}
impl TryRng for ConstantRng {
type Error = Infallible;

fn next_u64(&mut self) -> u64 {
u64::from_le_bytes([255, 255, 255, 255, 255, 255, 255, 255])
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
Ok(u32::from_le_bytes([255, 255, 255, 255]))
}

fn fill_bytes(&mut self, dest: &mut [u8]) {
dest.fill(255);
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
Ok(u64::from_le_bytes([255, 255, 255, 255, 255, 255, 255, 255]))
}

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
self.fill_bytes(dest);
Ok(())
}
}

impl ConstantRng {
fn fill_bytes(&mut self, dest: &mut [u8]) {
dest.fill(255);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This ConstantRng test utility is functionally identical to AllMaxRng defined below. Both produce a stream of 0xFF bytes and return u32::MAX and u64::MAX for try_next_u32 and try_next_u64 respectively.

To reduce code duplication, you can remove ConstantRng and its implementations, and use AllMaxRng in the fallback_path_terminates_for_constant_rng test instead.

@EffortlessSteven EffortlessSteven changed the base branch from rng-boundary-refactor to main March 13, 2026 05:04
@EffortlessSteven EffortlessSteven merged commit 82f763c into main Mar 13, 2026
4 checks passed
@EffortlessSteven EffortlessSteven deleted the rng-dual-stack branch March 13, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant