Skip to content

Commit

Permalink
Impl Random for Wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
haslersn committed Jan 17, 2023
1 parent c765e02 commit edb0955
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use crate::Zero;
use core::fmt;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

#[cfg(feature = "rand_core")]
use crate::Random;

#[cfg(feature = "serde")]
use serdect::serde::{Deserialize, Deserializer, Serialize, Serializer};

Expand Down Expand Up @@ -60,6 +63,13 @@ impl<T: ConstantTimeEq> ConstantTimeEq for Wrapping<T> {
}
}

#[cfg(feature = "rand_core")]
impl<T: Random> Random for Wrapping<T> {
fn random(mut rng: impl rand_core::CryptoRng + rand_core::RngCore) -> Self {
Wrapping(Random::random(&mut rng))
}
}

#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Wrapping<T> {
Expand Down

0 comments on commit edb0955

Please sign in to comment.