voa_config/file/technology/
settings.rs

1//! Handling of common items used in configuration files.
2
3use garde::Validate;
4use serde::{Deserialize, Serialize};
5
6use crate::{ConfigOrigin, file::ConfigOpenpgpSettings};
7
8/// Settings for all supported cryptographic technologies.
9///
10/// Describes zero or more settings for supported cryptographic technologies in a configuration
11/// file. May be used globally, or on an OS-specific level.
12///
13/// # Note
14///
15/// This struct _must_ be validated after creation.
16#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, Validate)]
17#[serde(rename_all = "lowercase")]
18pub struct ConfigTechnologySettings {
19    #[serde(skip)]
20    #[garde(skip)]
21    pub(crate) origins: Vec<ConfigOrigin>,
22
23    #[garde(dive)]
24    openpgp: Option<ConfigOpenpgpSettings>,
25}
26
27impl ConfigTechnologySettings {
28    /// Creates a new [`ConfigTechnologySettings`].
29    // NOTE: used in tests.
30    #[allow(dead_code)]
31    pub(crate) fn new(origins: Vec<ConfigOrigin>, openpgp: Option<ConfigOpenpgpSettings>) -> Self {
32        Self { origins, openpgp }
33    }
34
35    /// Returns a reference to the [`ConfigOpenpgpSettings`].
36    pub(crate) fn config_openpgp_settings(&self) -> Option<&ConfigOpenpgpSettings> {
37        self.openpgp.as_ref()
38    }
39
40    /// Returns a reference to the list of config file origins.
41    pub fn origins(&self) -> &[ConfigOrigin] {
42        &self.origins
43    }
44}
45
46impl Default for ConfigTechnologySettings {
47    fn default() -> Self {
48        Self {
49            origins: vec![ConfigOrigin::Default],
50            openpgp: Some(ConfigOpenpgpSettings::default()),
51        }
52    }
53}