Skip to content

Commit 2d55947

Browse files
committed
Fix rand_jitter error conversion
1 parent c5a5ab1 commit 2d55947

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

rand_jitter/src/error.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ use rand_core::Error;
1111
use core::fmt;
1212

1313
/// An error that can occur when [`JitterRng::test_timer`] fails.
14+
///
15+
/// All variants have a value of 0x6e530400 = 1850934272 plus a small
16+
/// increment (1 through 5).
1417
///
1518
/// [`JitterRng::test_timer`]: crate::JitterRng::test_timer
1619
#[derive(Debug, Clone, PartialEq, Eq)]
1720
pub enum TimerError {
1821
/// No timer available.
19-
NoTimer,
22+
NoTimer = 0x6e530401,
2023
/// Timer too coarse to use as an entropy source.
21-
CoarseTimer,
24+
CoarseTimer = 0x6e530402,
2225
/// Timer is not monotonically increasing.
23-
NotMonotonic,
26+
NotMonotonic = 0x6e530403,
2427
/// Variations of deltas of time too small.
25-
TinyVariantions,
28+
TinyVariantions = 0x6e530404,
2629
/// Too many stuck results (indicating no added entropy).
27-
TooManyStuck,
30+
TooManyStuck = 0x6e530405,
2831
#[doc(hidden)]
2932
__Nonexhaustive,
3033
}
@@ -60,11 +63,10 @@ impl From<TimerError> for Error {
6063
// Timer check is already quite permissive of failures so we don't
6164
// expect false-positive failures, i.e. any error is irrecoverable.
6265
#[cfg(feature = "std")] {
63-
Error::with_cause("timer jitter failed basic quality tests", err)
66+
Error::new(err)
6467
}
6568
#[cfg(not(feature = "std"))] {
66-
let _ = err;
67-
Error::new("timer jitter failed basic quality tests")
69+
Error::from(core::num::NonZeroU32::new(err as u32).unwrap())
6870
}
6971
}
7072
}

0 commit comments

Comments
 (0)