diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-12-07 16:20:59 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-12-07 16:48:23 +0100 |
commit | 58286b06295c95f77b1bb2cb28dc247238080a7a (patch) | |
tree | d847311b7c13b4af7914827c6d551c7163cef9fc | |
parent | 0768b36c4dd9bddd6b85a7017c32e44ad9775db5 (diff) |
openpgp: Make PacketParser's map field private.
-rw-r--r-- | openpgp/src/parse/map.rs | 4 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 12 | ||||
-rw-r--r-- | tool/src/commands/decrypt.rs | 2 | ||||
-rw-r--r-- | tool/src/commands/dump.rs | 2 | ||||
-rw-r--r-- | tool/src/commands/mod.rs | 2 |
5 files changed, 16 insertions, 6 deletions
diff --git a/openpgp/src/parse/map.rs b/openpgp/src/parse/map.rs index ed286977..434c0e93 100644 --- a/openpgp/src/parse/map.rs +++ b/openpgp/src/parse/map.rs @@ -65,8 +65,8 @@ impl Map { /// let msg = b"\xcb\x12t\x00\x00\x00\x00\x00Hello world."; /// let ppo = PacketParserBuilder::from_bytes(msg)? /// .map(true).finalize()?; - /// let map = ppo.unwrap().map.unwrap(); - /// assert_eq!(map.iter().map(|f| (f.name, f.data)).collect::<Vec<(&str, &[u8])>>(), + /// assert_eq!(ppo.unwrap().map().unwrap().iter() + /// .map(|f| (f.name, f.data)).collect::<Vec<(&str, &[u8])>>(), /// [("frame", &b"\xcb\x12"[..]), /// ("format", b"t"), /// ("filename_len", b"\x00"), diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index 396d8c53..60b95ec3 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -2157,7 +2157,7 @@ pub struct PacketParser<'a> { decrypted: bool, /// A map of this packet. - pub map: Option<map::Map>, + map: Option<map::Map>, state: PacketParserState, } @@ -3032,6 +3032,16 @@ impl <'a> PacketParser<'a> { Ok(&mut self.packet) } + + /// Returns a reference to the map (if any is written). + pub fn map(&self) -> Option<&map::Map> { + self.map.as_ref() + } + + /// Takes the map (if any is written). + pub fn take_map(&mut self) -> Option<map::Map> { + self.map.take() + } } /// This interface allows a caller to read the content of a diff --git a/tool/src/commands/decrypt.rs b/tool/src/commands/decrypt.rs index 9fc93f2a..d6f9a468 100644 --- a/tool/src/commands/decrypt.rs +++ b/tool/src/commands/decrypt.rs @@ -114,7 +114,7 @@ impl<'a> DecryptionHelper for Helper<'a> { dumper.packet(&mut io::stderr(), pp.recursion_depth() as usize, pp.header.clone(), pp.packet.clone(), - pp.map.clone(), None)?; + pp.map().map(|m| m.clone()), None)?; } Ok(()) } diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs index d883ce90..5f7ec627 100644 --- a/tool/src/commands/dump.rs +++ b/tool/src/commands/dump.rs @@ -33,7 +33,7 @@ pub fn dump(input: &mut io::Read, output: &mut io::Write, mpis: bool, hex: bool) }; let header = pp.header.clone(); - let map = pp.map.take(); + let map = pp.take_map(); let (packet, ppr_) = pp.recurse()?; ppr = ppr_; diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index a92b84ef..fa265747 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -595,7 +595,7 @@ pub fn split(input: &mut io::Read, prefix: &str) let mut pos = vec![0]; while let PacketParserResult::Some(pp) = ppr { - if let Some(ref map) = pp.map { + if let Some(ref map) = pp.map() { let filename = format!( "{}{}--{:?}", prefix, pos.iter().map(|n| format!("{}", n)) |