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
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Serializable configuration object.
use std::fmt::Debug;
use std::time::Duration;
#[cfg(any(test, feature = "test_utils"))]
use p2panda_encryption::key_bundle::Lifetime;
use serde::{Deserialize, Serialize};
/// Configuration for a spaces instance.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
/// When a key bundle should be considered expired and thus invalid.
pub pre_key_lifetime: Duration,
/// Rotate our own pre-keys after this duration, to allow some time between peers receiving our
/// new one and the old one expiring.
pub pre_key_rotate_after: Duration,
}
impl Default for Config {
fn default() -> Self {
Self {
// TODO: Use Duration::from_days() once stabilized:
// https://github.com/rust-lang/rust/issues/120301
pre_key_lifetime: Duration::from_hours(24 * 90), // 90 days
pre_key_rotate_after: Duration::from_hours(24 * 60), // 60 days
}
}
}
#[cfg(any(test, feature = "test_utils"))]
impl Config {
#[allow(unused)]
pub(crate) fn lifetime(&self) -> Lifetime {
Lifetime::new(self.pre_key_lifetime.as_secs())
}
}