forked from dalek-cryptography/curve25519-dalek
-
Notifications
You must be signed in to change notification settings - Fork 0
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 dalek-cryptography#442 this makes rand_core an optional feature that is not covered by the SemVer public API stability guarantees.
- Loading branch information
1 parent
03b8668
commit afde1c0
Showing
8 changed files
with
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,3 +83,6 @@ pub(crate) mod prelude; | |
|
||
// Generic code for window lookups | ||
pub(crate) mod window; | ||
|
||
#[cfg(test)] | ||
pub mod mocks; |
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