summaryrefslogtreecommitdiffstats
path: root/ffi/src
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-10 11:12:35 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-10 14:41:50 +0100
commitb3a4ad197f84b22883c2c2f4114b0e3472af60ee (patch)
tree470a64ce9d057ff5aa2f29619b6bd008c6fabcdb /ffi/src
parent14856cf73c4fe0afb7b6b6d752aab81ff7f94b74 (diff)
ffi: New module openpgp/crypto.
Diffstat (limited to 'ffi/src')
-rw-r--r--ffi/src/openpgp/crypto.rs56
-rw-r--r--ffi/src/openpgp/mod.rs1
2 files changed, 57 insertions, 0 deletions
diff --git a/ffi/src/openpgp/crypto.rs b/ffi/src/openpgp/crypto.rs
new file mode 100644
index 00000000..4236568f
--- /dev/null
+++ b/ffi/src/openpgp/crypto.rs
@@ -0,0 +1,56 @@
+//! Cryptographic primitives.
+//!
+//! Wraps [`sequoia-openpgp::crypto`].
+//!
+//! [`sequoia-openpgp::crypto`]: ../../../sequoia_openpgp/crypto/index.html
+
+use ::core::Context;
+
+extern crate sequoia_openpgp;
+use self::sequoia_openpgp::{
+ crypto,
+ packet::Key,
+};
+
+/// Frees a signer.
+#[no_mangle]
+pub extern "system" fn sq_signer_free
+ (s: Option<&mut &'static mut crypto::Signer>)
+{
+ ffi_free!(s)
+}
+
+/// Creates a new key pair.
+#[no_mangle]
+pub extern "system" fn sq_key_pair_new
+ (ctx: *mut Context, public: *mut Key, secret: *mut crypto::mpis::SecretKey)
+ -> *mut crypto::KeyPair
+{
+ let ctx = ffi_param_ref_mut!(ctx);
+ let public = ffi_param_move!(public);
+ let secret = ffi_param_move!(secret);
+ fry_box!(ctx, crypto::KeyPair::new(*public, *secret))
+}
+
+/// Frees a key pair.
+#[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.
+#[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)
+}
diff --git a/ffi/src/openpgp/mod.rs b/ffi/src/openpgp/mod.rs
index 2a663763..1f5081e6 100644
--- a/ffi/src/openpgp/mod.rs
+++ b/ffi/src/openpgp/mod.rs
@@ -54,6 +54,7 @@ use super::error::Status;
use super::core::Context;
pub mod armor;
+pub mod crypto;
pub mod fingerprint;
pub mod keyid;
pub mod packet_pile;