summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/src/crypto.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-03-25 15:22:56 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-03-25 16:54:11 +0100
commitf572bc851d520a56eebb0a6cea38144051168a8a (patch)
treefd592f520343bed4a572fe97ee3cf5d1620ea006 /openpgp-ffi/src/crypto.rs
parent9e9d3f773d85049daece18cb5488451b76c94d2e (diff)
openpgp-ffi: Wrap crypto::SessionKey and crypto::Password.
Diffstat (limited to 'openpgp-ffi/src/crypto.rs')
-rw-r--r--openpgp-ffi/src/crypto.rs48
1 files changed, 46 insertions, 2 deletions
diff --git a/openpgp-ffi/src/crypto.rs b/openpgp-ffi/src/crypto.rs
index 7a453b60..540bcfd4 100644
--- a/openpgp-ffi/src/crypto.rs
+++ b/openpgp-ffi/src/crypto.rs
@@ -4,13 +4,57 @@
//!
//! [`sequoia-openpgp::crypto`]: ../../sequoia_openpgp/crypto/index.html
-extern crate sequoia_openpgp;
-use self::sequoia_openpgp::{
+use libc::{size_t, uint8_t};
+use nettle::Yarrow;
+
+extern crate sequoia_openpgp as openpgp;
+use self::openpgp::{
crypto,
};
use super::packet::key::Key;
use MoveFromRaw;
+use MoveIntoRaw;
+
+/// Holds a session key.
+///
+/// The session key is cleared when dropped.
+#[::ffi_wrapper_type(prefix = "pgp_", name = "session_key",
+ derive = "Clone, Debug, PartialEq")]
+pub struct SessionKey(openpgp::crypto::SessionKey);
+
+/// Creates a new session key.
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_session_key_new(size: size_t) -> *mut SessionKey {
+ openpgp::crypto::SessionKey::new(&mut Yarrow::default(), size)
+ .move_into_raw()
+}
+
+/// Creates a new session key from a buffer.
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_session_key_from_bytes(buf: *const uint8_t, size: size_t)
+ -> *mut SessionKey {
+ let buf = unsafe {
+ ::std::slice::from_raw_parts(buf, size)
+ };
+ openpgp::crypto::SessionKey::from(buf).move_into_raw()
+}
+
+/// Holds a password.
+///
+/// The password is cleared when dropped.
+#[::ffi_wrapper_type(prefix = "pgp_", name = "password",
+ derive = "Clone, Debug, PartialEq")]
+pub struct Password(openpgp::crypto::Password);
+
+/// Creates a new password from a buffer.
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
+fn pgp_password_from_bytes(buf: *const uint8_t, size: size_t) -> *mut Password {
+ let buf = unsafe {
+ ::std::slice::from_raw_parts(buf, size)
+ };
+ openpgp::crypto::Password::from(buf).move_into_raw()
+}
/// Frees a signer.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]