Move decryption handlers to functions
This commit is contained in:
parent
8a09da764e
commit
67aa009746
1 changed files with 55 additions and 51 deletions
|
@ -86,7 +86,15 @@ pub fn decrypt(
|
||||||
ContentType::Image => DecryptedData::Image(blob, container.len()),
|
ContentType::Image => DecryptedData::Image(blob, container.len()),
|
||||||
ContentType::Audio => DecryptedData::Audio(blob),
|
ContentType::Audio => DecryptedData::Audio(blob),
|
||||||
ContentType::Video => DecryptedData::Video(blob),
|
ContentType::Video => DecryptedData::Video(blob),
|
||||||
ContentType::ZipArchive => {
|
ContentType::ZipArchive => handle_zip_archive(blob, container),
|
||||||
|
ContentType::Gzip => handle_gzip(blob, container),
|
||||||
|
ContentType::Unknown => DecryptedData::Blob(blob),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok((data, MimeType(mime_type.to_owned())))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_zip_archive(blob: Arc<Blob>, container: Vec<u8>) -> DecryptedData {
|
||||||
let mut entries = vec![];
|
let mut entries = vec![];
|
||||||
let cursor = Cursor::new(container);
|
let cursor = Cursor::new(container);
|
||||||
if let Ok(mut zip) = zip::ZipArchive::new(cursor) {
|
if let Ok(mut zip) = zip::ZipArchive::new(cursor) {
|
||||||
|
@ -110,8 +118,9 @@ pub fn decrypt(
|
||||||
|
|
||||||
entries.sort_by(|a, b| a.name.cmp(&b.name));
|
entries.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
DecryptedData::Archive(blob, entries)
|
DecryptedData::Archive(blob, entries)
|
||||||
}
|
}
|
||||||
ContentType::Gzip => {
|
|
||||||
|
fn handle_gzip(blob: Arc<Blob>, container: Vec<u8>) -> DecryptedData {
|
||||||
let mut entries = vec![];
|
let mut entries = vec![];
|
||||||
let cursor = Cursor::new(container);
|
let cursor = Cursor::new(container);
|
||||||
let gzip_dec = flate2::read::GzDecoder::new(cursor);
|
let gzip_dec = flate2::read::GzDecoder::new(cursor);
|
||||||
|
@ -136,11 +145,6 @@ pub fn decrypt(
|
||||||
} else {
|
} else {
|
||||||
DecryptedData::Blob(blob)
|
DecryptedData::Blob(blob)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ContentType::Unknown => DecryptedData::Blob(blob),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((data, MimeType(mime_type.to_owned())))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
|
Loading…
Reference in a new issue