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 e598ad6 commit a495599
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, rand_core::CryptoRngCore};

#[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(rng: &mut impl CryptoRngCore) -> Self {
Wrapping(Random::random(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 a495599

Please sign in to comment.