diff options
Diffstat (limited to 'openpgp/src/lib.rs')
-rw-r--r-- | openpgp/src/lib.rs | 120 |
1 files changed, 2 insertions, 118 deletions
diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 40aca343..fab9fd14 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -143,7 +143,8 @@ pub mod fmt; pub mod crypto; pub mod packet; -use crate::packet::{Container, key}; +pub use packet::Packet; +use crate::packet::key; pub mod parse; @@ -317,120 +318,3 @@ pub enum Error { /// variant. #[doc(hidden)] #[error("__Nonexhaustive")] __Nonexhaustive, } - -/// The OpenPGP packets that Sequoia understands. -/// -/// The different OpenPGP packets are detailed in [Section 5 of RFC 4880]. -/// -/// The `Unknown` packet allows Sequoia to deal with packets that it -/// doesn't understand. The `Unknown` packet is basically a binary -/// blob that includes the packet's tag. -/// -/// The unknown packet is also used for packets that are understood, -/// but use unsupported options. For instance, when the packet parser -/// encounters a compressed data packet with an unknown compression -/// algorithm, it returns the packet in an `Unknown` packet rather -/// than a `CompressedData` packet. -/// -/// [Section 5 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5 -/// -/// Note: This enum cannot be exhaustively matched to allow future -/// extensions. -/// -/// # A note on equality -/// -/// We define equality on `Packet` like equality of the serialized -/// form of the packet bodies defined by RFC4880, i.e. two packets are -/// considered equal if and only if their serialized form is equal, -/// modulo the OpenPGP framing (`CTB` and length style, potential -/// partial body encoding). -#[derive(Debug)] -#[derive(PartialEq, Eq, Hash, Clone)] -pub enum Packet { - /// Unknown packet. - Unknown(packet::Unknown), - /// Signature packet. - Signature(packet::Signature), - /// One pass signature packet. - OnePassSig(packet::OnePassSig), - /// Public key packet. - PublicKey(packet::key::PublicKey), - /// Public subkey packet. - PublicSubkey(packet::key::PublicSubkey), - /// Public/Secret key pair. - SecretKey(packet::key::SecretKey), - /// Public/Secret subkey pair. - SecretSubkey(packet::key::SecretSubkey), - /// Marker packet. - Marker(packet::Marker), - /// Trust packet. - Trust(packet::Trust), - /// User ID packet. - UserID(packet::UserID), - /// User attribute packet. - UserAttribute(packet::UserAttribute), - /// Literal data packet. - Literal(packet::Literal), - /// Compressed literal data packet. - CompressedData(packet::CompressedData), - /// Public key encrypted data packet. - PKESK(packet::PKESK), - /// Symmetric key encrypted data packet. - SKESK(packet::SKESK), - /// Symmetric key encrypted, integrity protected data packet. - SEIP(packet::SEIP), - /// Modification detection code packet. - MDC(packet::MDC), - /// AEAD Encrypted Data Packet. - AED(packet::AED), - - /// This marks this enum as non-exhaustive. Do not use this - /// variant. - #[doc(hidden)] __Nonexhaustive, -} - -impl Packet { - /// Returns the `Packet's` corresponding OpenPGP tag. - /// - /// Tags are explained in [Section 4.3 of RFC 4880]. - /// - /// [Section 4.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-4.3 - pub fn tag(&self) -> packet::Tag { - use crate::packet::Tag; - match self { - &Packet::Unknown(ref packet) => packet.tag(), - &Packet::Signature(_) => Tag::Signature, - &Packet::OnePassSig(_) => Tag::OnePassSig, - &Packet::PublicKey(_) => Tag::PublicKey, - &Packet::PublicSubkey(_) => Tag::PublicSubkey, - &Packet::SecretKey(_) => Tag::SecretKey, - &Packet::SecretSubkey(_) => Tag::SecretSubkey, - &Packet::Marker(_) => Tag::Marker, - &Packet::Trust(_) => Tag::Trust, - &Packet::UserID(_) => Tag::UserID, - &Packet::UserAttribute(_) => Tag::UserAttribute, - &Packet::Literal(_) => Tag::Literal, - &Packet::CompressedData(_) => Tag::CompressedData, - &Packet::PKESK(_) => Tag::PKESK, - &Packet::SKESK(_) => Tag::SKESK, - &Packet::SEIP(_) => Tag::SEIP, - &Packet::MDC(_) => Tag::MDC, - &Packet::AED(_) => Tag::AED, - Packet::__Nonexhaustive => unreachable!(), - } - } - - /// Returns the parsed `Packet's` corresponding OpenPGP tag. - /// - /// Returns the packets tag, but only if it was successfully - /// parsed into the corresponding packet type. If e.g. a - /// Signature Packet uses some unsupported methods, it is parsed - /// into an `Packet::Unknown`. `tag()` returns `Tag::Signature`, - /// whereas `kind()` returns `None`. - pub fn kind(&self) -> Option<packet::Tag> { - match self { - &Packet::Unknown(_) => None, - _ => Some(self.tag()), - } - } -} |