summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi
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
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')
-rw-r--r--openpgp-ffi/include/sequoia/openpgp.h10
-rw-r--r--openpgp-ffi/src/packet/userid.rs25
2 files changed, 35 insertions, 0 deletions
diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h
index ac8117d3..f504c037 100644
--- a/openpgp-ffi/include/sequoia/openpgp.h
+++ b/openpgp-ffi/include/sequoia/openpgp.h
@@ -962,6 +962,16 @@ int pgp_key_public_key_bits(pgp_key_t key);
pgp_key_pair_t pgp_key_into_key_pair (pgp_error_t *errp, pgp_key_t key);
/*/
+/// Create a new User ID with the value `value`.
+/*/
+pgp_packet_t pgp_user_id_new (const char *value);
+
+/*/
+/// Create a new User ID with the value `value`.
+/*/
+pgp_packet_t pgp_user_id_from_raw (const char *value, size_t len);
+
+/*/
/// Returns the value of the User ID Packet.
///
/// The returned pointer is valid until `uid` is deallocated. If
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.
///