Replace getrandom with rand_core (#276)
`rand_core::OsRng` provides a facade over `getrandom` which simplifies error handling.
This commit is contained in:
committed by
GitHub
parent
1018127843
commit
e249e91297
+4
-4
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user