From e4553d9a5207ffd471a186a8f59da82d0b18c562 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Tue, 7 May 2019 11:53:30 +0200 Subject: openpgp-ffi: Fix int to cipher suite conversion - Factor out the code so it can be used elsewhere. - Map all CipherSuites. --- openpgp-ffi/src/tpk.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'openpgp-ffi') 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_); } -- cgit v1.2.3