Replace getrandom with rand_core (#276)

`rand_core::OsRng` provides a facade over `getrandom` which simplifies
error handling.
This commit is contained in:
Tony Arcieri (iqlusion)
2021-07-12 09:58:58 -07:00
committed by GitHub
parent 1018127843
commit e249e91297
9 changed files with 48 additions and 78 deletions
+4 -4
View File
@@ -31,7 +31,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
use crate::{Error, Result, YubiKey};
use getrandom::getrandom;
use rand_core::{OsRng, RngCore};
use std::{
fmt::{self, Debug, Display},
str,
@@ -68,10 +68,10 @@ impl CardId {
pub const BYTE_SIZE: usize = 14;
/// Generate a random CCC Card ID
pub fn generate() -> Result<Self> {
pub fn generate() -> Self {
let mut id = [0u8; Self::BYTE_SIZE];
getrandom(&mut id).map_err(|_| Error::RandomnessError)?;
Ok(Self(id))
OsRng.fill_bytes(&mut id);
Self(id)
}
}