diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-02-15 13:45:32 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2022-03-25 12:17:26 +0100 |
commit | 5c42e3024dbfb4b2aa9d74f931ef944a778a10d8 (patch) | |
tree | 9d47c18d22b3d821766f082216c8083b4c0d7df1 | |
parent | d6d70d7ffc8970c3d55ad5b075ada757b4dd1eb9 (diff) |
openpgp: New function Packet::version.
-rw-r--r-- | openpgp/NEWS | 1 | ||||
-rw-r--r-- | openpgp/src/packet/mod.rs | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS index c4526ced..12877bdb 100644 --- a/openpgp/NEWS +++ b/openpgp/NEWS @@ -4,6 +4,7 @@ * Changes in 1.9.0 ** New functionality + - Packet::version - SignatureBuilder::set_reference_time - SignatureBuilder::effective_signature_creation_time * Changes in 1.8.0 diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index edae051f..991d3e38 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -365,6 +365,34 @@ impl Packet { } } + /// Returns the `Packet's` version, if the packet is versioned and + /// recognized. + /// + /// If the packet is not versioned, or we couldn't parse the + /// packet, this function returns `None`. + pub fn version(&self) -> Option<u8> { + match self { + Packet::Unknown(_) => None, + Packet::Signature(p) => Some(p.version()), + Packet::OnePassSig(p) => Some(p.version()), + Packet::PublicKey(p) => Some(p.version()), + Packet::PublicSubkey(p) => Some(p.version()), + Packet::SecretKey(p) => Some(p.version()), + Packet::SecretSubkey(p) => Some(p.version()), + Packet::Marker(_) => None, + Packet::Trust(_) => None, + Packet::UserID(_) => None, + Packet::UserAttribute(_) => None, + Packet::Literal(_) => None, + Packet::CompressedData(_) => None, + Packet::PKESK(p) => Some(p.version()), + Packet::SKESK(p) => Some(p.version()), + Packet::SEIP(p) => Some(p.version()), + Packet::MDC(_) => None, + Packet::AED(p) => Some(p.version()), + } + } + /// Hashes most everything into state. /// /// This is an alternate implementation of [`Hash`], which does |