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
extern crate hyper;
use mime_guess::Mime;
use serde_json;
use crypto::b64;
const MIME_TAR: &str = "application/x-tar";
#[derive(Debug, Serialize, Deserialize)]
pub struct Metadata {
iv: String,
name: String,
#[serde(rename = "type")]
mime: String,
}
impl Metadata {
pub fn from(iv: &[u8], name: String, mime: &Mime) -> Self {
Metadata {
iv: b64::encode(iv),
name,
mime: mime.to_string(),
}
}
pub fn to_json(&self) -> String {
serde_json::to_string(&self).unwrap()
}
pub fn name(&self) -> &str {
&self.name
}
pub fn mime(&self) -> &str {
&self.mime
}
pub fn iv(&self) -> [u8; 12] {
let decoded = b64::decode(&self.iv).unwrap();
*array_ref!(decoded, 0, 12)
}
pub fn is_archive(&self) -> bool {
self.mime.to_lowercase() == MIME_TAR.to_lowercase()
}
}