1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
use Error;
use File;
use Read;
/// Reads the system's boot ID from `/proc/sys/kernel/random/boot_id`.
///
/// The boot ID is a unique identifier that changes each time the system boots.
///
/// # Returns
/// - `Ok(String)` - The boot ID string
/// - `Err` - If there's an error reading the boot ID
///
/// # Errors
/// - Returns error if unable to open `/proc/sys/kernel/random/boot_id`
/// - Returns error if unable to read from the file
/// - Returns error if the file content is not valid UTF-8
///
/// # Example
/// ```no_run
/// # use anyhow::Result;
/// # use linux_crng_ioctl::proc::boot_id;
/// # fn main() -> Result<()> {
/// let boot_id = boot_id()?;
/// println!("System boot ID: {}", boot_id);
/// # Ok(())
/// # }
/// ```
/// Reads the current available entropy from `/proc/sys/kernel/random/entropy_avail`.
///
/// This value represents the kernel's estimation of available entropy in bits.
///
/// # Returns
/// - `Ok(u32)` - The number of bits of available entropy
/// - `Err` - If there's an error reading the entropy value
///
/// # Errors
/// - Returns error if unable to open `/proc/sys/kernel/random/entropy_avail`
/// - Returns error if unable to read from the file
/// - Returns error if the file content is not valid UTF-8
/// - Returns error if the content cannot be parsed as a u32
///
/// # Example
/// ```no_run
/// # use anyhow::Result;
/// # use linux_crng_ioctl::proc::entropy_avail;
/// # fn main() -> Result<()> {
/// let available_entropy = entropy_avail()?;
/// println!("Available entropy: {} bits", available_entropy);
/// # Ok(())
/// # }
/// ```
/// Reads the entropy pool size from `/proc/sys/kernel/random/poolsize`.
///
/// Returns the size of the kernel's entropy pool in bits.
///
/// # Returns
/// - `Ok(u32)` - The size of the entropy pool in bits
/// - `Err` - If there's an error reading the pool size
///
/// # Errors
/// - Returns error if unable to open `/proc/sys/kernel/random/poolsize`
/// - Returns error if unable to read from the file
/// - Returns error if the file content is not valid UTF-8
/// - Returns error if the content cannot be parsed as a u32
/// Generates a new UUID using the kernel's random number generator.
///
/// Reads a new UUID from `/proc/sys/kernel/random/uuid`.
///
/// # Returns
/// - `Ok(String)` - A new random UUID string
/// - `Err` - If there's an error generating or reading the UUID
///
/// # Errors
/// - Returns error if unable to open `/proc/sys/kernel/random/uuid`
/// - Returns error if unable to read from the file
/// - Returns error if the file content is not valid UTF-8
///
/// # Example
/// ```no_run
/// # use anyhow::Result;
/// # use linux_crng_ioctl::proc::uuid;
/// # fn main() -> Result<()> {
/// let uuid = uuid()?;
/// println!("Generated UUID: {}", uuid);
/// # Ok(())
/// # }
/// ```
/// Reads the minimum reseed time for /dev/urandom.
///
/// Returns the minimum number of seconds between automatic reseeding
/// of the urandom pool from the entropy pool.
///
/// # Returns
/// - `Ok(u32)` - The minimum reseed time in seconds
/// - `Err` - If there's an error reading the value
///
/// # Errors
/// - Returns error if unable to open `/proc/sys/kernel/random/urandom_min_reseed_secs`
/// - Returns error if unable to read from the file
/// - Returns error if the file content is not valid UTF-8
/// - Returns error if the content cannot be parsed as a u32
/// Reads the `write_wakeup_threshold` from `/proc/sys/kernel/random/write_wakeup_threshold`.
///
/// This value determines the threshold at which writers to /dev/random are woken up.
///
/// # Returns
/// - `Ok(u32)` - The current write wakeup threshold
/// - `Err` - If there's an error reading the threshold
///
/// # Errors
/// - Returns error if unable to open `/proc/sys/kernel/random/write_wakeup_threshold`
/// - Returns error if unable to read from the file
/// - Returns error if the file content is not valid UTF-8
/// - Returns error if the content cannot be parsed as a u32