secure_rand_bytes: Do not propagate getrandom error and correct example to not allocate a mac, but instead just random bytes.
@@ -33,7 +33,7 @@ use subtle::ConstantTimeEq;
/// types used throughout orion, implement their own `generate()` function and
/// it is strongly preferred to use those, compared to `secure_rand_bytes()`.
///
-/// This uses [`getrandom`](https://github.com/rust-random/getrandom).
+/// This uses [`getrandom`].
///
/// # Parameters:
/// - `dst`: Destination buffer for the randomly generated bytes. The amount of
@@ -47,22 +47,23 @@ use subtle::ConstantTimeEq;
/// # Panics:
/// A panic will occur if:
/// - Failure to generate random bytes securely.
+/// - The platform is not supported by [`getrandom`].
///
/// # Example:
/// ```rust
/// use orion::util;
///
/// let mut salt = [0u8; 64];
-///
/// util::secure_rand_bytes(&mut salt)?;
/// # Ok::<(), orion::errors::UnknownCryptoError>(())
/// ```
+/// [`getrandom`]: https://github.com/rust-random/getrandom
pub fn secure_rand_bytes(dst: &mut [u8]) -> Result<(), errors::UnknownCryptoError> {
if dst.is_empty() {
return Err(errors::UnknownCryptoError);
}
- getrandom::getrandom(dst)?;
+ getrandom::getrandom(dst).unwrap();
Ok(())
}
@@ -87,11 +88,11 @@ pub fn secure_rand_bytes(dst: &mut [u8]) -> Result<(), errors::UnknownCryptoErro
/// ```rust
/// use orion::util;
///
-/// let mut mac = [0u8; 64];
-/// assert!(util::secure_cmp(&mac, &[0u8; 64])?);
+/// let mut rnd_bytes = [0u8; 64];
+/// assert!(util::secure_cmp(&rnd_bytes, &[0u8; 64])?);
///
-/// util::secure_rand_bytes(&mut mac)?;
-/// assert!(util::secure_cmp(&mac, &[0u8; 64]).is_err());
+/// util::secure_rand_bytes(&mut rnd_bytes)?;
+/// assert!(util::secure_cmp(&rnd_bytes, &[0u8; 64]).is_err());
/// # Ok::<(), orion::errors::UnknownCryptoError>(())
/// ```
pub fn secure_cmp(a: &[u8], b: &[u8]) -> Result<bool, errors::UnknownCryptoError> {
