diff options
-rw-r--r-- | openpgp/build.rs | 34 | ||||
-rw-r--r-- | openpgp/src/crypto/keygrip.rs | 8 | ||||
-rw-r--r-- | openpgp/src/crypto/mod.rs | 3 | ||||
-rw-r--r-- | openpgp/src/crypto/mpis.rs | 8 | ||||
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 10 | ||||
-rw-r--r-- | openpgp/src/crypto/symmetric.rs | 34 | ||||
-rw-r--r-- | openpgp/src/lib.rs | 9 | ||||
-rw-r--r-- | openpgp/src/packet/key.rs | 14 | ||||
-rw-r--r-- | openpgp/src/packet/mod.rs | 10 | ||||
-rw-r--r-- | openpgp/src/packet/pkesk.rs | 51 | ||||
-rw-r--r-- | openpgp/src/packet/signature/mod.rs | 67 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 20 | ||||
-rw-r--r-- | openpgp/src/packet_pile.rs | 30 | ||||
-rw-r--r-- | openpgp/src/parse/packet_pile_parser.rs | 18 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 93 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 63 | ||||
-rw-r--r-- | openpgp/src/serialize/mod.rs | 27 | ||||
-rw-r--r-- | openpgp/src/tests.rs | 41 |
18 files changed, 216 insertions, 324 deletions
diff --git a/openpgp/build.rs b/openpgp/build.rs index 76042853..18cf91db 100644 --- a/openpgp/build.rs +++ b/openpgp/build.rs @@ -1,3 +1,7 @@ +use std::env; +use std::fs; +use std::io::{self, Write}; +use std::path::PathBuf; extern crate lalrpop; // Rerun if any of these files change: @@ -9,4 +13,34 @@ const SOURCE: [ &'static str; 2 ] fn main() { lalrpop::process_root().unwrap(); + include_test_data().unwrap(); +} + +/// Builds the index of the test data for use with the `::tests` +/// module. +fn include_test_data() -> io::Result<()> { + let cwd = env::current_dir()?; + let mut sink = fs::File::create( + PathBuf::from(env::var_os("OUT_DIR").unwrap()) + .join("tests.index.rs.inc")).unwrap(); + + writeln!(&mut sink, "{{")?; + let mut dirs = vec![PathBuf::from("tests/data")]; + while let Some(dir) = dirs.pop() { + println!("rerun-if-changed={}", dir.to_str().unwrap()); + for entry in fs::read_dir(dir).unwrap() { + let entry = entry?; + let path = entry.path(); + if path.is_file() { + writeln!( + &mut sink, " add!({:?}, {:?});", + path.components().skip(2).collect::<PathBuf>(), + cwd.join(path))?; + } else if path.is_dir() { + dirs.push(path.clone()); + } + } + } + writeln!(&mut sink, "}}")?; + Ok(()) } diff --git a/openpgp/src/crypto/keygrip.rs b/openpgp/src/crypto/keygrip.rs index 3d1a84bd..feccebc4 100644 --- a/openpgp/src/crypto/keygrip.rs +++ b/openpgp/src/crypto/keygrip.rs @@ -211,15 +211,9 @@ fn ecc_param(curve: &Curve, i: usize) -> MPI { #[cfg(test)] mod tests { - use std::path::PathBuf; use super::*; use ::conversions::from_hex; - fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "keys", artifact] - .iter().collect() - } - /// Test vectors from libgcrypt/tests/basic.c. #[test] fn libgcrypt_basic() { @@ -337,7 +331,7 @@ mod tests { "erika-corinna-daniela-simone-antonia-nistp384.pgp", "erika-corinna-daniela-simone-antonia-nistp521.pgp", ] - .iter().map(|n| (n, ::TPK::from_file(path_to(n)).unwrap())) + .iter().map(|n| (n, ::TPK::from_bytes(::tests::key(n)).unwrap())) { eprintln!("{}", name); for key in tpk.keys_all() { diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs index 362c1e58..e75e4ccb 100644 --- a/openpgp/src/crypto/mod.rs +++ b/openpgp/src/crypto/mod.rs @@ -214,7 +214,6 @@ pub fn hash_file<R: Read>(reader: R, algos: &[HashAlgorithm]) #[test] fn hash_file_test() { use std::collections::HashMap; - use std::fs::File; let expected: HashMap<HashAlgorithm, &str> = [ (HashAlgorithm::SHA1, "7945E3DA269C25C04F9EF435A5C0F25D9662C771"), @@ -222,7 +221,7 @@ fn hash_file_test() { ].iter().cloned().collect(); let result = - hash_file(File::open(::path_to("a-cypherpunks-manifesto.txt")).unwrap(), + hash_file(::std::io::Cursor::new(::tests::manifesto()), &expected.keys().cloned().collect::<Vec<HashAlgorithm>>()) .unwrap(); diff --git a/openpgp/src/crypto/mpis.rs b/openpgp/src/crypto/mpis.rs index 1a954eb5..febececb 100644 --- a/openpgp/src/crypto/mpis.rs +++ b/openpgp/src/crypto/mpis.rs @@ -871,15 +871,9 @@ impl Arbitrary for Signature { #[cfg(test)] mod tests { use super::*; - use std::path::PathBuf; use parse::Parse; use serialize::Serialize; - fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "keys", artifact] - .iter().collect() - } - quickcheck! { fn mpi_roundtrip(mpi: MPI) -> bool { let mut buf = Vec::new(); @@ -939,7 +933,7 @@ mod tests { ("erika-corinna-daniela-simone-antonia-nistp384.pgp", 0, 384), ("erika-corinna-daniela-simone-antonia-nistp521.pgp", 0, 521), ] { - let tpk = ::TPK::from_file(path_to(name)).unwrap(); + let tpk = ::TPK::from_bytes(::tests::key(name)).unwrap(); let key = tpk.keys_all().nth(*key_no).unwrap().2; assert_eq!(key.mpis().bits().unwrap(), *bits, "TPK {}, key no {}", name, *key_no); diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index c280e23d..7c10781e 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -265,12 +265,6 @@ mod tests { use parse::{Parse, PacketParser}; use serialize::Serialize; - use std::path::PathBuf; - fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "messages", "s2k", artifact] - .iter().collect() - } - #[test] fn s2k_parser_test() { use packet::SKESK; @@ -375,8 +369,8 @@ mod tests { ]; for test in tests.iter() { - let path = path_to(test.filename); - let mut pp = PacketParser::from_file(path).unwrap().unwrap(); + let path = ::tests::message(&format!("s2k/{}", test.filename)); + let mut pp = PacketParser::from_bytes(path).unwrap().unwrap(); if let Packet::SKESK(SKESK::V4(ref skesk)) = pp.packet { assert_eq!(skesk.symmetric_algo(), test.cipher_algo); assert_eq!(skesk.s2k(), &test.s2k); diff --git a/openpgp/src/crypto/symmetric.rs b/openpgp/src/crypto/symmetric.rs index 1a174a4a..d2a94b15 100644 --- a/openpgp/src/crypto/symmetric.rs +++ b/openpgp/src/crypto/symmetric.rs @@ -512,19 +512,7 @@ impl<W: io::Write> Drop for Encryptor<W> { #[cfg(test)] mod tests { use super::*; - use std::fs::File; - use std::io::{Read, Write}; - use std::path::PathBuf; - - const PLAINTEXT: &[u8] - = include_bytes!("../../tests/data/messages/a-cypherpunks-manifesto.txt"); - - #[cfg(test)] - #[allow(dead_code)] - fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", artifact] - .iter().collect() - } + use std::io::{Cursor, Read, Write}; /// This test is designed to test the buffering logic in Decryptor /// by reading directly from it (i.e. without any buffering @@ -541,10 +529,10 @@ mod tests { key[0] = i as u8; } - let filename = path_to(&format!( + let filename = &format!( "raw/a-cypherpunks-manifesto.aes{}.key_ascending_from_0", - algo.key_size().unwrap() * 8)[..]); - let ciphertext = File::open(filename).unwrap(); + algo.key_size().unwrap() * 8); + let ciphertext = Cursor::new(::tests::file(filename)); let decryptor = Decryptor::new(*algo, &key, ciphertext).unwrap(); // Read bytewise to test the buffer logic. @@ -553,7 +541,7 @@ mod tests { plaintext.push(b.unwrap()); } - assert_eq!(&PLAINTEXT[..], &plaintext[..]); + assert_eq!(::tests::manifesto(), &plaintext[..]); } } @@ -576,15 +564,15 @@ mod tests { .unwrap(); // Write bytewise to test the buffer logic. - for b in PLAINTEXT.chunks(1) { + for b in ::tests::manifesto().chunks(1) { encryptor.write_all(b).unwrap(); } } - let filename = path_to(&format!( + let filename = format!( "raw/a-cypherpunks-manifesto.aes{}.key_ascending_from_0", - algo.key_size().unwrap() * 8)[..]); - let mut cipherfile = File::open(filename).unwrap(); + algo.key_size().unwrap() * 8); + let mut cipherfile = Cursor::new(::tests::file(&filename)); let mut reference = Vec::new(); cipherfile.read_to_end(&mut reference).unwrap(); assert_eq!(&reference[..], &ciphertext[..]); @@ -616,7 +604,7 @@ mod tests { let mut encryptor = Encryptor::new(*algo, &key, &mut ciphertext) .unwrap(); - encryptor.write_all(PLAINTEXT).unwrap(); + encryptor.write_all(::tests::manifesto()).unwrap(); } let mut plaintext = Vec::new(); @@ -628,7 +616,7 @@ mod tests { decryptor.read_to_end(&mut plaintext).unwrap(); } - assert_eq!(&plaintext[..], &PLAINTEXT[..]); + assert_eq!(&plaintext[..], &::tests::manifesto()[..]); } } } diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 63179a34..c9fe4ff5 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -134,15 +134,6 @@ mod keyid; #[cfg(test)] mod tests; -#[cfg(test)] -use std::path::PathBuf; - -#[cfg(test)] -fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "messages", artifact] - .iter().collect() -} - /// Returns a timestamp for the tests. /// /// The time is chosen to that the subkeys in diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 1cc90455..c1fce733 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -703,21 +703,15 @@ mod tests { use TPK; use packet::pkesk::PKESK3; use packet::key::SecretKey; - use std::path::PathBuf; use super::*; use PacketPile; use serialize::SerializeKey; use parse::Parse; - fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "keys", artifact] - .iter().collect() - } - #[test] fn encrypted_rsa_key() { - let mut tpk = TPK::from_file( - path_to("testy-new-encrypted-with-123.pgp")).unwrap(); + let mut tpk = TPK::from_bytes( + ::tests::key("testy-new-encrypted-with-123.pgp")).unwrap(); let pair = tpk.primary_mut(); let pk_algo = pair.pk_algo(); let secret = pair.secret.as_mut().unwrap(); @@ -1011,8 +1005,8 @@ mod tests { #[test] fn fingerprint_test() { - let path = path_to("public-key.gpg"); - let pile = PacketPile::from_file(&path).unwrap(); + let pile = + PacketPile::from_bytes(::tests::key("public-key.gpg")).unwrap(); // The blob contains a public key and a three subkeys. let mut pki = 0; diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index 6f23f26a..e7529e32 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -546,15 +546,9 @@ impl<'a> Iterator for PacketPathIter<'a> { // Tests the `paths`() iter and `path_ref`(). #[test] fn packet_path_iter() { - use std::path::PathBuf; use parse::Parse; use PacketPile; - fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "messages", artifact] - .iter().collect() - } - fn paths(iter: slice::Iter<Packet>) -> Vec<Vec<usize>> { let mut lpaths : Vec<Vec<usize>> = Vec::new(); for (i, packet) in iter.enumerate() { @@ -573,8 +567,8 @@ fn packet_path_iter() { } for i in 1..5 { - let pile = PacketPile::from_file( - path_to(&format!("recursive-{}.gpg", i)[..])).unwrap(); + let pile = PacketPile::from_bytes( + ::tests::message(&format!("recursive-{}.gpg", i)[..])).unwrap(); let mut paths1 : Vec<Vec<usize>> = Vec::new(); for path in paths(pile.children()).iter() { diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs index bc31360f..b3ebdfb6 100644 --- a/openpgp/src/packet/pkesk.rs +++ b/openpgp/src/packet/pkesk.rs @@ -241,7 +241,6 @@ mod tests { use PacketPile; use packet::key::SecretKey; use Packet; - use std::path::PathBuf; use parse::Parse; use serialize::SerializeInto; @@ -253,22 +252,12 @@ mod tests { } } - fn path_to_key(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "keys", artifact] - .iter().collect() - } - - fn path_to_msg(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "messages", artifact] - .iter().collect() - } - #[test] fn decrypt_rsa() { - let tpk = TPK::from_file( - path_to_key("testy-private.pgp")).unwrap(); - let pile = PacketPile::from_file( - path_to_msg("encrypted-to-testy.gpg")).unwrap(); + let tpk = TPK::from_bytes( + ::tests::key("testy-private.pgp")).unwrap(); + let pile = PacketPile::from_bytes( + ::tests::message("encrypted-to-testy.gpg")).unwrap(); let pair = tpk.subkeys().next().unwrap().subkey(); if let Some(SecretKey::Unencrypted{ mpis: ref sec }) = pair.secret() { @@ -288,10 +277,10 @@ mod tests { #[test] fn decrypt_ecdh_cv25519() { - let tpk = TPK::from_file( - path_to_key("testy-new-private.pgp")).unwrap(); - let pile = PacketPile::from_file( - path_to_msg("encrypted-to-testy-new.pgp")).unwrap(); + let tpk = TPK::from_bytes( + ::tests::key("testy-new-private.pgp")).unwrap(); + let pile = PacketPile::from_bytes( + ::tests::message("encrypted-to-testy-new.pgp")).unwrap(); let pair = tpk.subkeys().next().unwrap().subkey(); if let Some(SecretKey::Unencrypted{ mpis: ref sec }) = pair.secret() { @@ -311,10 +300,10 @@ mod tests { #[test] fn decrypt_ecdh_nistp256() { - let tpk = TPK::from_file( - path_to_key("testy-nistp256-private.pgp")).unwrap(); - let pile = PacketPile::from_file( - path_to_msg("encrypted-to-testy-nistp256.pgp")).unwrap(); + let tpk = TPK::from_bytes( + ::tests::key("testy-nistp256-private.pgp")).unwrap(); + let pile = PacketPile::from_bytes( + ::tests::message("encrypted-to-testy-nistp256.pgp")).unwrap(); let pair = tpk.subkeys().next().unwrap().subkey(); if let Some(SecretKey::Unencrypted{ mpis: ref sec }) = pair.secret() { @@ -334,10 +323,10 @@ mod tests { #[test] fn decrypt_ecdh_nistp384() { - let tpk = TPK::from_file( - path_to_key("testy-nistp384-private.pgp")).unwrap(); - let pile = PacketPile::from_file( - path_to_msg("encrypted-to-testy-nistp384.pgp")).unwrap(); + let tpk = TPK::from_bytes( + ::tests::key("testy-nistp384-private.pgp")).unwrap(); + let pile = PacketPile::from_bytes( + ::tests::message("encrypted-to-testy-nistp384.pgp")).unwrap(); let pair = tpk.subkeys().next().unwrap().subkey(); if let Some(SecretKey::Unencrypted{ mpis: ref sec }) = pair.secret() { @@ -357,10 +346,10 @@ mod tests { #[test] fn decrypt_ecdh_nistp521() { - let tpk = TPK::from_file( - path_to_key("testy-nistp521-private.pgp")).unwrap(); - let pile = PacketPile::from_file( - path_to_msg("encrypted-to-testy-nistp521.pgp")).unwrap(); + let tpk = TPK::from_bytes( + ::tests::key("testy-nistp521-private.pgp")).unwrap(); + let pile = PacketPile::from_bytes( + ::tests::message("encrypted-to-testy-nistp521.pgp")).unwrap(); let pair = tpk.subkeys().next().unwrap().subkey(); if let Some(SecretKey::Unencrypted{ mpis: ref sec }) = pair.secret() { diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index 555eb31d..756fc96d 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -27,20 +27,10 @@ use serialize::SerializeInto; use nettle::{self, dsa, ecc, ecdsa, ed25519, rsa}; use nettle::rsa::verify_digest_pkcs1; -#[cfg(test)] -use std::path::PathBuf; - pub mod subpacket; const TRACE : bool = false; -#[cfg(test)] -#[allow(dead_code)] -fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", artifact] - .iter().collect() -} - /// Builds a signature packet. /// /// This is the mutable version of a `Signature4` packet. To convert @@ -1035,12 +1025,11 @@ mod test { eprintln!("{}, expect {} good signatures:", test.data, test.good); - let tpk = TPK::from_file( - path_to(&format!("keys/{}", test.key)[..])).unwrap(); + let tpk = TPK::from_bytes(::tests::key(test.key)).unwrap(); let mut good = 0; - let mut ppr = PacketParser::from_file( - path_to(&format!("messages/{}", test.data)[..])).unwrap(); + let mut ppr = PacketParser::from_bytes( + ::tests::message(test.data)).unwrap(); while let PacketParserResult::Some(mut pp) = ppr { if let Packet::Signature(ref sig) = pp.packet { let result = sig.verify(tpk.primary()).unwrap_or(false); @@ -1071,8 +1060,8 @@ mod test { #[test] fn signature_level() { use PacketPile; - let p = PacketPile::from_file( - path_to("messages/signed-1-notarized-by-ed25519.pgp")).unwrap() + let p = PacketPile::from_bytes( + ::tests::message("signed-1-notarized-by-ed25519.pgp")).unwrap() .into_children().collect::<Vec<Packet>>(); if let Packet::Signature(ref sig) = &p[3] { @@ -1097,14 +1086,14 @@ mod test { Yarrow::default().random(&mut hash); for key in &[ - "keys/testy-private.pgp", - "keys/dennis-simon-anton-private.pgp", - "keys/erika-corinna-daniela-simone-antonia-nistp256-private.pgp", - "keys/erika-corinna-daniela-simone-antonia-nistp384-private.pgp", - "keys/erika-corinna-daniela-simone-antonia-nistp521-private.pgp", - "keys/emmelie-dorothea-dina-samantha-awina-ed25519-private.pgp", + "testy-private.pgp", + "dennis-simon-anton-private.pgp", + "erika-corinna-daniela-simone-antonia-nistp256-private.pgp", + "erika-corinna-daniela-simone-antonia-nistp384-private.pgp", + "erika-corinna-daniela-simone-antonia-nistp521-private.pgp", + "emmelie-dorothea-dina-samantha-awina-ed25519-private.pgp", ] { - let tpk = TPK::from_file(path_to(key)).unwrap(); + let tpk = TPK::from_bytes(::tests::key(key)).unwrap(); let pair = tpk.primary(); if let Some(SecretKey::Unencrypted{ mpis: ref sec }) = pair.secret() { @@ -1160,26 +1149,12 @@ mod test { #[test] fn verify_message() { - use std::fs::File; - use std::io::Read; - - let tpk = TPK::from_file(path_to( - "keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp")) + let tpk = TPK::from_bytes(::tests::key( + "emmelie-dorothea-dina-samantha-awina-ed25519.pgp")).unwrap(); + let msg = ::tests::manifesto(); + let sig = Signature::from_bytes( + ::tests::message("a-cypherpunks-manifesto.txt.ed25519.sig")) .unwrap(); - let msg = { - let mut fd = File::open( - path_to("messages/a-cypherpunks-manifesto.txt")).unwrap(); - let mut buf = Vec::default(); - - fd.read_to_end(&mut buf).unwrap(); - buf - }; - let sig = { - let mut fd = File::open(path_to( - "messages/a-cypherpunks-manifesto.txt.ed25519.sig")).unwrap(); - - Signature::from_reader(&mut fd).unwrap() - }; assert!(sig.verify_message(tpk.primary(), &msg[..]).unwrap()); } @@ -1224,15 +1199,15 @@ mod test { fn verify_gpg_3rd_party_cert() { use TPK; - let test1 = TPK::from_file( - path_to("keys/test1-certification-key.pgp")).unwrap(); + let test1 = TPK::from_bytes( + ::tests::key("test1-certification-key.pgp")).unwrap(); let cert_key1 = test1.keys_all() .certification_capable() .nth(0) .map(|x| x.2) .unwrap(); - let test2 = TPK::from_file( - path_to("keys/test2-signed-by-test1.pgp")).unwrap(); + let test2 = TPK::from_bytes( + ::tests::key("test2-signed-by-test1.pgp")).unwrap(); let uid_binding = &test2.primary_key_signature_full().unwrap().0.unwrap(); let cert = &uid_binding.certifications()[0]; diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index ea87ddf8..302a16ba 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -91,15 +91,6 @@ use conversions::{ Time, Duration, }; - -#[cfg(test)] -use std::path::PathBuf; - -#[cfg(test)] -fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "messages", artifact] - .iter().collect() -} /// The subpacket types specified by [Section 5.2.3.1 of RFC 4880]. /// @@ -2667,8 +2658,7 @@ fn subpacket_test_1 () { use PacketPile; use parse::Parse; - let path = path_to("signed.gpg"); - let pile = PacketPile::from_file(&path).unwrap(); + let pile = PacketPile::from_bytes(::tests::message("signed.gpg")).unwrap(); eprintln!("PacketPile has {} top-level packets.", pile.children().len()); eprintln!("PacketPile: {:?}", pile); @@ -2750,8 +2740,8 @@ fn subpacket_test_2() { // // XXX: The subpackets marked with * are not tested. - let pile = PacketPile::from_file( - path_to("../keys/subpackets/shaw.gpg")).unwrap(); + let pile = PacketPile::from_bytes( + ::tests::key("subpackets/shaw.gpg")).unwrap(); // Test #1 if let (Some(&Packet::PublicKey(ref key)), @@ -2955,8 +2945,8 @@ fn subpacket_test_2() { })); } - let pile = PacketPile::from_file( - path_to("../keys/subpackets/marven.gpg")).unwrap(); + let pile = PacketPile::from_bytes( + ::tests::key("subpackets/marven.gpg")).unwrap(); // Test #3 if let Some(&Packet::Signature(ref sig)) = pile.children().nth(1) { diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 55d44e56..11b34b1a 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -20,16 +20,6 @@ use parse::Cookie; macro_rules! bytes { ( $x:expr ) => { include_bytes!(concat!("../tests/data/messages/", $x)) }; } - -#[cfg(test)] -use std::path::PathBuf; - -#[cfg(test)] -#[allow(dead_code)] -fn path_to(artifact: &str) -> PathBuf { - [env!("CARGO_MANIFEST_DIR"), "tests", "data", "messages", artifact] - .iter().collect() -} impl fmt::Debug for PacketPile { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -458,8 +448,8 @@ mod test { fn deserialize_test_2 () { // A message containing a compressed packet that contains a // literal packet. - let path = path_to("compressed-data-algo-1.gpg"); - let pile = PacketPile::from_file(&path).unwrap(); + let pile = PacketPile::from_bytes( + ::tests::message("compressed-data-algo-1.gpg")).unwrap(); eprintln!("PacketPile has {} top-level packets.", pile.children().len()); eprintln!("PacketPile: {:?}", pile); @@ -475,8 +465,8 @@ mod test { #[cfg(feature = "compression-deflate")] #[test] fn deserialize_test_3 () { - let path = path_to("signed.gpg"); - let pile = PacketPile::from_file(&path).unwrap(); + let pile = + Pack |