-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
relax sizing requirement on the
TryCryptoRng
- Loading branch information
Showing
5 changed files
with
49 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use rand_core::{CryptoRng, RngCore, TryCryptoRng, TryRngCore}; | ||
|
||
/// Adapter from [`CryptoRng`] to [`TryCryptoRng`] | ||
/// | ||
/// This is pending the release of a fix availale in this PR: | ||
/// <https://github.com/rust-random/rand/pull/1593> | ||
#[doc(hidden)] | ||
#[derive(Debug)] | ||
pub struct MaybeRng<'r, R>(pub &'r mut R) | ||
where | ||
R: ?Sized; | ||
|
||
impl<R> TryRngCore for MaybeRng<'_, R> | ||
where | ||
R: RngCore + ?Sized, | ||
{ | ||
type Error = core::convert::Infallible; | ||
|
||
#[inline] | ||
fn try_next_u32(&mut self) -> Result<u32, Self::Error> { | ||
Ok(self.0.next_u32()) | ||
} | ||
#[inline] | ||
fn try_next_u64(&mut self) -> Result<u64, Self::Error> { | ||
Ok(self.0.next_u64()) | ||
} | ||
#[inline] | ||
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> { | ||
self.0.fill_bytes(dst); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl<R: CryptoRng + ?Sized> TryCryptoRng for MaybeRng<'_, R> {} |