File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -38,15 +38,26 @@ recommend to run the much more stringent
38
38
39
39
Use the following code using ` timer_stats ` to collect the data:
40
40
41
- ``` rust
41
+ ``` rust,no_run
42
42
use rand_jitter::JitterRng;
43
43
44
44
use std::error::Error;
45
45
use std::fs::File;
46
46
use std::io::Write;
47
47
48
+ fn get_nstime() -> u64 {
49
+ use std::time::{SystemTime, UNIX_EPOCH};
50
+
51
+ let dur = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
52
+ // The correct way to calculate the current time is
53
+ // `dur.as_secs() * 1_000_000_000 + dur.subsec_nanos() as u64`
54
+ // But this is faster, and the difference in terms of entropy is
55
+ // negligible (log2(10^9) == 29.9).
56
+ dur.as_secs() << 30 | dur.subsec_nanos() as u64
57
+ }
58
+
48
59
fn main() -> Result<(), Box<Error>> {
49
- let mut rng = JitterRng :: new () ? ;
60
+ let mut rng = JitterRng::new_with_timer(get_nstime) ;
50
61
51
62
// 1_000_000 results are required for the
52
63
// NIST SP 800-90B Entropy Estimation Suite
Original file line number Diff line number Diff line change @@ -63,6 +63,17 @@ extern crate libc;
63
63
#[ cfg( target_os = "windows" ) ]
64
64
extern crate winapi;
65
65
66
+ // Coming from https://crates.io/crates/doc-comment
67
+ #[ cfg( test) ]
68
+ macro_rules! doc_comment {
69
+ ( $x: expr) => {
70
+ #[ doc = $x]
71
+ extern { }
72
+ } ;
73
+ }
74
+
75
+ #[ cfg( test) ]
76
+ doc_comment ! ( include_str!( "../README.md" ) ) ;
66
77
67
78
#[ cfg( not( feature = "log" ) ) ]
68
79
#[ macro_use] mod dummy_log;
You can’t perform that action at this time.
0 commit comments