diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-02-15 13:02:02 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-02-17 14:23:28 +0100 |
commit | bc1a29b12b722daf555d61ce936db89e7ef968af (patch) | |
tree | c56b01d741a7d6d906f348d8fe4cabd87968223d | |
parent | 3f050579321c6805c9c6c231310a2efd517ee959 (diff) |
openpgp: Implement From<Vec<Packets>> for PacketPile.
- This replaces PacketPile::from_packets.
-rw-r--r-- | openpgp/src/message/mod.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet_pile.rs | 28 | ||||
-rw-r--r-- | openpgp/src/serialize/mod.rs | 2 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 4 | ||||
-rw-r--r-- | openpgp/src/tpk/builder.rs | 4 | ||||
-rw-r--r-- | openpgp/src/tpk/mod.rs | 8 | ||||
-rw-r--r-- | sqv/tests/revoked-key.rs | 2 |
7 files changed, 23 insertions, 27 deletions
diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs index 96f27f1a..883b8465 100644 --- a/openpgp/src/message/mod.rs +++ b/openpgp/src/message/mod.rs @@ -368,7 +368,7 @@ impl Message { /// /// [`Message::from_packet_pile`]: #method.from_packet_pile pub fn from_packets(packets: Vec<Packet>) -> Result<Self> { - Self::from_packet_pile(PacketPile::from_packets(packets)) + Self::from_packet_pile(PacketPile::from(packets)) } /// Returns the body of the message. diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index cd550cfc..8af9c0eb 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -81,17 +81,13 @@ impl<'a> Parse<'a, PacketPile> for PacketPile { } } -impl PacketPile { - /// Turns a vector of [`Packet`s] into a `PacketPile`. - /// - /// This is a simple wrapper function; it does not process the - /// packets in any way. - /// - /// [`Packet`s]: enum.Packet.html - pub fn from_packets(p: Vec<Packet>) -> Self { +impl From<Vec<Packet>> for PacketPile { + fn from(p: Vec<Packet>) -> Self { PacketPile { top_level: Container { packets: p } } } +} +impl PacketPile { /// Turns a [`Packet`] into a `PacketPile`. /// /// This is a simple wrapper function; it does not process the @@ -101,7 +97,7 @@ impl PacketPile { pub fn from_packet(p: Packet) -> Self { let mut top_level = Vec::with_capacity(1); top_level.push(p); - Self::from_packets(top_level) + Self::from(top_level) } /// Pretty prints the message to stderr. @@ -330,7 +326,7 @@ impl PacketPile { if ppr.is_none() { // Empty message. - return Ok(PacketPile::from_packets(Vec::new())); + return Ok(PacketPile::from(Vec::new())); } let mut pp = ppr.unwrap(); @@ -669,7 +665,7 @@ mod test { eprintln!("{:#?}", packets); - let mut pile = PacketPile::from_packets(packets); + let mut pile = PacketPile::from(packets); assert_eq!(pile.path_ref(&[ 0 ]).unwrap().tag(), Tag::SEIP); assert_eq!(pile.path_ref_mut(&[ 0 ]).unwrap().tag(), Tag::SEIP); @@ -731,7 +727,7 @@ mod test { assert!(packets.iter().map(|p| p.tag()).collect::<Vec<Tag>>() == [ Tag::Literal ]); - let mut pile = PacketPile::from_packets(packets.clone()); + let mut pile = PacketPile::from(packets.clone()); pile.replace( &[ 0 ], 1, [ two.into() @@ -763,7 +759,7 @@ mod test { for start in 0..initial.len() + 1 { for delete in 0..initial.len() - start + 1 { for insert in 0..inserted.len() + 1 { - let mut pile = PacketPile::from_packets(packets.clone()); + let mut pile = PacketPile::from(packets.clone()); let mut replacement : Vec<Packet> = Vec::new(); for &text in inserted[0..insert].iter() { @@ -816,7 +812,7 @@ mod test { for start in 0..initial.len() + 1 { for delete in 0..initial.len() - start + 1 { for insert in 0..inserted.len() + 1 { - let mut pile = PacketPile::from_packets( + let mut pile = PacketPile::from( vec![ cd.clone().into() ]); let mut replacement : Vec<Packet> = Vec::new(); @@ -859,7 +855,7 @@ mod test { one.set_body(b"one".to_vec()); let mut packets : Vec<Packet> = Vec::new(); packets.push(one.into()); - let mut pile = PacketPile::from_packets(packets.clone()); + let mut pile = PacketPile::from(packets.clone()); assert!(pile.replace(&[ 1 ], 0, Vec::new()).is_ok()); assert!(pile.replace(&[ 2 ], 0, Vec::new()).is_err()); @@ -871,7 +867,7 @@ mod test { let mut packets : Vec<Packet> = Vec::new(); packets.push(CompressedData::new(CompressionAlgorithm::Uncompressed) .into()); - let mut pile = PacketPile::from_packets(packets.clone()); + let mut pile = PacketPile::from(packets.clone()); assert!(pile.replace(&[ 1 ], 0, Vec::new()).is_ok()); assert!(pile.replace(&[ 2 ], 0, Vec::new()).is_err()); diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs index 4dda8d93..20e1110e 100644 --- a/openpgp/src/serialize/mod.rs +++ b/openpgp/src/serialize/mod.rs @@ -1683,7 +1683,7 @@ mod test { for m in messages.into_iter() { // 1. The message. - let pile = PacketPile::from_packets(m); + let pile = PacketPile::from(m); pile.pretty_print(); diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index 4e771573..5e88db65 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -1184,7 +1184,7 @@ mod test { write!(ls, "three").unwrap(); } - let pile = PacketPile::from_packets(reference); + let pile = PacketPile::from(reference); let pile2 = PacketPile::from_bytes(&o).unwrap(); if pile != pile2 { eprintln!("REFERENCE..."); @@ -1250,7 +1250,7 @@ mod test { write!(ls, "four").unwrap(); } - let pile = PacketPile::from_packets(reference); + let pile = PacketPile::from(reference); let pile2 = PacketPile::from_bytes(&o).unwrap(); if pile != pile2 { eprintln!("REFERENCE..."); diff --git a/openpgp/src/tpk/builder.rs b/openpgp/src/tpk/builder.rs index 3a354c66..75f6d718 100644 --- a/openpgp/src/tpk/builder.rs +++ b/openpgp/src/tpk/builder.rs @@ -267,7 +267,7 @@ impl TPKBuilder { } - let tpk = TPK::from_packet_pile(PacketPile::from_packets(packets))?; + let tpk = TPK::from_packet_pile(PacketPile::from(packets))?; let sec = if let Some(SecretKey::Unencrypted { ref mpis }) = primary.secret() { mpis.clone() @@ -577,7 +577,7 @@ mod tests { .add_signing_subkey() .generate().unwrap(); let pile = tpk.clone().into_packet_pile().into_children().collect::<Vec<_>>(); - let exp = TPK::from_packet_pile(PacketPile::from_packets(pile)) + let exp = TPK::from_packet_pile(PacketPile::from(pile)) .unwrap(); assert_eq!(tpk, exp); diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs index 96974520..538300eb 100644 --- a/openpgp/src/tpk/mod.rs +++ b/openpgp/src/tpk/mod.rs @@ -2520,7 +2520,7 @@ impl TPK { /// /// This method discards an invalid components and bad signatures. pub fn into_packet_pile(self) -> PacketPile { - PacketPile::from_packets(self.into_packets()) + PacketPile::from(self.into_packets()) } /// Merges `other` into `self`. @@ -2563,7 +2563,7 @@ impl TPK { pub fn merge_packets(self, mut packets: Vec<Packet>) -> Result<Self> { let mut combined = self.into_packets(); combined.append(&mut packets); - TPK::from_packet_pile(PacketPile::from_packets(combined)) + TPK::from_packet_pile(PacketPile::from(combined)) } /// Cast the public key into a secret key that allows using the secret @@ -2577,7 +2577,7 @@ impl TPK { /// true are included in the TSK. pub fn filter_into_tsk<F: Fn(&Packet) -> bool>(self, f: F) -> Result<TSK> { let pkts = self.into_packet_pile().into_children().filter(f).collect::<Vec<_>>(); - let pile = PacketPile::from_packets(pkts); + let pile = PacketPile::from(pkts); Ok(TSK::from_tpk(TPK::from_packet_pile(pile)?)) } @@ -3593,7 +3593,7 @@ mod test { (bind1, rev, bind2) }; - let tpk = TPK::from_packet_pile(PacketPile::from_packets(vec![ + let tpk = TPK::from_packet_pile(PacketPile::from(vec![ key.into_packet(Tag::PublicKey).unwrap(), bind1.into(), bind2.into(), diff --git a/sqv/tests/revoked-key.rs b/sqv/tests/revoked-key.rs index 655ba141..1cc74d3c 100644 --- a/sqv/tests/revoked-key.rs +++ b/sqv/tests/revoked-key.rs @@ -154,7 +154,7 @@ mod integration { // // (bind1, rev, bind2, sig1, sig2, sig3) // }; -// let tpk = TPK::from_packet_pile(PacketPile::from_packets(vec![ +// let tpk = TPK::from_packet_pile(PacketPile::from(vec![ // key.into_packet(Tag::PublicKey).unwrap(), // bind1.into(), // bind2.into(), |