diff options
author | Neal H. Walfield <neal@pep.foundation> | 2019-03-11 10:09:39 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2019-03-11 10:09:39 +0100 |
commit | 8d280b4cf59ab57c2e7fa63614e3672277654749 (patch) | |
tree | 8470de1ca13c17639eb62f2e7ad0c2d3cf02e672 /openpgp-ffi | |
parent | 06b7e5c0d508e2053e1de20ef7f4522289b54cc9 (diff) |
openpgp-ffi: Improve error message
Diffstat (limited to 'openpgp-ffi')
-rw-r--r-- | openpgp-ffi/src/packet/pkesk.rs | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/openpgp-ffi/src/packet/pkesk.rs b/openpgp-ffi/src/packet/pkesk.rs index 36af7c0d..34527870 100644 --- a/openpgp-ffi/src/packet/pkesk.rs +++ b/openpgp-ffi/src/packet/pkesk.rs @@ -44,24 +44,31 @@ pub extern "system" fn pgp_pkesk_decrypt(errp: Option<&mut *mut ::error::Error>, let algo = ffi_param_ref_mut!(algo); let key_len = ffi_param_ref_mut!(key_len); - if let Some(SecretKey::Unencrypted{ mpis: ref secret_part }) = secret_key.secret() { - match pkesk.decrypt(secret_key, secret_part) { - Ok((a, k)) => { - *algo = a.into(); - if !key.is_null() && *key_len >= k.len() { - unsafe { - ::std::ptr::copy(k.as_ptr(), - key, - k.len()); + match secret_key.secret() { + Some(SecretKey::Unencrypted{ mpis: secret_parts }) => { + match pkesk.decrypt(secret_key, secret_parts) { + Ok((a, k)) => { + *algo = a.into(); + if !key.is_null() && *key_len >= k.len() { + unsafe { + ::std::ptr::copy(k.as_ptr(), + key, + k.len()); + } } - } - *key_len = k.len(); - Status::Success - }, - Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)), + *key_len = k.len(); + Status::Success + }, + Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)), + } + } + Some(thing @ SecretKey::Encrypted{ .. }) => { + // XXX: Better message, don't panic. + panic!("Secret parts not unencrypted: {:?}", thing); + } + None => { + // XXX: Better message, don't panic. + panic!("No secret parts: {:?}", secret_key.secret()); } - } else { - // XXX: Better message. - panic!("No secret parts"); } } |