Skip to main content

origin_secrets/
key.rs

1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4/// Addresses one secret.
5///
6/// `namespace` maps to the "service" concept of the platform keychains, `name` to the
7/// account entry within it.
8#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
9pub struct SecretKey {
10    namespace: String,
11    name: String,
12}
13
14impl SecretKey {
15    pub fn new(namespace: impl Into<String>, name: impl Into<String>) -> Self {
16        Self {
17            namespace: namespace.into(),
18            name: name.into(),
19        }
20    }
21
22    pub fn namespace(&self) -> &str {
23        &self.namespace
24    }
25
26    pub fn name(&self) -> &str {
27        &self.name
28    }
29}
30
31impl fmt::Display for SecretKey {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        write!(f, "{}/{}", self.namespace, self.name)
34    }
35}