summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/src
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-05-07 18:22:56 +0200
committerNeal H. Walfield <neal@pep.foundation>2019-05-08 14:48:59 +0200
commit11807cb3d90d6442fc0ead2eab3c3a41bcc7ce7d (patch)
treeb4c1201bb51876ef65dffa130c364c92ab349292 /openpgp-ffi/src
parent0ad3263b1e28192b19e4588de37b848dedad801b (diff)
openpgp-ffi: Add functions to instantiate UserIDs
- Add pgp_user_id_new to instantiate from a c string. - Add pgp_user_id_from_raw to instantiate from a not-NUL-terminated buffer.
Diffstat (limited to 'openpgp-ffi/src')
-rw-r--r--openpgp-ffi/src/packet/userid.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/openpgp-ffi/src/packet/userid.rs b/openpgp-ffi/src/packet/userid.rs
index ba34cb0c..0db8824c 100644
--- a/openpgp-ffi/src/packet/userid.rs
+++ b/openpgp-ffi/src/packet/userid.rs
@@ -10,6 +10,31 @@ use error::Status;
use super::Packet;
use RefRaw;
+use MoveIntoRaw;
+
+/// Create a new User ID with the value `value`.
+///
+/// `value` need not be valid UTF-8, but it must be NUL terminated.
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
+pub extern "system" fn pgp_user_id_new(value: *const c_char)
+ -> *mut Packet
+{
+ let value : &[u8] = ffi_param_cstr!(value).to_bytes();
+ let packet : openpgp::Packet = openpgp::packet::UserID::from(value).into();
+ packet.move_into_raw()
+}
+
+/// Create a new User ID with the value `value`.
+///
+/// `value` need not be valid UTF-8.
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
+pub extern "system" fn pgp_user_id_from_raw(value: *const uint8_t, len: size_t)
+ -> *mut Packet
+{
+ let value : &[u8] = unsafe { std::slice::from_raw_parts(value, len) };
+ let packet : openpgp::Packet = openpgp::packet::UserID::from(value).into();
+ packet.move_into_raw()
+}
/// Returns the value of the User ID Packet.
///