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
}
}