cleanup: KeyConfig::decrypt - show password hint on error

This commit is contained in:
Dietmar Maurer
2021-01-21 07:13:56 +01:00
parent f490dda05a
commit 8428063d9e
2 changed files with 12 additions and 15 deletions

View File

@ -216,7 +216,7 @@ impl KeyConfig {
let derived_key = kdf.derive_key(&passphrase)?;
if raw_data.len() < 32 {
bail!("Unable to encode key - short data");
bail!("Unable to decrypt key - short data");
}
let iv = &raw_data[0..16];
let tag = &raw_data[16..32];
@ -231,7 +231,16 @@ impl KeyConfig {
b"",
&enc_data,
&tag,
).map_err(|err| format_err!("Unable to decrypt key (wrong password?) - {}", err))?
).map_err(|err| {
match self.hint {
Some(ref hint) => {
format_err!("Unable to decrypt key (password hint: {})", hint)
}
None => {
format_err!("Unable to decrypt key (wrong password?) - {}", err)
}
}
})?
} else {
raw_data.clone()