//! Handles TPKs.
//!
//! 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 std::io::{Read, Write};
use libc::{uint8_t, c_char, c_int, size_t, time_t};
extern crate sequoia_openpgp;
use self::sequoia_openpgp::{
Fingerprint,
Packet,
PacketPile,
RevocationStatus,
TPK,
TSK,
autocrypt::Autocrypt,
crypto,
constants::ReasonForRevocation,
packet::{self, Signature},
parse::PacketParserResult,
parse::Parse,
serialize::Serialize,
tpk::{
CipherSuite,
KeyIter,
TPKBuilder,
UserIDBinding,
UserIDBindingIter,
},
};
use ::core::Context;
use ::error::Status;
/// Returns the first TPK encountered in the reader.
#[::ffi_catch_abort] #[no_mangle]
pub extern "system" fn sq_tpk_from_reader(ctx: *mut Context,
reader: *mut Box<Read>)
-> *mut TPK {
let ctx = ffi_param_ref_mut!(ctx);
ffi_make_fry_from_ctx!(ctx);
let reader = ffi_param_ref_mut!(reader);
ffi_try_box!(TPK::from_reader(reader))
}
/// Returns the first TPK encountered in the file.
#[::ffi_catch_abort] #[no_mangle]
pub extern "system" fn sq_tpk_from_file(ctx: *mut Context,
filename: *const c_char)
-> *mut TPK {
let ctx = ffi_param_ref_mut!(ctx);
ffi_make_fry_from_ctx!(ctx);
let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned();
ffi_try_box!(TPK::from_file(&filename))
}
/// Returns the first TPK found in `m`.
///
/// Consumes `m`.
#[::ffi_catch_abort] #[no_mangle]
pub extern "system" fn sq_tpk_from_packet_pile(ctx: *mut Context,
m: *mut PacketPile)
-> *mut TPK {
let ctx = ffi_param_ref_mut!(ctx);
ffi_make_fry_from_ctx!(ctx);
let m = ffi_param_move!(m);
ffi_try_box!(TPK::from_packet_pile(*m))
}
/// Returns the first TPK found in `buf`.
///
/// `buf` must be an OpenPGP-encoded TPK.
#[::ffi_catch_abort] #[no_mangle]
pub extern "system" fn sq_tpk_from_bytes(ctx: *mut Context,
b: *const uint8_t, len: size_t)
-> *mut TPK {
let ctx = ffi_param_ref_mut!(ctx);
ffi_make_fry_from_ctx!(ctx);
assert!(!b.is_null());
let buf = unsafe {
slice::from_raw_parts(b, len as usize)
};
ffi_try_box!(TPK::from_bytes(buf))
}
/// Returns the first TPK found in the packet parser.
///
/// Consumes the packet parser result.
#[::ffi_catch_abort] #[no_mangle]
pub extern "system" fn sq_tpk_from_packet_parser(ctx: *mut Context,
ppr: *mut PacketParserResult)
-> *mut TPK
{
let ctx = ffi_param_ref_mut!(ctx);
ffi_make_fry_from_ctx!(ctx);
let ppr = ffi_param_move!(ppr);
ffi_try_box!(TPK::from_packet_parser(*ppr))
}
/// Frees the TPK.
#[::ffi_catch_abort] #[no_mangle]
pub extern "system" fn sq_tpk_free(tpk: Option<&mut TPK>) {
ffi_free!(tpk)
}
/// Clones the TPK.
#[::ffi_catch_abort] #[no_mangle]
pub extern "system" fn sq_tpk_clone(tpk: *const TPK)
-> *mut TPK {
let tpk = ffi_param_ref!(tpk);
box_raw!(tpk.clone())
}
/// Compares TPKs.
#[::ffi_catch_abort] #[no_mangle]
pub extern "system" fn sq_tpk_equal(a: *const TPK,
b: *const TPK)
-> bool {
let a = ffi_param_ref!(a);
let b = ffi_param_ref!(b);
a == b
}
/// Serializes the TPK.
#[::ffi_catch_abort] #[no_mangle]
pub extern "system" fn sq_tpk_serialize(ctx: *mut Context,
tpk: *const