@@ -4,8 +4,9 @@ use aes::{
44 Aes256Enc , Block ,
55 cipher:: { BlockCipherEncrypt , KeyInit } ,
66} ;
7+ use core:: convert:: Infallible ;
78use hybrid_array:: { Array , typenum:: U48 } ;
8- use rand_core:: { CryptoRng , RngCore , SeedableRng } ;
9+ use rand_core:: { RngCore , SeedableRng , TryCryptoRng , TryRngCore } ;
910
1011/// Seed type for the AES-CTR DRBG
1112pub type RngSeed = Array < u8 , U48 > ;
@@ -29,20 +30,22 @@ impl SeedableRng for AesCtrDrbg {
2930 }
3031}
3132
32- impl RngCore for AesCtrDrbg {
33- fn next_u32 ( & mut self ) -> u32 {
33+ impl TryRngCore for AesCtrDrbg {
34+ type Error = Infallible ;
35+
36+ fn try_next_u32 ( & mut self ) -> Result < u32 , Self :: Error > {
3437 let mut int = [ 0u8 ; 4 ] ;
3538 self . fill_bytes ( & mut int) ;
36- u32:: from_le_bytes ( int)
39+ Ok ( u32:: from_le_bytes ( int) )
3740 }
3841
39- fn next_u64 ( & mut self ) -> u64 {
42+ fn try_next_u64 ( & mut self ) -> Result < u64 , Self :: Error > {
4043 let mut int = [ 0u8 ; 8 ] ;
4144 self . fill_bytes ( & mut int) ;
42- u64:: from_le_bytes ( int)
45+ Ok ( u64:: from_le_bytes ( int) )
4346 }
4447
45- fn fill_bytes ( & mut self , dest : & mut [ u8 ] ) {
48+ fn try_fill_bytes ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
4649 let mut in_block = Block :: default ( ) ;
4750 let mut out_block = Block :: default ( ) ;
4851 let enc = Aes256Enc :: new_from_slice ( & self . key ) . unwrap ( ) ;
@@ -64,10 +67,11 @@ impl RngCore for AesCtrDrbg {
6467
6568 self . update ( None ) ;
6669 self . reseed_counter += 1 ;
70+ Ok ( ( ) )
6771 }
6872}
6973
70- impl CryptoRng for AesCtrDrbg { }
74+ impl TryCryptoRng for AesCtrDrbg { }
7175
7276impl AesCtrDrbg {
7377 /// Reseed the DRBG with a new seed
0 commit comments