summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi/src/packet/userid.rs
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-11-21 16:34:28 +0100
committerNeal H. Walfield <neal@pep.foundation>2019-11-21 16:50:44 +0100
commit28be944bd9f6548b2eee5fc222ffeb52c9d2f8aa (patch)
tree247030a61766a0c664a8466c74ad7e258f435e3e /openpgp-ffi/src/packet/userid.rs
parentb251f9e8857fba284f515061ac62013519997e30 (diff)
openpgp: When parsing User IDs, recognize URIs.
- Restore the functionality removed in 8693a005 when replacing the RFC 2822 mailbox parser.
Diffstat (limited to 'openpgp-ffi/src/packet/userid.rs')
-rw-r--r--openpgp-ffi/src/packet/userid.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/openpgp-ffi/src/packet/userid.rs b/openpgp-ffi/src/packet/userid.rs
index 168227c4..9935c2ca 100644
--- a/openpgp-ffi/src/packet/userid.rs
+++ b/openpgp-ffi/src/packet/userid.rs
@@ -249,6 +249,46 @@ fn pgp_user_id_email(
Status::Success
}
+/// Returns the User ID's URI, if any.
+///
+/// The User ID is parsed according to de factor convention, and the
+/// URI is extracted.
+///
+/// If the User ID cannot be parsed, then an error is returned.
+///
+/// If the User ID does not contain a URI, *urip is set to NULL.
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
+pub extern "C"
+fn pgp_user_id_uri(
+ errp: Option<&mut *mut crate::error::Error>, uid: *const Packet,
+ urip: &mut *mut c_char)
+ -> Status
+{
+ ffi_make_fry_from_errp!(errp);
+ let uid = uid.ref_raw();
+
+ if let &openpgp::Packet::UserID(ref uid) = uid {
+ match uid.uri() {
+ Ok(Some(uri)) =>
+ *urip = ffi_return_string!(uri),
+ Ok(None) =>
+ *urip = ::std::ptr::null_mut(),
+ Err(err) => {
+ use crate::MoveIntoRaw;
+ let status = crate::error::Status::from(&err);
+ if let Some(errp) = errp {
+ *errp = err.move_into_raw();
+ }
+ return status;
+ }
+ }
+ } else {
+ panic!("Not a UserID packet");
+ }
+
+ Status::Success
+}
+
/// Returns a normalized version of the UserID's email address.
///
/// Normalized email addresses are primarily needed when email