use crate::core::helpers;
use crate::handler::types::{DecryptOutput, EncryptOutput, LibrageResponse};
use age::scrypt;
pub fn encrypt_with_passphrase(
plaintext: &[u8],
passphrase: &str,
) -> LibrageResponse<EncryptOutput> {
let recipient = scrypt::Recipient::new(passphrase.into());
let mut ciphertext = Vec::new();
match helpers::encrypt_to_writer(plaintext, &[Box::new(recipient)], &mut ciphertext) {
Ok(_) => LibrageResponse::ok(EncryptOutput::new(ciphertext, false)),
Err(e) => LibrageResponse::err(e.into()),
}
}
pub fn decrypt_with_passphrase(
ciphertext: &[u8],
passphrase: &str,
) -> LibrageResponse<DecryptOutput> {
let identity = scrypt::Identity::new(passphrase.into());
match helpers::decrypt_to_vec(ciphertext, &[Box::new(identity)]) {
Ok(plaintext) => LibrageResponse::ok(DecryptOutput::new(plaintext)),
Err(e) => LibrageResponse::err(e.into()),
}
}