-
-
Notifications
You must be signed in to change notification settings - Fork 558
/
types.rs
81 lines (68 loc) · 1.83 KB
/
types.rs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use minicbor::{Decode, Encode};
use ockam::identity::Identifier;
use std::collections::BTreeMap;
use std::time::Duration;
#[derive(Debug, Decode, Encode)]
#[rustfmt::skip]
#[cbor(map)]
pub struct AddMember {
#[n(1)] member: Identifier,
#[b(2)] attributes: BTreeMap<String, String>,
}
impl AddMember {
pub fn new(member: Identifier) -> Self {
AddMember {
member,
attributes: BTreeMap::new(),
}
}
pub fn with_attributes(mut self, attributes: BTreeMap<String, String>) -> Self {
self.attributes = attributes;
self
}
pub fn member(&self) -> &Identifier {
&self.member
}
pub fn attributes(&self) -> &BTreeMap<String, String> {
&self.attributes
}
}
#[derive(Debug, Decode, Encode)]
#[rustfmt::skip]
#[cbor(map)]
pub struct CreateToken {
#[b(1)] attributes: BTreeMap<String, String>,
#[n(2)] ttl_secs: Option<u64>,
#[n(3)] ttl_count: Option<u64>,
}
impl CreateToken {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
CreateToken {
attributes: Default::default(),
ttl_count: None,
ttl_secs: None,
}
}
pub fn with_attributes(mut self, attributes: BTreeMap<String, String>) -> Self {
self.attributes = attributes;
self
}
pub fn with_ttl(mut self, duration: Option<Duration>) -> Self {
self.ttl_secs = duration.map(|d| d.as_secs());
self
}
pub fn with_ttl_count(mut self, ttl_count: Option<u64>) -> Self {
self.ttl_count = ttl_count;
self
}
pub fn into_owned_attributes(self) -> BTreeMap<String, String> {
self.attributes.clone()
}
pub fn ttl_count(&self) -> Option<u64> {
self.ttl_count
}
pub fn ttl_secs(&self) -> Option<u64> {
self.ttl_secs
}
}