diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-04-01 12:44:55 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-04-01 12:57:32 +0200 |
commit | 684fd9c08357debc49f1cd6a006044796d0b1499 (patch) | |
tree | 7bef1762b9b88f6c6438caa6216eee8f06db8797 /openpgp/src/packet/marker.rs | |
parent | 33cdb0deebb5b5f96f3097dcb4e91f6af91924a1 (diff) |
openpgp: Support the marker packet.
- Fixes #234.
Diffstat (limited to 'openpgp/src/packet/marker.rs')
-rw-r--r-- | openpgp/src/packet/marker.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/openpgp/src/packet/marker.rs b/openpgp/src/packet/marker.rs new file mode 100644 index 00000000..21be2443 --- /dev/null +++ b/openpgp/src/packet/marker.rs @@ -0,0 +1,53 @@ +use quickcheck::{Arbitrary, Gen}; + +use packet; +use Packet; + +/// Holds a Marker packet. +/// +/// See [Section 5.8 of RFC 4880] for details. +/// +/// [Section 5.8 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.8 +#[derive(PartialEq, Eq, Hash, Clone, Debug)] +pub struct Marker { + /// CTB packet header fields. + pub(crate) common: packet::Common, +} + +impl Marker { + pub(crate) const BODY: &'static [u8] = &[0x50, 0x47, 0x50]; +} + +impl Default for Marker { + fn default() -> Self { + Self { + common: Default::default(), + } + } +} + +impl From<Marker> for Packet { + fn from(p: Marker) -> Self { + Packet::Marker(p) + } +} + +impl Arbitrary for Marker { + fn arbitrary<G: Gen>(_: &mut G) -> Self { + Self::default() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use parse::Parse; + use serialize::SerializeInto; + + #[test] + fn roundtrip() { + let p = Marker::default(); + let q = Marker::from_bytes(&p.to_vec().unwrap()).unwrap(); + assert_eq!(p, q); + } +} |