use std::{
borrow::Cow,
};
use crate::Result;
use crate::cert::prelude::*;
use crate::packet::{header::BodyLength, key, Signature, Tag};
use crate::seal;
use crate::serialize::{
PacketRef,
Marshal, MarshalInto,
NetLength,
generic_serialize_into, generic_export_into,
};
impl Cert {
/// Returns whether the certificate should be exported.
///
/// A certificate should only be exported if it has at least one
/// exportable direct key signature, or there is at least one user
/// ID with at least one exportable self signature.
///
/// # Examples
///
/// ```
/// use sequoia_openpgp as openpgp;
/// use openpgp::cert::prelude::*;
///
/// # fn main() -> openpgp::Result<()> {
/// // By default, certificates are exportable.
/// let (cert, _) =
/// CertBuilder::general_purpose(None, Some("alice@example.org"))
/// .generate()?;
/// assert!(cert.exportable());
///
/// // Setting the exportable flag to false makes them
/// // not-exportable.
/// let (cert, _) =
/// CertBuilder::general_purpose(None, Some("alice@example.org"))
/// .set_exportable(false)
/// .generate()?;
/// assert!(! cert.exportable());
/// # Ok(())
/// # }
/// ```
#[allow(clippy::if_same_then_else)]
pub fn exportable(&self) -> bool {
let pk = self.primary_key();
if pk.self_signatures().chain(pk.self_revocations())
.any(|sig| sig.exportable().is_ok())
{
// Exportable direct key signature. Export it.
true
} else if self.userids().any(|userid| {
userid.self_signatures()
.chain(userid.self_revocations())
.