//! Transferable public keys.
//!
//! Wraps [`sequoia-openpgp::TPK`] and [related functionality].
//!
//! [`sequoia-openpgp::TPK`]: ../../sequoia_openpgp/struct.TPK.html
//! [related functionality]: ../../sequoia_openpgp/tpk/index.html
use std::ptr;
use std::slice;
use libc::{c_char, c_int, size_t, time_t};
extern crate sequoia_openpgp as openpgp;
use self::openpgp::{
Packet,
RevocationStatus,
autocrypt::Autocrypt,
crypto,
constants::ReasonForRevocation,
parse::PacketParserResult,
tpk::{
CipherSuite,
KeyIter,
TPKBuilder,
UserIDBinding,
UserIDBindingIter,
},
};
use ::error::Status;
use super::fingerprint::Fingerprint;
use super::packet::key::Key;
use super::packet::signature::Signature;
use super::packet_pile::PacketPile;
use super::tsk::TSK;
use Maybe;
use RefRaw;
use MoveFromRaw;
use MoveIntoRaw;
use MoveResultIntoRaw;
/// A transferable public key (TPK).
///
/// A TPK (see [RFC 4880, section 11.1]) can be used to verify
/// signatures and encrypt data. It can be stored in a keystore and
/// uploaded to keyservers.
///
/// TPKs are always canonicalized in the sense that only elements
/// (user id, user attribute, subkey) with at least one valid
/// self-signature are preserved. Also, invalid self-signatures are
/// dropped. The self-signatures are sorted so that the newest
/// self-signature comes first. User IDs are sorted so that the first
/// `UserID` is the primary User ID. Third-party certifications are
/// *not* validated, as the keys are not available; they are simply
/// passed through as is.
///
/// [RFC 4880, section 11.1]: https://tools.ietf.org/html/rfc4880#section-11.1
#[::ffi_wrapper_type(
prefix = "pgp_", name = "tpk",
derive = "Clone, Debug, Display, PartialEq, Parse, Serialize")]
pub struct TPK(openpgp::TPK);
/// Returns the first TPK found in `m`.
///
/// Consumes `m`.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
fn pgp_tpk_from_packet_pile(errp: Option<&mut *mut ::error::Error>,
m: *mut PacketPile)
-> Maybe<TPK> {
openpgp::TPK::from_packet_pile(m.move_from_raw()).move_into_raw(errp)
}
/// Returns the first TPK found in the packet parser.
///
/// Consumes the packet parser result.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
fn pgp_tpk_from_packet_parser(errp: Option<&mut *mut ::error::Error>,
ppr: *mut PacketParserResult)
-> Maybe<TPK>
{
let ppr = ffi_param_move!(ppr);
openpgp::TPK::from_packet_parser(*ppr).move_into_raw(errp)
}
/// Merges `other` into `tpk`.
///
/// If `other` is a different key, then nothing is merged into
/// `tpk`, but `tpk` is still canonicalized.
///
/// Consumes `tpk` and `other`.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
fn pgp_tpk_merge(errp: Option<&mut *mut ::error::Error>,
tpk: *mut TPK,
other: *mut TPK)
-> Maybe<TPK> {
let tpk = tpk.move_from_raw();
let other = other.move_from_raw();
tpk.merge(other).move_into_raw(errp)
}
/// Adds packets to the TPK.
///
/// This recanonicalizes the TPK. If the packets are invalid, they
/// are dropped.
///
/// Consumes `tpk` and the packets in `packets`. The buffer, however,
/// must be managed by the caller.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system"
fn pgp_tpk_merge_packets(errp: Option<&mut *mut ::error::Error>,
tpk: *mut TPK,
packets: *mut *mut Packet,
packets_len: size_t)
-> Maybe<TPK> {
let tpk = tpk.move_from_raw();
let packets = unsafe {
slice::from_raw_parts_mut(packets, packets_len)
};
let packets =
packets.iter_mut().map(|p| *unsafe { Box::from_raw(*p) } ).collect();
tpk.merge_packets(packets).move_into_raw(errp)
}
/// Returns the fingerprint.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern