Compare commits
No commits in common. "06a952251443742f45e731dd6e47b683d589c62b" and "d2755f82c94c3951f34e5aece06e1ce9457c2fe4" have entirely different histories.
06a9522514
...
d2755f82c9
3 changed files with 56 additions and 64 deletions
|
@ -22,15 +22,11 @@ struct Opts {
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
enum Action {
|
enum Action {
|
||||||
Upload {
|
Upload {
|
||||||
/// The OmegaUpload instance to upload data to.
|
|
||||||
url: Url,
|
url: Url,
|
||||||
/// Encrypt the uploaded paste with the provided password, preventing
|
|
||||||
/// public access.
|
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
password: Option<SecretString>,
|
password: Option<SecretString>,
|
||||||
},
|
},
|
||||||
Download {
|
Download {
|
||||||
/// The paste to download.
|
|
||||||
url: ParsedUrl,
|
url: ParsedUrl,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,12 +39,13 @@ pub fn decrypt(
|
||||||
nonce: Nonce,
|
nonce: Nonce,
|
||||||
maybe_password: Option<Key>,
|
maybe_password: Option<Key>,
|
||||||
) -> Result<DecryptedData, PasteCompleteConstructionError> {
|
) -> Result<DecryptedData, PasteCompleteConstructionError> {
|
||||||
|
let container = &mut container;
|
||||||
log!("Stage 1 decryption started.");
|
log!("Stage 1 decryption started.");
|
||||||
let start = now();
|
let start = now();
|
||||||
|
|
||||||
if let Some(password) = maybe_password {
|
if let Some(password) = maybe_password {
|
||||||
crate::render_message("Decrypting Stage 1...".into());
|
crate::render_message("Decrypting Stage 1...".into());
|
||||||
open_in_place(&mut container, &nonce.increment(), &password).map_err(|_| {
|
open_in_place(container, &nonce.increment(), &password).map_err(|_| {
|
||||||
crate::render_message("Unable to decrypt paste with the provided password.".into());
|
crate::render_message("Unable to decrypt paste with the provided password.".into());
|
||||||
PasteCompleteConstructionError::StageOneFailure
|
PasteCompleteConstructionError::StageOneFailure
|
||||||
})?;
|
})?;
|
||||||
|
@ -54,7 +55,7 @@ pub fn decrypt(
|
||||||
log!("Stage 2 decryption started.");
|
log!("Stage 2 decryption started.");
|
||||||
let start = now();
|
let start = now();
|
||||||
crate::render_message("Decrypting Stage 2...".into());
|
crate::render_message("Decrypting Stage 2...".into());
|
||||||
open_in_place(&mut container, &nonce, &key).map_err(|_| {
|
open_in_place(container, &nonce, &key).map_err(|_| {
|
||||||
crate::render_message(
|
crate::render_message(
|
||||||
"Unable to decrypt paste with the provided encryption key and nonce.".into(),
|
"Unable to decrypt paste with the provided encryption key and nonce.".into(),
|
||||||
);
|
);
|
||||||
|
@ -62,63 +63,65 @@ pub fn decrypt(
|
||||||
})?;
|
})?;
|
||||||
log!(format!("Stage 2 completed in {}ms", now() - start));
|
log!(format!("Stage 2 completed in {}ms", now() - start));
|
||||||
|
|
||||||
let mime_type = tree_magic_mini::from_u8(&container);
|
if let Ok(decrypted) = std::str::from_utf8(container) {
|
||||||
log!("Mimetype: ", mime_type);
|
Ok(DecryptedData::String(Arc::new(decrypted.to_owned())))
|
||||||
|
} else {
|
||||||
|
let mime_type = tree_magic_mini::from_u8(container);
|
||||||
|
log!("Mimetype: ", mime_type);
|
||||||
|
|
||||||
log!("Blob conversion started.");
|
log!("Blob conversion started.");
|
||||||
let start = now();
|
let start = now();
|
||||||
let blob_chunks = Array::new_with_length(container.chunks(65536).len().try_into().unwrap());
|
let blob_chunks = Array::new_with_length(container.chunks(65536).len().try_into().unwrap());
|
||||||
for (i, chunk) in container.chunks(65536).enumerate() {
|
for (i, chunk) in container.chunks(65536).enumerate() {
|
||||||
let array = Uint8Array::new_with_length(chunk.len().try_into().unwrap());
|
let array = Uint8Array::new_with_length(chunk.len().try_into().unwrap());
|
||||||
array.copy_from(chunk);
|
array.copy_from(chunk);
|
||||||
blob_chunks.set(i.try_into().unwrap(), array.dyn_into().unwrap());
|
blob_chunks.set(i.try_into().unwrap(), array.dyn_into().unwrap());
|
||||||
}
|
}
|
||||||
let mut blob_props = BlobPropertyBag::new();
|
let mut blob_props = BlobPropertyBag::new();
|
||||||
blob_props.type_(mime_type);
|
blob_props.type_(mime_type);
|
||||||
let blob = Arc::new(
|
let blob = Arc::new(
|
||||||
Blob::new_with_u8_array_sequence_and_options(blob_chunks.dyn_ref().unwrap(), &blob_props)
|
Blob::new_with_u8_array_sequence_and_options(
|
||||||
|
blob_chunks.dyn_ref().unwrap(),
|
||||||
|
&blob_props,
|
||||||
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
log!(format!("Blob conversion completed in {}ms", now() - start));
|
log!(format!("Blob conversion completed in {}ms", now() - start));
|
||||||
|
|
||||||
if mime_type.starts_with("text/") {
|
if mime_type.starts_with("image/") || mime_type == "application/x-riff" {
|
||||||
String::from_utf8(container)
|
Ok(DecryptedData::Image(blob, container.len()))
|
||||||
.map(Arc::new)
|
} else if mime_type.starts_with("audio/") {
|
||||||
.map(DecryptedData::String)
|
Ok(DecryptedData::Audio(blob))
|
||||||
.map_err(|_| PasteCompleteConstructionError::InvalidEncoding)
|
} else if mime_type.starts_with("video/") || mime_type == "application/x-matroska" {
|
||||||
} else if mime_type.starts_with("image/") || mime_type == "application/x-riff" {
|
Ok(DecryptedData::Video(blob))
|
||||||
Ok(DecryptedData::Image(blob, container.len()))
|
} else if mime_type == "application/zip" {
|
||||||
} else if mime_type.starts_with("audio/") {
|
let mut entries = vec![];
|
||||||
Ok(DecryptedData::Audio(blob))
|
let cursor = Cursor::new(container);
|
||||||
} else if mime_type.starts_with("video/") || mime_type == "application/x-matroska" {
|
if let Ok(mut zip) = zip::ZipArchive::new(cursor) {
|
||||||
Ok(DecryptedData::Video(blob))
|
for i in 0..zip.len() {
|
||||||
} else if mime_type == "application/zip" {
|
match zip.by_index(i) {
|
||||||
let mut entries = vec![];
|
Ok(file) => entries.push(ArchiveMeta {
|
||||||
let cursor = Cursor::new(container);
|
name: file.name().to_string(),
|
||||||
if let Ok(mut zip) = zip::ZipArchive::new(cursor) {
|
file_size: file.size() as usize,
|
||||||
for i in 0..zip.len() {
|
}),
|
||||||
match zip.by_index(i) {
|
Err(err) => match err {
|
||||||
Ok(file) => entries.push(ArchiveMeta {
|
zip::result::ZipError::UnsupportedArchive(s) => {
|
||||||
name: file.name().to_string(),
|
log!("Unsupported: ", s.to_string());
|
||||||
file_size: file.size() as usize,
|
}
|
||||||
}),
|
_ => {
|
||||||
Err(err) => match err {
|
log!(format!("Error: {}", err));
|
||||||
zip::result::ZipError::UnsupportedArchive(s) => {
|
}
|
||||||
log!("Unsupported: ", s.to_string());
|
},
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
log!(format!("Error: {}", err));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(DecryptedData::Archive(blob, entries))
|
||||||
|
} else if mime_type == "application/gzip" {
|
||||||
|
let entries = vec![];
|
||||||
|
Ok(DecryptedData::Archive(blob, entries))
|
||||||
|
} else {
|
||||||
|
Ok(DecryptedData::Blob(blob))
|
||||||
}
|
}
|
||||||
Ok(DecryptedData::Archive(blob, entries))
|
|
||||||
} else if mime_type == "application/gzip" {
|
|
||||||
let entries = vec![];
|
|
||||||
Ok(DecryptedData::Archive(blob, entries))
|
|
||||||
} else {
|
|
||||||
Ok(DecryptedData::Blob(blob))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +129,6 @@ pub fn decrypt(
|
||||||
pub enum PasteCompleteConstructionError {
|
pub enum PasteCompleteConstructionError {
|
||||||
StageOneFailure,
|
StageOneFailure,
|
||||||
StageTwoFailure,
|
StageTwoFailure,
|
||||||
InvalidEncoding,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for PasteCompleteConstructionError {}
|
impl std::error::Error for PasteCompleteConstructionError {}
|
||||||
|
@ -140,10 +142,6 @@ impl Display for PasteCompleteConstructionError {
|
||||||
PasteCompleteConstructionError::StageTwoFailure => {
|
PasteCompleteConstructionError::StageTwoFailure => {
|
||||||
write!(f, "Failed to decrypt stage two.")
|
write!(f, "Failed to decrypt stage two.")
|
||||||
}
|
}
|
||||||
PasteCompleteConstructionError::InvalidEncoding => write!(
|
|
||||||
f,
|
|
||||||
"Got an file with a text/* mime type, but was unable to parsed as valid UTF-8?"
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,8 +177,6 @@ function createArchivePasteUi({ expiration, data, entries }) {
|
||||||
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
// This doesn't get sub directories and their folders, but hey it's close
|
|
||||||
// enough
|
|
||||||
entries.sort((a, b) => {
|
entries.sort((a, b) => {
|
||||||
return b.name.includes("/") - a.name.includes("/");
|
return b.name.includes("/") - a.name.includes("/");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue