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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
extern crate hyper;
use std::fmt;
use mime_guess::Mime;
use reqwest::header::{
Formatter as HeaderFormatter,
Header,
Raw,
};
use self::hyper::error::Error as HyperError;
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()
}
}
#[derive(Clone)]
pub struct XFileMetadata {
metadata: String,
}
impl XFileMetadata {
pub fn from(bytes: &[u8]) -> Self {
XFileMetadata {
metadata: b64::encode(bytes),
}
}
}
impl Header for XFileMetadata {
fn header_name() -> &'static str {
"X-File-Metadata"
}
fn parse_header(_raw: &Raw) -> Result<Self, HyperError> {
unimplemented!();
}
fn fmt_header(&self, f: &mut HeaderFormatter) -> fmt::Result {
f.fmt_line(&self.metadata)
}
}