Expand description

Tracker authentication services and structs.

This module contains functions to handle tracker keys. Tracker keys are tokens used to authenticate the tracker clients when the tracker runs in private or private_listed modes.

There are services to generate and verify authentication keys.

Authentication keys are used only by HTTP trackers. All keys have an expiration time, that means they are only valid during a period of time. After that time the expiring key will no longer be valid.

Keys are stored in this struct:

use torrust_tracker::tracker::auth::Key;
use torrust_tracker::shared::clock::DurationSinceUnixEpoch;

pub struct ExpiringKey {
    /// Random 32-char string. For example: `YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ`
    pub key: Key,
    /// Timestamp, the key will be no longer valid after this timestamp
    pub valid_until: DurationSinceUnixEpoch,
}

You can generate a new key valid for 9999 seconds and 0 nanoseconds from the current time with the following:

use torrust_tracker::tracker::auth;
use std::time::Duration;

let expiring_key = auth::generate(Duration::new(9999, 0));

// And you can later verify it with:

assert!(auth::verify(&expiring_key).is_ok());

Structs

  • An authentication key which has an expiration time. After that time is will automatically become invalid.
  • A randomly generated token used for authentication.
  • Error returned when a key cannot be parsed from a string.

Enums

Functions