Skip to content

fix(security): port the RNG onto the rand 0.10 API - #138

Merged
InstaZDLL merged 1 commit into
mainfrom
fix/rand-0.10-api
Aug 24, 2026
Merged

fix(security): port the RNG onto the rand 0.10 API#138
InstaZDLL merged 1 commit into
mainfrom
fix/rand-0.10-api

Conversation

@InstaZDLL

@InstaZDLL InstaZDLL commented Aug 24, 2026

Copy link
Copy Markdown
Owner

main does not compile. It has not since #133 merged, six hours before
#137 landed on top of it.

error[E0432]: unresolved imports `rand::rngs::OsRng`, `rand::RngCore`
  --> src/security.rs:14:12

rand 0.10 renamed OsRng to SysRng and dropped RngCore from the root.
src/security.rs is the crate's only user of either.

Commit CI (Rust)
7168b3b — before the bump success
2bddbdd — the rand bump failure
0e6b80a — the module split failure

The split's own branch was green: it forked from 869c881, before the bump,
and was never rebased. A green PR and a red base merged into a red main.

The change

SysRng is fallible where OsRng panicked internally. The three callers that
already return Result<_, SecurityError> — the instance key, the AEAD nonce and
the Argon2 salt — now report a new SecurityError::Random instead of aborting
the process. generate_token keeps its infallible signature, and therefore the
panic it already had; a system CSPRNG that will not answer leaves nothing to
retry, and drawing a token from anything else would be worse than drawing none.

SysRng rather than the infallible ThreadRng, which would have been a smaller
diff: the original asked the operating system directly, and an instance key that
outlives every other secret is the last place to start going through a userspace
buffer instead.

Gates

cargo fmt --all --check, cargo clippy --all-targets --all-features -D warnings,
42 unit and 46 integration tests — all green, which is more than main can say.

Summary by CodeRabbit

  • Améliorations
    • Renforcement de la génération aléatoire utilisée pour les clés, nonces et sels de mots de passe.
    • Les échecs de génération aléatoire sont désormais signalés explicitement par une erreur de sécurité.
    • La génération de jetons gère explicitement les défaillances critiques du générateur aléatoire système.

`main` has not compiled since #133 bumped rand from 0.8.7 to 0.10.2:
`rand::rngs::OsRng` and `rand::RngCore` no longer exist under those
names, and `src/security.rs` is the crate's only user of either. CI has
been red on every commit since 2bddbdd; the split merged on top of it
because its branch predated the bump and was never rebased.

`OsRng` is now `SysRng`, and it is fallible where the old one panicked on
its own. The three callers whose signature already returns
`Result<_, SecurityError>` — the instance key, the AEAD nonce and the
Argon2 salt — report it as the new `SecurityError::Random`.
`generate_token` keeps its infallible shape and therefore its panic,
which is what the previous version did anyway: a system CSPRNG that
refuses to answer leaves nothing to fall back on, and a token drawn from
anything else would be worse than no token.

`SysRng` rather than the infallible `ThreadRng`: the original asked for
the operating system directly, and a long-lived instance key is the last
place to start routing through a userspace buffer instead.

fmt, clippy and 42 unit + 46 integration tests pass.

Signed-off-by: InstaZDLL <github.105mh@8shield.net>
@github-actions github-actions Bot added type: fix Bug fix scope: server Server core (Rust) scope: auth Authentication, tokens, sessions size: s 10-50 lines and removed type: fix Bug fix labels Aug 24, 2026
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ad4e22bc-a368-4427-833a-44d305575b9a

📥 Commits

Reviewing files that changed from the base of the PR and between 0e6b80a and 690e79a.

📒 Files selected for processing (1)
  • src/security.rs

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

Le module src/security.rs remplace OsRng par SysRng. Il centralise le remplissage aléatoire dans fill_random, ajoute SecurityError::Random et adapte la propagation des erreurs pour les clés, les nonces, les sels et les jetons.

Changes

Aléa cryptographique

Layer / File(s) Summary
Contrat d’erreur et remplissage aléatoire
src/security.rs
SecurityError::Random représente l’échec du CSPRNG système. fill_random utilise SysRng::try_fill_bytes et convertit cet échec en erreur de sécurité.
Propagation vers les opérations de sécurité
src/security.rs
La génération de clés d’instance, de nonces et de sels propage l’erreur aléatoire. generate_token conserve une API infallible et panique explicitement en cas d’échec.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 690e7

This localized security update ports random-number generation to the rand 0.10 API and preserves the existing caller behavior while reporting failures where signatures allow it; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed Le titre décrit clairement la correction principale de l’intégration RNG avec rand 0.10.
Description check ✅ Passed La description présente le problème, les changements et les validations effectuées, malgré l’absence des rubriques exactes du modèle.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rand-0.10-api

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

@github-actions github-actions Bot added the type: fix Bug fix label Aug 24, 2026
@github-actions github-actions Bot removed the type: fix Bug fix label Aug 24, 2026
@InstaZDLL
InstaZDLL merged commit f995186 into main Aug 24, 2026
18 checks passed
@github-actions github-actions Bot added the type: fix Bug fix label Aug 24, 2026
@InstaZDLL
InstaZDLL deleted the fix/rand-0.10-api branch August 24, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: auth Authentication, tokens, sessions scope: server Server core (Rust) size: s 10-50 lines type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant