Skip to content

Commit 24d6e1c

Browse files
hyperpolymathclaude
andcommitted
vext-email-gateway: migrate OsRng to rand 0.9 try_fill_bytes API
Closes the pre-existing rand_core 0.9 build break flagged in commit 0d11476's report (the .expect("TODO") sweep). 3 sites used the rand 0.8 fallible-via-RngCore pattern: use rand::RngCore; let mut rng = rand::rngs::OsRng; rng.fill_bytes(&mut sk); In rand 0.9 OsRng no longer implements `RngCore`; it implements `TryRngCore` instead (the fallible variant) since OS-level RNG calls can fail. Migrated to: use rand::TryRngCore; rng.try_fill_bytes(&mut sk) .expect("OsRng must succeed for cryptographic key generation"); Sites: * src/types.rs::tests::generate_signing_key (test scaffold) * src/types.rs::verification::generate_signing_key (#[cfg(feature = "kani")]) * src/main.rs::get_or_create_identity (production; also marked INSECURE - prototype only in the surrounding comment, so .expect matches the existing risk acceptance) Verified locally: cargo build -> EXIT 0 (warnings unchanged) cargo test -> 7 passed / 0 failed / 0 ignored Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5a70427 commit 24d6e1c

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

vext-email-gateway/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,14 @@ impl Gateway {
298298

299299
/// Get or create cryptographic identity for email address
300300
fn get_or_create_identity(&self, _email: &str) -> Result<ed25519_dalek::SigningKey> {
301-
use rand::RngCore;
301+
use rand::TryRngCore;
302302

303303
// TODO: Persistent storage of email → keypair mapping
304304
// For now, generate a new signing key (INSECURE - prototype only).
305305
let mut rng = rand::rngs::OsRng;
306306
let mut sk = [0u8; 32];
307-
rng.fill_bytes(&mut sk);
307+
rng.try_fill_bytes(&mut sk)
308+
.expect("OsRng must succeed for cryptographic key generation");
308309
Ok(ed25519_dalek::SigningKey::from_bytes(&sk))
309310
}
310311
}

vext-email-gateway/src/types.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,11 @@ mod tests {
331331
use proptest::prelude::*;
332332

333333
fn generate_signing_key() -> SigningKey {
334-
use rand::RngCore;
334+
use rand::TryRngCore;
335335
let mut rng = rand::rngs::OsRng;
336336
let mut sk = [0u8; 32];
337-
rng.fill_bytes(&mut sk);
337+
rng.try_fill_bytes(&mut sk)
338+
.expect("OsRng must succeed for cryptographic key generation");
338339
SigningKey::from_bytes(&sk)
339340
}
340341

@@ -401,10 +402,11 @@ mod verification {
401402
use super::*;
402403

403404
fn generate_signing_key() -> SigningKey {
404-
use rand::RngCore;
405+
use rand::TryRngCore;
405406
let mut rng = rand::rngs::OsRng;
406407
let mut sk = [0u8; 32];
407-
rng.fill_bytes(&mut sk);
408+
rng.try_fill_bytes(&mut sk)
409+
.expect("OsRng must succeed for cryptographic key generation");
408410
SigningKey::from_bytes(&sk)
409411
}
410412

0 commit comments

Comments
 (0)