forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathephemeral_instance_keys.rs
More file actions
25 lines (20 loc) · 1.02 KB
/
ephemeral_instance_keys.rs
File metadata and controls
25 lines (20 loc) · 1.02 KB
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
//! This module contains the ephemeral instance keys used by the application.
//!
//! They are ephemeral because they are generated at runtime when the
//! application starts and are not persisted anywhere.
use blowfish::BlowfishLE;
use cipher::generic_array::GenericArray;
use cipher::{BlockSizeUser, KeyInit};
use rand::rngs::ThreadRng;
use rand::Rng;
pub type Seed = [u8; 32];
pub type CipherBlowfish = BlowfishLE;
pub type CipherArrayBlowfish = GenericArray<u8, <CipherBlowfish as BlockSizeUser>::BlockSize>;
lazy_static! {
/// The random static seed.
pub static ref RANDOM_SEED: Seed = Rng::gen(&mut ThreadRng::default());
/// The random cipher from the seed.
pub static ref RANDOM_CIPHER_BLOWFISH: CipherBlowfish = CipherBlowfish::new_from_slice(&Rng::gen::<Seed>(&mut ThreadRng::default())).expect("it could not generate key");
/// The constant cipher for testing.
pub static ref ZEROED_TEST_CIPHER_BLOWFISH: CipherBlowfish = CipherBlowfish::new_from_slice(&[0u8; 32]).expect("it could not generate key");
}