summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-02-06 13:35:35 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-02-06 13:39:56 +0100
commit2a75428b44fd56616342a786cc33dd66145f6228 (patch)
tree3ccf25024106dec1d81954aa47b3e9bf152d124f /openpgp
parentd6f553a2f3063d2995fbd91ed137cc876d7ecdc0 (diff)
openpgp: Rename consuming conversion functions.
- Rename functions that consume their receiver but are called .to_...() to .into_...(). - For the packet types, simply drop the conversion function in favor of using the From trait. - Fixes #160.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/autocrypt.rs4
-rw-r--r--openpgp/src/message/mod.rs113
-rw-r--r--openpgp/src/packet/aed.rs7
-rw-r--r--openpgp/src/packet/compressed_data.rs7
-rw-r--r--openpgp/src/packet/literal.rs7
-rw-r--r--openpgp/src/packet/mdc.rs7
-rw-r--r--openpgp/src/packet/one_pass_sig.rs7
-rw-r--r--openpgp/src/packet/pkesk.rs7
-rw-r--r--openpgp/src/packet/seip.rs7
-rw-r--r--openpgp/src/packet/signature/mod.rs7
-rw-r--r--openpgp/src/packet/signature/subpacket.rs2
-rw-r--r--openpgp/src/packet/skesk.rs13
-rw-r--r--openpgp/src/packet/unknown.rs7
-rw-r--r--openpgp/src/packet/user_attribute.rs7
-rw-r--r--openpgp/src/packet/userid.rs7
-rw-r--r--openpgp/src/packet_pile.rs40
-rw-r--r--openpgp/src/parse/packet_pile_parser.rs2
-rw-r--r--openpgp/src/serialize/mod.rs66
-rw-r--r--openpgp/src/serialize/stream.rs22
-rw-r--r--openpgp/src/tpk/builder.rs2
-rw-r--r--openpgp/src/tpk/mod.rs38
21 files changed, 158 insertions, 221 deletions
diff --git a/openpgp/src/autocrypt.rs b/openpgp/src/autocrypt.rs
index 8367d62a..e648d33c 100644
--- a/openpgp/src/autocrypt.rs
+++ b/openpgp/src/autocrypt.rs
@@ -536,7 +536,7 @@ impl AutocryptSetupMessage {
/// Returns the TSK consuming the `AutocryptSetupMessage` in the
/// process.
- pub fn to_tsk(self) -> TSK {
+ pub fn into_tsk(self) -> TSK {
self.tsk
}
}
@@ -978,7 +978,7 @@ In the light of the Efail vulnerability I am asking myself if it's
let asm = asm.parse().unwrap();
// A basic check to make sure we got the key.
- assert_eq!(asm.to_tsk().tpk().fingerprint(),
+ assert_eq!(asm.into_tsk().tpk().fingerprint(),
Fingerprint::from_hex(
"E604 68CE 44D7 7C3F CE9F D072 71DB C565 7FDE 65A7")
.unwrap());
diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs
index 9c64f7d9..d1c80f9c 100644
--- a/openpgp/src/message/mod.rs
+++ b/openpgp/src/message/mod.rs
@@ -371,11 +371,6 @@ impl Message {
Self::from_packet_pile(PacketPile::from_packets(packets))
}
- /// Converts the `Message` to a `PacketPile`.
- pub fn to_packet_pile(self) -> PacketPile {
- self.pile
- }
-
/// Returns the body of the message.
///
/// Returns `None` if no literal data packet is found. This
@@ -392,6 +387,12 @@ impl Message {
}
}
+impl From<Message> for PacketPile {
+ fn from(m: Message) -> Self {
+ m.pile
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -681,7 +682,7 @@ mod tests {
let mut packets = Vec::new();
let mut lit = Literal::new(Text);
lit.set_body(b"data".to_vec());
- packets.push(lit.to_packet());
+ packets.push(lit.into());
let message = Message::from_packets(packets);
assert!(message.is_ok(), "{:?}", message);
@@ -698,8 +699,8 @@ mod tests {
let mut packets = Vec::new();
packets.push(
CompressedData::new(CompressionAlgorithm::Uncompressed)
- .push(lit.clone().to_packet())
- .to_packet());
+ .push(lit.clone().into())
+ .into());
let message = Message::from_packets(packets);
assert!(message.is_ok(), "{:?}", message);
@@ -711,9 +712,9 @@ mod tests {
let mut packets = Vec::new();
packets.push(
CompressedData::new(CompressionAlgorithm::Uncompressed)
- .push(lit.clone().to_packet())
- .push(lit.clone().to_packet())
- .to_packet());
+ .push(lit.clone().into())
+ .push(lit.clone().into())
+ .into());
let message = Message::from_packets(packets);
assert!(message.is_err(), "{:?}", message);
@@ -725,9 +726,9 @@ mod tests {
let mut packets = Vec::new();
packets.push(
CompressedData::new(CompressionAlgorithm::Uncompressed)
- .push(lit.clone().to_packet())
- .to_packet());
- packets.push(lit.clone().to_packet());
+ .push(lit.clone().into())
+ .into());
+ packets.push(lit.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_err(), "{:?}", message);
@@ -741,9 +742,9 @@ mod tests {
CompressedData::new(CompressionAlgorithm::Uncompressed)
.push(CompressedData::new(CompressionAlgorithm::Uncompressed)
.push(lit.clone()
- .to_packet())
- .to_packet())
- .to_packet());
+ .into())
+ .into())
+ .into());
let message = Message::from_packets(packets);
assert!(message.is_ok(), "{:?}", message);
@@ -769,7 +770,7 @@ mod tests {
// 0: OnePassSig
// => bad.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
let message = Message::from_packets(packets);
assert!(message.is_err(), "{:?}", message);
@@ -778,8 +779,8 @@ mod tests {
// 1: Literal
// => bad.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
- packets.push(lit.clone().to_packet());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
+ packets.push(lit.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_err(), "{:?}", message);
@@ -789,9 +790,9 @@ mod tests {
// 2: Signature
// => good.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
- packets.push(lit.clone().to_packet());
- packets.push(sig.clone().to_packet());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
+ packets.push(lit.clone().into());
+ packets.push(sig.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_ok(), "{:?}", message);
@@ -802,10 +803,10 @@ mod tests {
// 3: Signature
// => bad.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
- packets.push(lit.clone().to_packet());
- packets.push(sig.clone().to_packet());
- packets.push(sig.clone().to_packet());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
+ packets.push(lit.clone().into());
+ packets.push(sig.clone().into());
+ packets.push(sig.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_err(), "{:?}", message);
@@ -817,11 +818,11 @@ mod tests {
// 4: Signature
// => good.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
- packets.push(lit.clone().to_packet());
- packets.push(sig.clone().to_packet());
- packets.push(sig.clone().to_packet());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
+ packets.push(lit.clone().into());
+ packets.push(sig.clone().into());
+ packets.push(sig.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_ok(), "{:?}", message);
@@ -834,12 +835,12 @@ mod tests {
// 5: Signature
// => bad.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
- packets.push(lit.clone().to_packet());
- packets.push(lit.clone().to_packet());
- packets.push(sig.clone().to_packet());
- packets.push(sig.clone().to_packet());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
+ packets.push(lit.clone().into());
+ packets.push(lit.clone().into());
+ packets.push(sig.clone().into());
+ packets.push(sig.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_err(), "{:?}", message);
@@ -852,14 +853,14 @@ mod tests {
// 4: Signature
// => good.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
- packets.push(OnePassSig::new(SignatureType::Binary).to_packet());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
+ packets.push(OnePassSig::new(SignatureType::Binary).into());
packets.push(
CompressedData::new(CompressionAlgorithm::Uncompressed)
- .push(lit.clone().to_packet())
- .to_packet());
- packets.push(sig.clone().to_packet());
- packets.push(sig.clone().to_packet());
+ .push(lit.clone().into())
+ .into());
+ packets.push(sig.clone().into());
+ packets.push(sig.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_ok(), "{:?}", message);
@@ -885,7 +886,7 @@ mod tests {
// 0: Signature
// => bad.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(sig.clone().to_packet());
+ packets.push(sig.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_err(), "{:?}", message);
@@ -894,8 +895,8 @@ mod tests {
// 1: Literal
// => good.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(sig.clone().to_packet());
- packets.push(lit.clone().to_packet());
+ packets.push(sig.clone().into());
+ packets.push(lit.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_ok(), "{:?}", message);
@@ -905,9 +906,9 @@ mod tests {
// 2: Literal
// => good.
let mut packets : Vec<Packet> = Vec::new();
- packets.push(sig.clone().to_packet());
- packets.push(sig.clone().to_packet());
- packets.push(lit.clone().to_packet());
+ packets.push(sig.clone().into());
+ packets.push(sig.clone().into());
+ packets.push(lit.clone().into());
let message = Message::from_packets(packets);
assert!(message.is_ok(), "{:?}", message);
@@ -932,14 +933,14 @@ mod tests {
SymmetricAlgorithm::AES256,
S2K::Simple { hash: HashAlgorithm::SHA256 },
&sk,
- &"12345678".into()).unwrap().to_packet());
+ &"12345678".into()).unwrap().into());
let message = Message::from_packets(packets.clone());
assert!(message.is_err(), "{:?}", message);
// 0: SK-ESK
// 1: Literal
// => bad.
- packets.push(lit.clone().to_packet());
+ packets.push(lit.clone().into());
assert!(packets.iter().map(|p| p.tag()).collect::<Vec<Tag>>()
== [ Tag::SKESK, Tag::Literal ]);
@@ -955,9 +956,9 @@ mod tests {
let mut seip = SEIP::new();
seip.common.children = Some(Container::new());
seip.common.children.as_mut().unwrap().push(
- lit.clone().to_packet());
+ lit.clone().into());
seip.common.children.as_mut().unwrap().push(
- MDC::for_hash(Default::default()).to_packet());
+ MDC::for_hash(Default::default()).into());
packets[1] = Packet::SEIP(seip);
assert!(packets.iter().map(|p| p.tag()).collect::<Vec<Tag>>()
@@ -1020,7 +1021,7 @@ mod tests {
// 1: MDC
// 3: Literal
// => bad.
- packets[3] = lit.clone().to_packet();
+ packets[3] = lit.clone().into();
assert!(packets.iter().map(|p| p.tag()).collect::<Vec<Tag>>()
== [ Tag::SKESK, Tag::SKESK, Tag::SEIP, Tag::Literal ]);
@@ -1036,7 +1037,7 @@ mod tests {
// 2: Literal
// => bad.
packets.remove(3);
- packets[2].children.as_mut().unwrap().push(lit.clone().to_packet());
+ packets[2].children.as_mut().unwrap().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/aed.rs b/openpgp/src/packet/aed.rs
index 8edc4dc2..7bf23bcb 100644
--- a/openpgp/src/packet/aed.rs
+++ b/openpgp/src/packet/aed.rs
@@ -121,16 +121,11 @@ impl AED {
pub fn set_iv(&mut self, iv: Box<[u8]>) {
self.iv = iv;
}
-
- /// Convert the `AED` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::AED(self)
- }
}
impl From<AED> for Packet {
fn from(s: AED) -> Self {
- s.to_packet()
+ Packet::AED(s)
}
}
diff --git a/openpgp/src/packet/compressed_data.rs b/openpgp/src/packet/compressed_data.rs
index 36771232..cda495ba 100644
--- a/openpgp/src/packet/compressed_data.rs
+++ b/openpgp/src/packet/compressed_data.rs
@@ -76,16 +76,11 @@ impl CompressedData {
self.common.children.as_mut().unwrap().insert(i, packet);
self
}
-
- /// Convert the `CompressedData` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::CompressedData(self)
- }
}
impl From<CompressedData> for Packet {
fn from(s: CompressedData) -> Self {
- s.to_packet()
+ Packet::CompressedData(s)
}
}
diff --git a/openpgp/src/packet/literal.rs b/openpgp/src/packet/literal.rs
index 05a8047d..48b31775 100644
--- a/openpgp/src/packet/literal.rs
+++ b/openpgp/src/packet/literal.rs
@@ -163,16 +163,11 @@ impl Literal {
self.date = timestamp.map(|t| t.canonicalize())
.unwrap_or(time::Tm::from_pgp(0));
}
-
- /// Convert the `Literal` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::Literal(self)
- }
}
impl From<Literal> for Packet {
fn from(s: Literal) -> Self {
- s.to_packet()
+ Packet::Literal(s)
}
}
diff --git a/openpgp/src/packet/mdc.rs b/openpgp/src/packet/mdc.rs
index 0a217639..1ee61ed5 100644
--- a/openpgp/src/packet/mdc.rs
+++ b/openpgp/src/packet/mdc.rs
@@ -56,11 +56,6 @@ impl MDC {
&self.computed_hash[..]
}
- /// Converts the `MDC` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::MDC(self)
- }
-
/// Returns whether the data protected by the MDC is valid.
pub fn valid(&self) -> bool {
if self.hash == [ 0; 20 ] {
@@ -75,6 +70,6 @@ impl MDC {
impl From<MDC> for Packet {
fn from(s: MDC) -> Self {
- s.to_packet()
+ Packet::MDC(s)
}
}
diff --git a/openpgp/src/packet/one_pass_sig.rs b/openpgp/src/packet/one_pass_sig.rs
index ae174652..d094bb58 100644
--- a/openpgp/src/packet/one_pass_sig.rs
+++ b/openpgp/src/packet/one_pass_sig.rs
@@ -140,16 +140,11 @@ impl OnePassSig {
pub fn set_last_raw(&mut self, last: u8) {
self.last = last;
}
-
- /// Convert the `OnePassSig` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::OnePassSig(self)
- }
}
impl From<OnePassSig> for Packet {
fn from(s: OnePassSig) -> Self {
- s.to_packet()
+ Packet::OnePassSig(s)
}
}
diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs
index 7b77cf7b..eb049bdd 100644
--- a/openpgp/src/packet/pkesk.rs
+++ b/openpgp/src/packet/pkesk.rs
@@ -209,16 +209,11 @@ impl PKESK {
.into())
}
}
-
- /// Convert the `PKESK` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::PKESK(self)
- }
}
impl From<PKESK> for Packet {
fn from(s: PKESK) -> Self {
- s.to_packet()
+ Packet::PKESK(s)
}
}
diff --git a/openpgp/src/packet/seip.rs b/openpgp/src/packet/seip.rs
index 9d27684a..02f0e818 100644
--- a/openpgp/src/packet/seip.rs
+++ b/openpgp/src/packet/seip.rs
@@ -28,16 +28,11 @@ impl SEIP {
pub fn version(&self) -> u8 {
self.version
}
-
- /// Convert the `SEIP` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::SEIP(self)
- }
}
impl From<SEIP> for Packet {
fn from(s: SEIP) -> Self {
- s.to_packet()
+ Packet::SEIP(s)
}
}
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs
index 1bd5b31b..940314e2 100644
--- a/openpgp/src/packet/signature/mod.rs
+++ b/openpgp/src/packet/signature/mod.rs
@@ -796,16 +796,11 @@ impl Signature {
self.verify_hash(signer, self.hash_algo(), &digest[..])
}
-
- /// Convert the `Signature` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::Signature(self)
- }
}
impl From<Signature> for Packet {
fn from(s: Signature) -> Self {
- s.to_packet()
+ Packet::Signature(s)
}
}
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index a082bf0d..48059a62 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -2238,7 +2238,7 @@ impl signature::Builder {
pub fn set_embedded_signature(mut self, signature: Signature)
-> Result<Self> {
self.unhashed_area.replace(Subpacket::new(
- SubpacketValue::EmbeddedSignature(signature.to_packet()),
+ SubpacketValue::EmbeddedSignature(signature.into()),
true)?)?;
Ok(self)
diff --git a/openpgp/src/packet/skesk.rs b/openpgp/src/packet/skesk.rs
index eb4ff03f..f0515cc4 100644
--- a/openpgp/src/packet/skesk.rs
+++ b/openpgp/src/packet/skesk.rs
@@ -173,10 +173,6 @@ impl SKESK4 {
}
/// Convert the `SKESK4` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::SKESK(SKESK::V4(self))
- }
-
/// Derives the key inside this SKESK4 from `password`. Returns a
/// tuple of the symmetric cipher to use with the key and the key
/// itself.
@@ -223,7 +219,7 @@ impl SKESK4 {
impl From<SKESK4> for Packet {
fn from(s: SKESK4) -> Self {
- s.to_packet()
+ Packet::SKESK(SKESK::V4(s))
}
}
@@ -387,16 +383,11 @@ impl SKESK5 {
pub fn set_aead_digest(&mut self, digest: Box<[u8]>) {
self.aead_digest = digest;
}
-
- /// Convert the `SKESK5` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::SKESK(SKESK::V5(self))
- }
}
impl From<SKESK5> for Packet {
fn from(s: SKESK5) -> Self {
- s.to_packet()
+ Packet::SKESK(SKESK::V5(s))
}
}
diff --git a/openpgp/src/packet/unknown.rs b/openpgp/src/packet/unknown.rs
index 0819c375..ca7d40e6 100644
--- a/openpgp/src/packet/unknown.rs
+++ b/openpgp/src/packet/unknown.rs
@@ -52,15 +52,10 @@ impl Unknown {
pub fn set_body(&mut self, data: Vec<u8>) {
self.common.body = Some(data);
}
-
- /// Convert the `Unknown` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::Unknown(self)
- }
}
impl From<Unknown> for Packet {
fn from(s: Unknown) -> Self {
- s.to_packet()
+ Packet::Unknown(s)
}
}
diff --git a/openpgp/src/packet/user_attribute.rs b/openpgp/src/packet/user_attribute.rs
index d07fea66..38007a8c 100644
--- a/openpgp/src/packet/user_attribute.rs
+++ b/openpgp/src/packet/user_attribute.rs
@@ -62,16 +62,11 @@ impl UserAttribute {
pub fn set_user_attribute(&mut self, value: &[u8]) {
self.value = value.to_vec();
}
-
- /// Convert the `UserAttribute` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::UserAttribute(self)
- }
}
impl From<UserAttribute> for Packet {
fn from(s: UserAttribute) -> Self {
- s.to_packet()
+ Packet::UserAttribute(s)
}
}
diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs
index d88b06b2..e3dcf625 100644
--- a/openpgp/src/packet/userid.rs
+++ b/openpgp/src/packet/userid.rs
@@ -83,16 +83,11 @@ impl UserID {
pub fn set_userid(&mut self, userid: &str) {
self.set_userid_from_bytes(userid.as_bytes())
}
-
- /// Convert the `UserID` struct to a `Packet`.
- pub fn to_packet(self) -> Packet {
- Packet::UserID(self)
- }
}
impl From<UserID> for Packet {
fn from(s: UserID) -> Self {
- s.to_packet()
+ Packet::UserID(s)
}
}
diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs
index 8d5ef64e..cd550cfc 100644
--- a/openpgp/src/packet_pile.rs
+++ b/openpgp/src/packet_pile.rs
@@ -209,15 +209,15 @@ impl PacketPile {
/// literal.set_body(b"old".to_vec());
/// let mut pile = PacketPile::from_packet(
/// CompressedData::new(CompressionAlgorithm::Uncompressed)
- /// .push(literal.to_packet())
- /// .to_packet());
+ /// .push(literal.into())
+ /// .into());
///
/// // Replace the literal data packet.
/// let mut literal = Literal::new(DataFormat::Text);
/// literal.set_body(b"new".to_vec());
/// pile.re