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