Skip to content

Commit 47a5724

Browse files
committed
Reset data_half_used on JitterRng::clone()
1 parent deb1f04 commit 47a5724

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/jitter.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const MEMORY_SIZE: usize = MEMORY_BLOCKS * MEMORY_BLOCKSIZE;
5151
/// [Jitterentropy](http://www.chronox.de/jent.html) version 2.1.0.
5252
///
5353
/// [`OsRng`]: ../os/struct.OsRng.html
54-
#[derive(Clone)]
5554
pub struct JitterRng {
5655
data: u64, // Actual random number
5756
// Number of rounds to run the entropy collector per 64 bits
@@ -120,6 +119,20 @@ impl fmt::Debug for JitterRng {
120119
}
121120
}
122121

122+
impl Clone for JitterRng {
123+
fn clone(&self) -> JitterRng {
124+
JitterRng {
125+
data: self.data,
126+
rounds: self.rounds,
127+
timer: self.timer,
128+
mem_prev_index: self.mem_prev_index,
129+
// The 32 bits that may still be unused from the previous round are
130+
// for the original to use, not for the clone.
131+
data_half_used: false,
132+
}
133+
}
134+
}
135+
123136
/// An error that can occur when [`JitterRng::test_timer`] fails.
124137
///
125138
/// [`JitterRng::test_timer`]: struct.JitterRng.html#method.test_timer

0 commit comments

Comments
 (0)