Skip to content
Snippets Groups Projects

Elois/rand

Merged Éloïs requested to merge elois/rand into dev
7 files
+ 74
15
Compare changes
  • Side-by-side
  • Inline

Files

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