Compare commits
2 commits
d2755f82c9
...
06a9522514
Author | SHA1 | Date | |
---|---|---|---|
06a9522514 | |||
372a160558 |
3 changed files with 64 additions and 56 deletions
|
@ -22,11 +22,15 @@ struct Opts {
|
|||
#[derive(Parser)]
|
||||
enum Action {
|
||||
Upload {
|
||||
/// The OmegaUpload instance to upload data to.
|
||||
url: Url,
|
||||
/// Encrypt the uploaded paste with the provided password, preventing
|
||||
/// public access.
|
||||
#[clap(short, long)]
|
||||
password: Option<SecretString>,
|
||||
},
|
||||
Download {
|
||||
/// The paste to download.
|
||||
url: ParsedUrl,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -39,13 +39,12 @@ pub fn decrypt(
|
|||
nonce: Nonce,
|
||||
maybe_password: Option<Key>,
|
||||
) -> Result<DecryptedData, PasteCompleteConstructionError> {
|
||||
let container = &mut container;
|
||||
log!("Stage 1 decryption started.");
|
||||
let start = now();
|
||||
|
||||
if let Some(password) = maybe_password {
|
||||
crate::render_message("Decrypting Stage 1...".into());
|
||||
open_in_place(container, &nonce.increment(), &password).map_err(|_| {
|
||||
open_in_place(&mut container, &nonce.increment(), &password).map_err(|_| {
|
||||
crate::render_message("Unable to decrypt paste with the provided password.".into());
|
||||
PasteCompleteConstructionError::StageOneFailure
|
||||
})?;
|
||||
|
@ -55,7 +54,7 @@ pub fn decrypt(
|
|||
log!("Stage 2 decryption started.");
|
||||
let start = now();
|
||||
crate::render_message("Decrypting Stage 2...".into());
|
||||
open_in_place(container, &nonce, &key).map_err(|_| {
|
||||
open_in_place(&mut container, &nonce, &key).map_err(|_| {
|
||||
crate::render_message(
|
||||
"Unable to decrypt paste with the provided encryption key and nonce.".into(),
|
||||
);
|
||||
|
@ -63,10 +62,7 @@ pub fn decrypt(
|
|||
})?;
|
||||
log!(format!("Stage 2 completed in {}ms", now() - start));
|
||||
|
||||
if let Ok(decrypted) = std::str::from_utf8(container) {
|
||||
Ok(DecryptedData::String(Arc::new(decrypted.to_owned())))
|
||||
} else {
|
||||
let mime_type = tree_magic_mini::from_u8(container);
|
||||
let mime_type = tree_magic_mini::from_u8(&container);
|
||||
log!("Mimetype: ", mime_type);
|
||||
|
||||
log!("Blob conversion started.");
|
||||
|
@ -80,15 +76,17 @@ pub fn decrypt(
|
|||
let mut blob_props = BlobPropertyBag::new();
|
||||
blob_props.type_(mime_type);
|
||||
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(),
|
||||
);
|
||||
log!(format!("Blob conversion completed in {}ms", now() - start));
|
||||
|
||||
if mime_type.starts_with("image/") || mime_type == "application/x-riff" {
|
||||
if mime_type.starts_with("text/") {
|
||||
String::from_utf8(container)
|
||||
.map(Arc::new)
|
||||
.map(DecryptedData::String)
|
||||
.map_err(|_| PasteCompleteConstructionError::InvalidEncoding)
|
||||
} else if mime_type.starts_with("image/") || mime_type == "application/x-riff" {
|
||||
Ok(DecryptedData::Image(blob, container.len()))
|
||||
} else if mime_type.starts_with("audio/") {
|
||||
Ok(DecryptedData::Audio(blob))
|
||||
|
@ -123,12 +121,12 @@ pub fn decrypt(
|
|||
Ok(DecryptedData::Blob(blob))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PasteCompleteConstructionError {
|
||||
StageOneFailure,
|
||||
StageTwoFailure,
|
||||
InvalidEncoding,
|
||||
}
|
||||
|
||||
impl std::error::Error for PasteCompleteConstructionError {}
|
||||
|
@ -142,6 +140,10 @@ impl Display for PasteCompleteConstructionError {
|
|||
PasteCompleteConstructionError::StageTwoFailure => {
|
||||
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,6 +177,8 @@ function createArchivePasteUi({ expiration, data, entries }) {
|
|||
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) => {
|
||||
return b.name.includes("/") - a.name.includes("/");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue