crypto: Improve error for missing passphrase
This commit is contained in:
parent
de381cb378
commit
60cc0a8d01
|
|
@ -23,6 +23,8 @@ pub enum Error {
|
||||||
InvalidKeyType,
|
InvalidKeyType,
|
||||||
#[error("keystore already initialized")]
|
#[error("keystore already initialized")]
|
||||||
AlreadyInitialized,
|
AlreadyInitialized,
|
||||||
|
#[error("keystore is encrypted; a passphrase is required")]
|
||||||
|
PassphraseMissing,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
|
@ -123,6 +125,8 @@ impl Keystore {
|
||||||
let secret = ssh_key::PrivateKey::read_openssh_file(&path)?;
|
let secret = ssh_key::PrivateKey::read_openssh_file(&path)?;
|
||||||
let secret = if let Some(p) = passphrase {
|
let secret = if let Some(p) = passphrase {
|
||||||
secret.decrypt(p)?
|
secret.decrypt(p)?
|
||||||
|
} else if secret.is_encrypted() {
|
||||||
|
return Err(Error::PassphraseMissing);
|
||||||
} else {
|
} else {
|
||||||
secret
|
secret
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue