container read AES key

master
Avril 4 years ago
parent 5b0c4e7ae0
commit 807fab34a2
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -120,11 +120,11 @@ impl Password
{
/// Consume into real password
#[instrument]
pub fn into_password(self) -> eyre::Result<Option<String>>
pub fn into_password(self, prompt: impl AsRef<str>) -> eyre::Result<Option<String>>
{
Ok(match self {
Self::No => None,
Self::Yes => Some(read_password()?),
Self::Yes => Some(read_password(prompt.as_ref())?),
Self::Specific(passwd) => Some(passwd),
})
}
@ -132,8 +132,8 @@ impl Password
/// Read password from stdin
#[instrument(err)]
fn read_password() -> eyre::Result<String>
fn read_password(prompt: &str) -> eyre::Result<String>
{
rpassword::read_password()
rpassword::prompt_password_stderr(prompt)
.wrap_err(eyre!("Failed to read password from stdin"))
}

@ -14,10 +14,10 @@ use tokio::{
///
/// Detect the container type if possible and then decode the AES key. Returning it as `format::key::aes::AesBody`.
#[instrument(skip(path), err, fields(path = ?path.as_ref()))]
pub async fn read_aes_container(path: impl AsRef<Path>, passwd: config::op::Password) -> eyre::Result<format::key::aes::AesBody>
pub async fn read_aes_container(path: impl AsRef<Path>, passwd: (config::op::Password, Option<&str>)) -> eyre::Result<format::key::aes::AesBody>
{
// password function
let passwd = passwd.into_password()?;
let passwd = passwd.0.into_password(passwd.1.unwrap_or("Enter password for input key: "))?;
macro_rules! passwdfn {
() => (|salt| passwd.as_ref().map(|string| crypto::password::Password::derive(string, salt)))
}

@ -191,12 +191,17 @@ async fn work(op: config::Operation) -> Result<(), eyre::Report>
match op {
config::Operation::Help => args::usage(),
config::Operation::GenerateKey(config::op::GenerateKey::Aes(aes)) => {
// read input aes key if provided
let input_aes = match aes.input {
Some((path, passwd)) => {
Some(container::aes::read_aes_container(&path, (passwd, None)).await
.wrap_err(eyre!("Failed to read input AES container from file"))
.with_section(|| format!("{:?}", path).header("Path was"))?)
},
_ => (),
_ => None,
};
//TODO: Generate new key
//TODO: Save new key to file, in provided format, with password if needed
},
config::Operation::GenerateKey(config::op::GenerateKey::Rsa(rsa)) => {

Loading…
Cancel
Save