diff options
author | Neal H. Walfield <neal@pep.foundation> | 2020-04-02 14:48:03 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2020-04-02 16:42:54 +0200 |
commit | 789ae8615fda8e6dcbc1a39625e322255da90cef (patch) | |
tree | 97b8fec96ef1bfcd1d7c09a264d138803a6b85c0 /openpgp-ffi/src/amalgamation.rs | |
parent | 6dd60b0b306e5d69b8770a5fa1f0bbfcead2270c (diff) |
openpgp-ffi: Use UserIDAmalgamations, not UserIDBundles.
- Add the `UserID`, `UserIDAmalgamation` and
`ValidUserIDAmalgamation` types, and some associated methods.
- Replace the use of `UserIDBundle` with `UserIDAmalgamation` and
`ValidUserIDAmalgamation`.
Diffstat (limited to 'openpgp-ffi/src/amalgamation.rs')
-rw-r--r-- | openpgp-ffi/src/amalgamation.rs | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/openpgp-ffi/src/amalgamation.rs b/openpgp-ffi/src/amalgamation.rs new file mode 100644 index 00000000..248fe24f --- /dev/null +++ b/openpgp-ffi/src/amalgamation.rs @@ -0,0 +1,112 @@ +//! `KeyAmalgamation`s. +//! +//! +//! Wraps [`sequoia-openpgp::cert::key_amalgamation::KeyAmalgamation`]. +//! +//! [`sequoia-openpgp::cert::key_amalgamation::KeyAmalgamation`]: ../../../sequoia_openpgp/cert/key_amalgamation/struct.KeyAmalgamation.html + +use libc::time_t; + +extern crate sequoia_openpgp as openpgp; + +use self::openpgp::cert::amalgamation::ValidAmalgamation as _; +use self::openpgp::cert::amalgamation::ValidateAmalgamation as _; + +use super::packet::userid::UserID; +use super::packet::signature::Signature; +use super::policy::Policy; +use super::revocation_status::RevocationStatus; + +use crate::Maybe; +use crate::MoveIntoRaw; +use crate::MoveResultIntoRaw; +use crate::RefRaw; +use crate::MoveFromRaw; +use crate::maybe_time; + +/// A local alias to appease the proc macro transformation. +type UserIDAmalgamationType<'a> + = openpgp::cert::amalgamation::ComponentAmalgamation<'a, openpgp::packet::UserID>; + +/// A `UserIDAmalgamation` holds a `UserID` and associated data. +/// +/// Wraps [`sequoia-openpgp::cert::amalgamation::ComponentAmalgamation`]. +/// +/// [`sequoia-openpgp::cert::amalgamation::ComponentAmalgamation`]: ../../../sequoia_openpgp/cert/amalgamation/struct.ComponentAmalgamation.html +#[crate::ffi_wrapper_type(prefix = "pgp_", + derive = "Clone, Debug")] +pub struct UserIDAmalgamation<'a>(UserIDAmalgamationType<'a>); + +/// Returns a reference to the `UserID`. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] +pub extern "C" fn pgp_user_id_amalgamation_user_id<'a>(ua: *const UserIDAmalgamation<'a>) + -> *const UserID +{ + let ua = ua.ref_raw(); + + ua.userid().move_into_raw() +} + +/// A local alias to appease the proc macro transformation. +type ValidUserIDAmalgamationType<'a> + = openpgp::cert::amalgamation::ValidComponentAmalgamation<'a, openpgp::packet::UserID>; + +/// A `ValidUserIDAmalgamation` holds a `UserID` and associated data +/// including a policy and a reference time. +/// +/// Wraps [`sequoia-openpgp::cert::amalgamation::ValidComponentAmalgamation`]. +/// +/// [`sequoia-openpgp::cert::amalgamation::ValidComponentAmalgamation`]: ../../../sequoia_openpgp/cert/amalgamation/struct.ValidComponentAmalgamation.html +#[crate::ffi_wrapper_type(prefix = "pgp_", + derive = "Clone, Debug")] +pub struct ValidUserIDAmalgamation<'a>(ValidUserIDAmalgamationType<'a>); + +/// Returns a reference to the `UserID`. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] +pub extern "C" fn pgp_valid_user_id_amalgamation_user_id<'a>(ua: *const ValidUserIDAmalgamation<'a>) + -> *const UserID +{ + let ua = ua.ref_raw(); + + ua.userid().move_into_raw() +} + +/// Returns the UserID's revocation status. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] +pub extern "C" fn pgp_valid_user_id_amalgamation_revocation_status<'a>(ua: *const ValidUserIDAmalgamation<'a>) + -> *mut RevocationStatus<'a> +{ + ua.ref_raw() + .revoked() + .move_into_raw() +} + +/// Returns the User ID's binding signature. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] +pub extern "C" fn pgp_valid_user_id_amalgamation_binding_signature<'a>(ua: *const ValidUserIDAmalgamation<'a>) + -> *const Signature +{ + ua.ref_raw() + .binding_signature() + .move_into_raw() +} + +/// Changes the policy applied to the `ValidUserIDAmalgamation`. +/// +/// This consumes the User ID amalgamation. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] +pub extern "C" +fn pgp_valid_user_id_amalgamation_with_policy<'a>(errp: Option<&mut *mut crate::error::Error>, + ua: *mut ValidUserIDAmalgamation<'a>, + policy: *const Policy, + time: time_t) + -> Maybe<ValidUserIDAmalgamation<'a>> +{ + ffi_make_fry_from_errp!(errp); + + let ua = ua.move_from_raw(); + let policy = policy.ref_raw(); + let time = maybe_time(time); + + ua.with_policy(&**policy, time).move_into_raw(errp) +} |