Skip to content
Snippets Groups Projects

Elois/rand

7 files
+ 74
15
Compare changes
  • Side-by-side
  • Inline

Files

+ 6
4
@@ -16,8 +16,9 @@
//! Provide wrappers for cryptographic hashs
use crate::bases::*;
#[cfg(feature = "rand")]
use crate::rand::UnspecifiedRandError;
use ring::{digest, rand};
use ring::digest;
#[cfg(feature = "ser")]
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display, Error, Formatter};
@@ -57,12 +58,12 @@ impl Hash {
/// Hash size (in bytes).
pub const SIZE_IN_BYTES: usize = 32;
#[cfg(feature = "rand")]
/// Generate a random Hash
#[inline]
pub fn random() -> Result<Self, UnspecifiedRandError> {
let random_bytes = rand::generate::<[u8; 32]>(&rand::SystemRandom::new())
.map_err(|_| UnspecifiedRandError)?;
Ok(Hash(random_bytes.expose()))
let random_bytes = crate::rand::gen_32_bytes().map_err(|_| UnspecifiedRandError)?;
Ok(Hash(random_bytes))
}
/// Compute hash of any binary datas
@@ -103,6 +104,7 @@ mod tests {
use super::*;
#[cfg(feature = "rand")]
#[test]
fn test_hash_random() {
let hash1 = Hash::random();
Loading