Skip to content

Commit dd5c48b

Browse files
authored
Fix Ed25519 doctest; improve rand test (#653)
1 parent f013911 commit dd5c48b

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

aws-lc-rs/src/rand.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ mod tests {
172172

173173
#[test]
174174
fn test_secure_random_fill() {
175-
let mut random_array = [0u8; 173];
175+
// Collect enough random values so that the assertions below should never fail again
176+
let mut random_array = [0u8; 1009];
176177
let rng = SystemRandom::new();
177178
rng.fill(&mut random_array).unwrap();
178179

@@ -184,7 +185,8 @@ mod tests {
184185

185186
#[test]
186187
fn test_rand_fill() {
187-
let mut random_array: [u8; 173] = [0u8; 173];
188+
// Collect enough random values so that the assertions below should never fail again
189+
let mut random_array = [0u8; 1009];
188190
rand::fill(&mut random_array).unwrap();
189191

190192
let (mean, variance) = mean_variance(&mut random_array.into_iter());
@@ -197,7 +199,8 @@ mod tests {
197199
fn test_randomly_constructable() {
198200
let rando = SystemRandom::new();
199201
let random_array = generate(&rando).unwrap();
200-
let random_array: [u8; 173] = random_array.expose();
202+
// Collect enough random values so that the assertions below should never fail again
203+
let random_array: [u8; 1009] = random_array.expose();
201204
let (mean, variance) = mean_variance(&mut random_array.into_iter());
202205
assert!((106f64..150f64).contains(&mean), "Mean: {mean}");
203206
assert!(variance > 8f64);

aws-lc-rs/src/signature.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,8 @@
124124
//! };
125125
//!
126126
//! fn main() -> Result<(), aws_lc_rs::error::Unspecified> {
127-
//! // Generate a key pair in PKCS#8 (v1) format.
128-
//! let rng = rand::SystemRandom::new();
129-
//! let pkcs8_bytes = signature::Ed25519KeyPair::generate_pkcs8v1(&rng)?;
130-
//!
131-
//! // Normally the application would store the PKCS#8 file persistently. Later
132-
//! // it would read the PKCS#8 file from persistent storage to use it.
133-
//!
134-
//! let key_pair = signature::Ed25519KeyPair::from_pkcs8_maybe_unchecked(pkcs8_bytes.as_ref())?;
127+
//! // Generate a new key pair for Ed25519.
128+
//! let key_pair = signature::Ed25519KeyPair::generate()?;
135129
//!
136130
//! // Sign the message "hello, world".
137131
//! const MESSAGE: &[u8] = b"hello, world";

0 commit comments

Comments
 (0)