@@ -7,7 +7,7 @@ use p256::{
77 SecretKey ,
88} ;
99use qos_p256:: encrypt:: Envelope ;
10- use rand_core:: { OsRng , RngCore } ;
10+ use rand_core:: { OsRng , TryRngCore } ;
1111use x509:: RelativeDistinguishedName ;
1212use yubikey:: {
1313 certificate:: { Certificate , PublicKeyInfo } ,
@@ -70,6 +70,9 @@ pub enum YubiKeyError {
7070/// Generate a signed certificate with a p256 key for the given `slot`.
7171///
7272/// Returns the public key as an uncompressed encoded point.
73+ ///
74+ /// # Panics
75+ /// Panics if the `OsRng` is unable to provide data, which shouldn't happen in normal operation.
7376pub fn generate_signed_certificate (
7477 yubikey : & mut YubiKey ,
7578 slot : SlotId ,
@@ -95,7 +98,9 @@ pub fn generate_signed_certificate(
9598
9699 // Create a random serial number
97100 let mut serial = [ 0u8 ; 20 ] ;
98- OsRng . fill_bytes ( & mut serial) ;
101+ OsRng . try_fill_bytes ( & mut serial) . expect (
102+ "The OsRng was unable to provide data, which should never happen" ,
103+ ) ;
99104
100105 // Don't add any extensions
101106 let extensions: & [ x509:: Extension < ' _ , & [ u64 ] > ] = & [ ] ;
@@ -117,6 +122,9 @@ pub fn generate_signed_certificate(
117122
118123/// Import the given `key_data` onto the `yubikey` and create a signed
119124/// certificate for the key.
125+ ///
126+ /// # Panics
127+ /// Panics if the `OsRng` is unable to provide data, which shouldn't happen in normal operation.
120128pub fn import_key_and_generate_signed_certificate (
121129 yubikey : & mut YubiKey ,
122130 key_data : & [ u8 ] ,
@@ -156,7 +164,9 @@ pub fn import_key_and_generate_signed_certificate(
156164
157165 // Create a random serial number
158166 let mut serial = [ 0u8 ; 20 ] ;
159- OsRng . fill_bytes ( & mut serial) ;
167+ OsRng . try_fill_bytes ( & mut serial) . expect (
168+ "The OsRng was unable to provide data, which should never happen" ,
169+ ) ;
160170
161171 // Don't add any extensions
162172 let extensions: & [ x509:: Extension < ' _ , & [ u64 ] > ] = & [ ] ;
0 commit comments