diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-01-17 11:11:27 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-01-17 16:48:28 +0100 |
commit | 3f58832474a4b270e136544016a401ef773ac065 (patch) | |
tree | c617160250c3040ca964c1b72ab5957cd872b82f /openpgp-ffi/src/crypto.rs | |
parent | 38b4108cc1eac851ac17932c5c33623dd535bebb (diff) |
openpgp-ffi: New crate.
- This creates a new crate, 'sequoia-openpgp-ffi', and moves a
handful of functions from 'sequoia-ffi' to it.
- The 'sequoia-ffi' crate is a superset of the 'sequoia-openpgp-ffi'
crate. This is accomplished by some include! magic.
- My first attempt involved having 'sequoia-ffi' depend on
'sequoia-openpgp-ffi', so that the former just re-exports the
symbols. However, that turned out to be unreliable, and might be
not what we want, because it could also duplicate parts of Rust's
standard library.
- Fixes #144.
Diffstat (limited to 'openpgp-ffi/src/crypto.rs')
-rw-r--r-- | openpgp-ffi/src/crypto.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/openpgp-ffi/src/crypto.rs b/openpgp-ffi/src/crypto.rs new file mode 100644 index 00000000..5b695ec7 --- /dev/null +++ b/openpgp-ffi/src/crypto.rs @@ -0,0 +1,54 @@ +//! Cryptographic primitives. +//! +//! Wraps [`sequoia-openpgp::crypto`]. +//! +//! [`sequoia-openpgp::crypto`]: ../../../sequoia_openpgp/crypto/index.html + +extern crate sequoia_openpgp; +use self::sequoia_openpgp::{ + crypto, + packet::Key, +}; + +/// Frees a signer. +#[::ffi_catch_abort] #[no_mangle] +pub extern "system" fn sq_signer_free + (s: Option<&mut &'static mut crypto::Signer>) +{ + ffi_free!(s) +} + +/// Creates a new key pair. +#[::ffi_catch_abort] #[no_mangle] +pub extern "system" fn sq_key_pair_new + (errp: Option<&mut *mut failure::Error>, public: *mut Key, secret: *mut crypto::mpis::SecretKey) + -> *mut crypto::KeyPair +{ + ffi_make_fry_from_errp!(errp); + let public = ffi_param_move!(public); + let secret = ffi_param_move!(secret); + ffi_try_box!(crypto::KeyPair::new(*public, *secret)) +} + +/// Frees a key pair. +#[::ffi_catch_abort] #[no_mangle] +pub extern "system" fn sq_key_pair_free + (kp: Option<&mut crypto::KeyPair>) +{ + ffi_free!(kp) +} + +/// Creates a signer from a key pair. +/// +/// Note that the returned object merely references the key pair, and +/// must not outlive the key pair. +#[::ffi_catch_abort] #[no_mangle] +pub extern "system" fn sq_key_pair_as_signer + (kp: *mut crypto::KeyPair) + -> *mut &'static mut crypto::Signer +{ + let kp = ffi_param_ref_mut!(kp); + let signer: &mut crypto::Signer = kp; + box_raw!(signer) + //box_raw!(kp) +} |