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
use crate::crypto;
use crate::options::Options;
use crate::types::PageKind;
pub use super::ServiceBuilder;
impl ServiceBuilder {
pub(crate) fn validate(&self) -> Result<(), String> {
if let Some(_private_opts) = &self.private_options {
if self.secret_key.is_none() {
return Err("Private options cannot be used without specifying or creating an associated secret key".to_owned());
}
}
Ok(())
}
pub fn peer(&mut self) -> &mut Self {
let mut new = self;
new.kind = Some(PageKind::Peer);
new
}
pub fn generic(&mut self) -> &mut Self {
let mut new = self;
new.kind = Some(PageKind::Generic);
new
}
pub fn private(&mut self) -> &mut Self {
let mut new = self;
new.kind = Some(PageKind::Private);
new
}
pub fn encrypt(&mut self) -> &mut Self {
let mut new = self;
let secret_key = crypto::new_sk().unwrap();
new.secret_key = Some(Some(secret_key));
new.encrypted = Some(true);
new
}
pub fn append_public_option(&mut self, o: Options) -> &mut Self {
match &mut self.public_options {
Some(opts) => opts.push(o),
None => self.public_options = Some(vec![o]),
}
self
}
pub fn append_private_option(&mut self, o: Options) -> &mut Self {
match &mut self.private_options {
Some(opts) => opts.append(o),
None => panic!("attempting to append private option to encrypted field"),
}
self
}
}