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
use std::{
fs::File,
io::{self, BufReader, Read},
ops::{Deref, DerefMut},
path::{Path, PathBuf},
};
use crate::{sign::sign_path_to_file, template::Template};
#[derive(Debug, Clone)]
pub struct Pass {
pass_path: PathBuf,
pub template: Template,
}
impl Pass {
pub fn from_path(pass_path: &Path) -> io::Result<Self> {
let mut path_buf = pass_path.to_path_buf();
path_buf.push("pass.json");
let file = File::open(&path_buf).unwrap();
let mut file_reader = BufReader::new(file);
let mut file_buffer = Vec::new();
file_reader.read_to_end(&mut file_buffer).unwrap();
let template: crate::template::Template = serde_json::from_slice(&file_buffer)?;
Ok(Self {
pass_path: pass_path.to_path_buf(),
template,
})
}
pub fn from_template(template: &Template, pass_path: &Path) -> Self {
Self {
pass_path: pass_path.to_path_buf(),
template: template.clone(),
}
}
pub fn export_to_file(
&self,
output_path: &Path,
certificate_path: &Path,
certificate_password: &str,
wwdr_intermediate_certificate_path: &Path,
) -> io::Result<()> {
sign_path_to_file(
&self.pass_path,
Some(&self.template),
certificate_path,
certificate_password,
wwdr_intermediate_certificate_path,
output_path,
false,
)?;
Ok(())
}
}
impl Deref for Pass {
type Target = Template;
fn deref(&self) -> &Self::Target {
&self.template
}
}
impl DerefMut for Pass {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.template
}
}