summaryrefslogtreecommitdiffstats
path: root/openpgp/src
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-12-19 17:37:23 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-12-20 18:04:56 +0100
commitcf103b49bbaf37783e7d761d3eb06366d9692b89 (patch)
treec3506d0b0af91eb0803500c8108dbfe14a6c9e0c /openpgp/src
parentcfdc2c0a51ca5bcb30683d37b3983c6589799a20 (diff)
openpgp: Trim set of container functions and reduce visibility.
Diffstat (limited to 'openpgp/src')
-rw-r--r--openpgp/src/message/mod.rs7
-rw-r--r--openpgp/src/packet/compressed_data.rs6
-rw-r--r--openpgp/src/packet/container.rs28
-rw-r--r--openpgp/src/packet_pile.rs9
4 files changed, 16 insertions, 34 deletions
diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs
index 9592a703..b08de710 100644
--- a/openpgp/src/message/mod.rs
+++ b/openpgp/src/message/mod.rs
@@ -997,9 +997,9 @@ mod tests {
// 1: MDC
// => good.
let mut seip = SEIP1::new();
- seip.container_mut().push(
+ seip.children_mut().push(
lit.clone().into());
- seip.container_mut().push(
+ seip.children_mut().push(
MDC::from([0u8; 20]).into());
packets[1] = seip.into();
@@ -1079,7 +1079,8 @@ mod tests {
// 2: Literal
// => bad.
packets.remove(3);
- packets[2].container_mut().unwrap().push(lit.clone().into());
+ packets[2].container_mut().unwrap()
+ .children_mut().push(lit.clone().into());
assert!(packets.iter().map(|p| p.tag()).collect::<Vec<Tag>>()
== [ Tag::SKESK, Tag::SKESK, Tag::SEIP ]);
diff --git a/openpgp/src/packet/compressed_data.rs b/openpgp/src/packet/compressed_data.rs
index 9cdb7e58..44f5d0db 100644
--- a/openpgp/src/packet/compressed_data.rs
+++ b/openpgp/src/packet/compressed_data.rs
@@ -58,8 +58,9 @@ impl CompressedData {
}
/// Adds a new packet to the container.
+ #[cfg(test)]
pub fn push(mut self, packet: Packet) -> Self {
- self.container.push(packet);
+ self.container.children_mut().push(packet);
self
}
@@ -67,8 +68,9 @@ impl CompressedData {
/// If `i` is 0, the new packet is insert at the front of the
/// container. If `i` is one, it is inserted after the first
/// packet, etc.
+ #[cfg(test)]
pub fn insert(mut self, i: usize, packet: Packet) -> Self {
- self.container.insert(i, packet);
+ self.container.children_mut().insert(i, packet);
self
}
}
diff --git a/openpgp/src/packet/container.rs b/openpgp/src/packet/container.rs
index 68138240..8b75aa45 100644
--- a/openpgp/src/packet/container.rs
+++ b/openpgp/src/packet/container.rs
@@ -118,19 +118,6 @@ impl Container {
&mut self.packets
}
- // Adds a new packet to the container.
- pub(crate) fn push(&mut self, packet: Packet) {
- self.packets.push(packet);
- }
-
- // Inserts a new packet to the container at a particular index.
- // If `i` is 0, the new packet is insert at the front of the
- // container. If `i` is one, it is inserted after the first
- // packet, etc.
- pub(crate) fn insert(&mut self, i: usize, packet: Packet) {
- self.packets.insert(i, packet);
- }
-
/// Returns an iterator over the packet's descendants. The
/// descendants are visited in depth-first order.
pub fn descendants(&self) -> Iter {
@@ -281,13 +268,13 @@ impl Packet {
}
/// Returns an iterator over the packet's immediate children.
- pub fn children<'a>(&'a self) -> impl Iterator<Item = &'a Packet> {
+ pub(crate) fn children<'a>(&'a self) -> impl Iterator<Item = &'a Packet> {
self.container_ref().map(|c| c.children()).unwrap_or_else(|| [].iter())
}
/// Returns an iterator over all of the packet's descendants, in
/// depth-first order.
- pub fn descendants(&self) -> Iter {
+ pub(crate) fn descendants(&self) -> Iter {
self.container_ref().map(|c| c.descendants()).unwrap_or_default()
}
@@ -296,16 +283,7 @@ impl Packet {
/// Packets can store a sequence of bytes as body, e.g. if the
/// maximum recursion level is reached while parsing a sequence of
/// packets, the container's body is stored as is.
- pub fn body(&self) -> Option<&[u8]> {
+ pub(crate) fn body(&self) -> Option<&[u8]> {
self.container_ref().and_then(|c| c.body())
}
-
- #[deprecated]
- /// Sets the packet's body.
- ///
- /// Setting the body clears the old body, or any of the packet's
- /// descendants.
- pub fn set_body(&mut self, data: Vec<u8>) -> Vec<u8> {
- self.container_mut().unwrap().set_body(data)
- }
}
diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs
index c3f95625..dff0411b 100644
--- a/openpgp/src/packet_pile.rs
+++ b/openpgp/src/packet_pile.rs
@@ -188,9 +188,10 @@ impl PacketPile {
/// // A compressed data packet that contains a literal data packet.
/// let mut literal = Literal::new(DataFormat::Text);
/// literal.set_body(b"old".to_vec());
- /// let mut pile = PacketPile::from(Packet::from(
- /// CompressedData::new(CompressionAlgorithm::Uncompressed)
- /// .push(literal.into())));
+ /// let mut compressed =
+ /// CompressedData::new(CompressionAlgorithm::Uncompressed);
+ /// compressed.children_mut().push(literal.into());
+ /// let mut pile = PacketPile::from(Packet::from(compressed));
///
/// // Replace the literal data packet.
/// let mut literal = Literal::new(DataFormat::Text);
@@ -627,7 +628,7 @@ mod test {
}
let mut seip = SEIP1::new();
- seip.container_mut().push(cd.into());
+ seip.children_mut().push(cd.into());
packets.push(seip.into());
eprintln!("{:#?}", packets);