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
40
41
42
43
44
45
46
47
48
49
50
51
use ockam_vault::SecretAttributes;
use ockam_vault_core::{SecretPersistence, SecretType, CURVE25519_SECRET_LENGTH};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub enum MetaKeyAttributes {
None,
SecretAttributes(SecretAttributes),
}
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct KeyAttributes {
label: String,
meta: MetaKeyAttributes,
}
impl From<&str> for KeyAttributes {
fn from(str: &str) -> Self {
Self::new(str.to_string())
}
}
impl KeyAttributes {
pub fn label(&self) -> &str {
&self.label
}
pub fn meta(&self) -> &MetaKeyAttributes {
&self.meta
}
}
impl KeyAttributes {
pub fn new<S: Into<String>>(label: S) -> Self {
Self {
label: label.into(),
meta: MetaKeyAttributes::SecretAttributes(SecretAttributes::new(
SecretType::Curve25519,
SecretPersistence::Persistent,
CURVE25519_SECRET_LENGTH,
)),
}
}
pub fn with_attributes(label: String, meta: MetaKeyAttributes) -> Self {
Self { label, meta }
}
}