fix(security): port the RNG onto the rand 0.10 API - #138
Conversation
`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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
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. 📝 WalkthroughWalkthroughLe module ChangesAléa cryptographique
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to 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)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
maindoes not compile. It has not since #133 merged, six hours before#137 landed on top of it.
rand0.10 renamedOsRngtoSysRngand droppedRngCorefrom the root.src/security.rsis the crate's only user of either.7168b3b— before the bump2bddbdd— the rand bump0e6b80a— the module splitThe 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
SysRngis fallible whereOsRngpanicked internally. The three callers thatalready return
Result<_, SecurityError>— the instance key, the AEAD nonce andthe Argon2 salt — now report a new
SecurityError::Randominstead of abortingthe process.
generate_tokenkeeps its infallible signature, and therefore thepanic 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.
SysRngrather than the infallibleThreadRng, which would have been a smallerdiff: 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
maincan say.Summary by CodeRabbit