summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-05-07 11:53:30 +0200
committerNeal H. Walfield <neal@pep.foundation>2019-05-07 12:18:43 +0200
commite4553d9a5207ffd471a186a8f59da82d0b18c562 (patch)
treea90ebb67aeae96f7b78b9b954913ea99c1154505 /openpgp-ffi
parent576b4d68aa046ccac9ff0b9c275c7a0413cc417a (diff)
openpgp-ffi: Fix int to cipher suite conversion
- Factor out the code so it can be used elsewhere. - Map all CipherSuites.
Diffstat (limited to 'openpgp-ffi')
-rw-r--r--openpgp-ffi/src/tpk.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/openpgp-ffi/src/tpk.rs b/openpgp-ffi/src/tpk.rs
index 060715bc..2083add9 100644
--- a/openpgp-ffi/src/tpk.rs
+++ b/openpgp-ffi/src/tpk.rs
@@ -739,20 +739,28 @@ pub extern "system" fn pgp_tpk_builder_free(tpkb: Option<&mut TPKBuilder>)
ffi_free!(tpkb)
}
+fn int_to_cipher_suite(cs: c_int) -> CipherSuite {
+ use self::CipherSuite::*;
+
+ match cs {
+ 0 => Cv25519,
+ 1 => RSA3k,
+ 2 => P256,
+ 3 => P384,
+ 4 => P521,
+ n => panic!("Bad ciphersuite: {}", n),
+ }
+}
+
/// Sets the encryption and signature algorithms for primary and all
/// subkeys.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "system" fn pgp_tpk_builder_set_cipher_suite
(tpkb: *mut *mut TPKBuilder, cs: c_int)
{
- use self::CipherSuite::*;
let tpkb = ffi_param_ref_mut!(tpkb);
let tpkb_ = ffi_param_move!(*tpkb);
- let cs = match cs {
- 0 => Cv25519,
- 1 => RSA3k,
- n => panic!("Bad ciphersuite: {}", n),
- };
+ let cs = int_to_cipher_suite(cs);
let tpkb_ = tpkb_.set_cipher_suite(cs);
*tpkb = box_raw!(tpkb_);
}