str4d / wage

A WASM package and web app for encrypting and decrypting age-encrypted files, powered by rage.
https://rage-encry.pt
Apache License 2.0
76 stars 10 forks source link

Recipent decryption #2

Closed str4d closed 3 years ago

str4d commented 4 years ago

This should take a decryptor and a list of identity files, and return the same value as decrypt_with_passphrase:

#[wasm_bindgen]
pub async decrypt_with_identities(decryptor: u32, identities: &[web_sys::File]) -> Result<JsValue, JsValue> {}
fubuloubu commented 4 years ago

I started looking at this, age::keys::Identity::from_buffer() requires std::io::BufRead. Can we get that from web_sys::File?

str4d commented 4 years ago

File.stream() returns ReadableStream, which we can wrap with StreamReader to get something implementing AsyncRead (as with the file being decrypted), but not the blocking BufRead. I think what we eventually want is an equivalent Identity::from_async_buffer in age, but we could also manually read each identity into a secrecy::SecretVec and then pass those through Identity::from_buffer.

pirate commented 4 years ago

Not sure if this issue is the right place for it, but if you need a snippet for this TODO in the readme Expose a Rust stream to JavaScript as a user-downloadable file., this one works well:

function download(content, filename, contentType) {
    contentType = contentType || 'application/octet-stream'
    const anchor = document.createElement('a')
    const blob = new Blob([content], {'type': contentType})
    anchor.href = window.URL.createObjectURL(blob)
    anchor.download = filename
    anchor.click()
}
str4d commented 3 years ago

Implemented in #25.