diff options
author | Neal H. Walfield <neal@pep.foundation> | 2019-11-21 16:34:28 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2019-11-21 16:50:44 +0100 |
commit | 28be944bd9f6548b2eee5fc222ffeb52c9d2f8aa (patch) | |
tree | 247030a61766a0c664a8466c74ad7e258f435e3e /openpgp-ffi | |
parent | b251f9e8857fba284f515061ac62013519997e30 (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')
-rw-r--r-- | openpgp-ffi/include/sequoia/openpgp.h | 13 | ||||
-rw-r--r-- | openpgp-ffi/src/packet/userid.rs | 40 |
2 files changed, 53 insertions, 0 deletions
diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h index 6dadcbc0..fccc79d4 100644 --- a/openpgp-ffi/include/sequoia/openpgp.h +++ b/openpgp-ffi/include/sequoia/openpgp.h @@ -1266,6 +1266,19 @@ pgp_status_t pgp_user_id_email_normalized(pgp_error_t *errp, pgp_packet_t uid, char **emailp); /*/ +/// 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. +/*/ +pgp_status_t pgp_user_id_uri(pgp_error_t *errp, pgp_packet_t uid, + char **uri); + +/*/ /// Returns the value of the User Attribute Packet. /// /// The returned pointer is valid until `ua` is deallocated. If 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 |