@@ -17,15 +17,18 @@ pub trait Padding {
17
17
fn pub_pad ( & mut self , input : impl AsRef < [ u8 ] > , k : usize ) -> Vec < u8 > ;
18
18
}
19
19
20
- pub trait FillBytes {
21
- type Error : std:: fmt:: Debug + std:: fmt:: Display ;
20
+ /// Represents a source of random bytes.
21
+ pub trait Rng {
22
+ type Error : std:: error:: Error ;
22
23
24
+ /// Implementor must fill all the bytes in the `dest`.
23
25
fn fill ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > ;
24
26
}
25
27
26
- pub struct OsRng ;
28
+ /// Randomness source based on the [`getrandom::fill`].
29
+ pub struct GetRandom ;
27
30
28
- impl FillBytes for OsRng {
31
+ impl Rng for GetRandom {
29
32
type Error = getrandom:: Error ;
30
33
31
34
fn fill ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
@@ -45,7 +48,7 @@ impl<T> Pkcs1Padding<T> {
45
48
}
46
49
}
47
50
48
- impl < T : FillBytes > Padding for Pkcs1Padding < T > {
51
+ impl < T : Rng > Padding for Pkcs1Padding < T > {
49
52
fn pub_pad ( & mut self , input : impl AsRef < [ u8 ] > , k : usize ) -> Vec < u8 > {
50
53
let input = input. as_ref ( ) ;
51
54
let input_len = input. len ( ) ;
@@ -117,7 +120,7 @@ impl<T> Pkcs1OaepPadding<T> {
117
120
}
118
121
}
119
122
120
- impl < T : FillBytes > Padding for Pkcs1OaepPadding < T > {
123
+ impl < T : Rng > Padding for Pkcs1OaepPadding < T > {
121
124
/// Will pad input according to PKCS #1 v2 with encoding parameters equal to `[]`.
122
125
fn pub_pad ( & mut self , input : impl AsRef < [ u8 ] > , k : usize ) -> Vec < u8 > {
123
126
let input = input. as_ref ( ) ;
@@ -231,7 +234,7 @@ mod tests {
231
234
232
235
struct Seed < ' a > ( & ' a [ u8 ] ) ;
233
236
234
- impl < ' a > FillBytes for Seed < ' a > {
237
+ impl < ' a > Rng for Seed < ' a > {
235
238
type Error = std:: io:: Error ;
236
239
237
240
fn fill ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , std:: io:: Error > {
0 commit comments