-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As proposed in #442 this makes `rand_core` an optional feature that is not covered by the SemVer public API stability guarantees. Co-authored-by: Michael Rosenberg <[email protected]>
- Loading branch information
1 parent
2190332
commit 47a0c3e
Showing
9 changed files
with
69 additions
and
14 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
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,42 @@ | ||
//! This is used mocking / proxying the below for tests: | ||
//! - random_test() to Scalar::random() depending on feature `rand_core` | ||
use crate::ristretto::RistrettoPoint; | ||
use crate::scalar::Scalar; | ||
|
||
use rand_core::{CryptoRng, RngCore}; | ||
|
||
pub struct MockScalar; | ||
impl MockScalar { | ||
#[cfg(feature = "rand_core")] | ||
/// Proxy Scalar::random() for random_test | ||
pub fn random<R: RngCore + CryptoRng + ?Sized>(rng: &mut R) -> Scalar { | ||
Scalar::random(rng) | ||
} | ||
|
||
#[cfg(not(feature = "rand_core"))] | ||
/// Mock Scalar::random() for random_test | ||
pub fn random<R: RngCore + CryptoRng + ?Sized>(rng: &mut R) -> Scalar { | ||
let mut scalar_bytes = [0u8; 64]; | ||
rng.fill_bytes(&mut scalar_bytes); | ||
Scalar::from_bytes_mod_order_wide(&scalar_bytes) | ||
} | ||
} | ||
|
||
pub struct MockRistrettoPoint; | ||
impl MockRistrettoPoint { | ||
#[cfg(feature = "rand_core")] | ||
/// Proxy RistrettoPoint::random() for random_test | ||
pub fn random<R: RngCore + CryptoRng + ?Sized>(rng: &mut R) -> RistrettoPoint { | ||
RistrettoPoint::random(rng) | ||
} | ||
|
||
#[cfg(not(feature = "rand_core"))] | ||
/// Mock RistrettoPoint::random() for random_test | ||
pub fn random<R: RngCore + CryptoRng + ?Sized>(rng: &mut R) -> RistrettoPoint { | ||
let mut uniform_bytes = [0u8; 64]; | ||
rng.fill_bytes(&mut uniform_bytes); | ||
|
||
RistrettoPoint::from_uniform_bytes(&uniform_bytes) | ||
} | ||
} |
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