use std::io::Cursor;
use crate::container::{self, KeyDerivation, PayloadType};
use crate::crypto::Key;
use crate::kdf::KdfParams;
use crate::padding::Padding;
pub const ARGON_SALT: [u8; 32] = [0x11; 32];
pub const OBJECT_SALT: [u8; 32] = [0x22; 32];
pub const MASTER_KEY: [u8; 32] = [0x42; 32];
pub const HKDF_OBJECT_SALT: [u8; 32] = [0x33; 32];
pub const KDF_PARAMS: KdfParams = KdfParams {
m_cost_kib: 8 * 1024,
t_cost: 1,
p_cost: 1,
};
pub fn standalone(password: &str, plaintext: &[u8], original_name: &str) -> Vec<u8> {
let kd = KeyDerivation::Password {
argon_salt: ARGON_SALT,
object_salt: OBJECT_SALT,
params: KDF_PARAMS,
};
let mut out = Vec::new();
let mut src = Cursor::new(plaintext);
container::write_container(
&mut out,
&kd,
Some(password),
None,
PayloadType::File,
b"",
Some(&mut src),
Some(original_name),
Padding::None,
None,
)
.expect("deterministic vector construction cannot fail");
out
}
pub fn hkdf_file(plaintext: &[u8], identity: &str) -> Vec<u8> {
let master = Key::from_bytes(MASTER_KEY);
let kd = KeyDerivation::Hkdf {
object_salt: HKDF_OBJECT_SALT,
};
let mut out = Vec::new();
let mut src = Cursor::new(plaintext);
container::write_container(
&mut out,
&kd,
None,
Some(&master),
PayloadType::File,
identity.as_bytes(),
Some(&mut src),
None,
Padding::None,
None,
)
.expect("deterministic vector construction cannot fail");
out
}
pub fn manifest(json: &[u8]) -> Vec<u8> {
let master = Key::from_bytes(MASTER_KEY);
let kd = KeyDerivation::Hkdf {
object_salt: HKDF_OBJECT_SALT,
};
let mut out = Vec::new();
let mut src = Cursor::new(json);
container::write_container(
&mut out,
&kd,
None,
Some(&master),
PayloadType::Manifest,
b"vault-manifest",
Some(&mut src),
None,
Padding::None,
None,
)
.expect("deterministic vector construction cannot fail");
out
}