From a4955998fe5c741792f3fb0eea71f79f6551997b Mon Sep 17 00:00:00 2001 From: Sebastian Hasler Date: Tue, 17 Jan 2023 12:07:16 +0100 Subject: [PATCH] Impl `Random` for `Wrapping` --- src/wrapping.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/wrapping.rs b/src/wrapping.rs index c2f6c2b3..83311c58 100644 --- a/src/wrapping.rs +++ b/src/wrapping.rs @@ -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}; @@ -60,6 +63,13 @@ impl ConstantTimeEq for Wrapping { } } +#[cfg(feature = "rand_core")] +impl Random for Wrapping { + 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 {