//! 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, uint8_t};
extern crate sequoia_openpgp as openpgp;
use self::openpgp::{
autocrypt::Autocrypt,
crypto,
constants::ReasonForRevocation,
parse::{
PacketParserResult,
Parse,
},
tpk::{
CipherSuite,
KeyIter,
TPKBuilder,
TPKParser,
UserIDBinding,
UserIDBindingIter,
},
};
use ::error::Status;
use super::fingerprint::Fingerprint;
use super::packet::key::Key;
use super::packet::Packet;
use super::packet::signature::Signature;
use super::packet_pile::PacketPile;
use super::tsk::TSK;
use super::revocation_status::RevocationStatus;
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 "C"
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 "C"
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 "C"
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 =