12
12
//! Keys are stored in this struct:
13
13
//!
14
14
//! ```rust,no_run
15
- //! use torrust_tracker_lib::core::auth ::Key;
15
+ //! use torrust_tracker_lib::core::authentication ::Key;
16
16
//! use torrust_tracker_primitives::DurationSinceUnixEpoch;
17
17
//!
18
- //! pub struct ExpiringKey {
18
+ //! pub struct PeerKey {
19
19
//! /// Random 32-char string. For example: `YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ`
20
20
//! pub key: Key,
21
- //! /// Timestamp, the key will be no longer valid after this timestamp
21
+ //!
22
+ //! /// Timestamp, the key will be no longer valid after this timestamp.
23
+ //! /// If `None` the keys will not expire (permanent key).
22
24
//! pub valid_until: Option<DurationSinceUnixEpoch>,
23
25
//! }
24
26
//! ```
25
27
//!
26
28
//! You can generate a new key valid for `9999` seconds and `0` nanoseconds from the current time with the following:
27
29
//!
28
30
//! ```rust,no_run
29
- //! use torrust_tracker_lib::core::auth ;
31
+ //! use torrust_tracker_lib::core::authentication ;
30
32
//! use std::time::Duration;
31
33
//!
32
- //! let expiring_key = auth ::generate_key(Some(Duration::new(9999, 0)));
34
+ //! let expiring_key = authentication::key ::generate_key(Some(Duration::new(9999, 0)));
33
35
//!
34
36
//! // And you can later verify it with:
35
37
//!
36
- //! assert!(auth ::verify_key_expiration(&expiring_key).is_ok());
38
+ //! assert!(authentication::key ::verify_key_expiration(&expiring_key).is_ok());
37
39
//! ```
38
40
39
41
use std:: panic:: Location ;
@@ -197,7 +199,7 @@ impl Key {
197
199
/// Error returned when a key cannot be parsed from a string.
198
200
///
199
201
/// ```text
200
- /// use torrust_tracker_lib::core::auth ::Key;
202
+ /// use torrust_tracker_lib::core::authentication ::Key;
201
203
/// use std::str::FromStr;
202
204
///
203
205
/// let key_string = "YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ";
@@ -227,7 +229,7 @@ impl FromStr for Key {
227
229
}
228
230
229
231
/// Verification error. Error returned when an [`PeerKey`] cannot be
230
- /// verified with the (`crate::core::auth ::verify_key`) function.
232
+ /// verified with the (`crate::core::authentication ::verify_key`) function.
231
233
#[ derive( Debug , Error ) ]
232
234
#[ allow( dead_code) ]
233
235
pub enum Error {
@@ -258,7 +260,7 @@ mod tests {
258
260
mod key {
259
261
use std:: str:: FromStr ;
260
262
261
- use crate :: core:: auth :: Key ;
263
+ use crate :: core:: authentication :: Key ;
262
264
263
265
#[ test]
264
266
fn should_be_parsed_from_an_string ( ) {
@@ -293,12 +295,12 @@ mod tests {
293
295
use torrust_tracker_clock:: clock;
294
296
use torrust_tracker_clock:: clock:: stopped:: Stopped as _;
295
297
296
- use crate :: core:: auth ;
298
+ use crate :: core:: authentication ;
297
299
298
300
#[ test]
299
301
fn should_be_parsed_from_an_string ( ) {
300
302
let key_string = "YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ" ;
301
- let auth_key = auth :: Key :: from_str ( key_string) ;
303
+ let auth_key = authentication :: Key :: from_str ( key_string) ;
302
304
303
305
assert ! ( auth_key. is_ok( ) ) ;
304
306
assert_eq ! ( auth_key. unwrap( ) . to_string( ) , key_string) ;
@@ -309,7 +311,7 @@ mod tests {
309
311
// Set the time to the current time.
310
312
clock:: Stopped :: local_set_to_unix_epoch ( ) ;
311
313
312
- let expiring_key = auth :: generate_key ( Some ( Duration :: from_secs ( 0 ) ) ) ;
314
+ let expiring_key = authentication :: key :: generate_key ( Some ( Duration :: from_secs ( 0 ) ) ) ;
313
315
314
316
assert_eq ! (
315
317
expiring_key. to_string( ) ,
@@ -319,9 +321,9 @@ mod tests {
319
321
320
322
#[ test]
321
323
fn should_be_generated_with_a_expiration_time ( ) {
322
- let expiring_key = auth :: generate_key ( Some ( Duration :: new ( 9999 , 0 ) ) ) ;
324
+ let expiring_key = authentication :: key :: generate_key ( Some ( Duration :: new ( 9999 , 0 ) ) ) ;
323
325
324
- assert ! ( auth :: verify_key_expiration( & expiring_key) . is_ok( ) ) ;
326
+ assert ! ( authentication :: key :: verify_key_expiration( & expiring_key) . is_ok( ) ) ;
325
327
}
326
328
327
329
#[ test]
@@ -330,17 +332,17 @@ mod tests {
330
332
clock:: Stopped :: local_set_to_system_time_now ( ) ;
331
333
332
334
// Make key that is valid for 19 seconds.
333
- let expiring_key = auth :: generate_key ( Some ( Duration :: from_secs ( 19 ) ) ) ;
335
+ let expiring_key = authentication :: key :: generate_key ( Some ( Duration :: from_secs ( 19 ) ) ) ;
334
336
335
337
// Mock the time has passed 10 sec.
336
338
clock:: Stopped :: local_add ( & Duration :: from_secs ( 10 ) ) . unwrap ( ) ;
337
339
338
- assert ! ( auth :: verify_key_expiration( & expiring_key) . is_ok( ) ) ;
340
+ assert ! ( authentication :: key :: verify_key_expiration( & expiring_key) . is_ok( ) ) ;
339
341
340
342
// Mock the time has passed another 10 sec.
341
343
clock:: Stopped :: local_add ( & Duration :: from_secs ( 10 ) ) . unwrap ( ) ;
342
344
343
- assert ! ( auth :: verify_key_expiration( & expiring_key) . is_err( ) ) ;
345
+ assert ! ( authentication :: key :: verify_key_expiration( & expiring_key) . is_err( ) ) ;
344
346
}
345
347
}
346
348
}
0 commit comments