crypto: Improve error for missing passphrase

This commit is contained in:
Alexis Sellier 2023-07-24 12:27:45 +02:00
parent de381cb378
commit 60cc0a8d01
No known key found for this signature in database
1 changed files with 4 additions and 0 deletions

View File

@ -23,6 +23,8 @@ pub enum Error {
InvalidKeyType,
#[error("keystore already initialized")]
AlreadyInitialized,
#[error("keystore is encrypted; a passphrase is required")]
PassphraseMissing,
}
impl Error {
@ -123,6 +125,8 @@ impl Keystore {
let secret = ssh_key::PrivateKey::read_openssh_file(&path)?;
let secret = if let Some(p) = passphrase {
secret.decrypt(p)?
} else if secret.is_encrypted() {
return Err(Error::PassphraseMissing);
} else {
secret
};