summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-05-13 13:13:22 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-05-13 14:47:51 +0200
commit6ecb30381b3e7f5efd1f46808566aa75c339b658 (patch)
tree44ff47bbb53ddd31e63048e16d770dce2af8de84
parent34687bd6dd750edaadfc76ba0bbe28dd401dd655 (diff)
openpgp: New module containing the test data.
-rw-r--r--openpgp/src/lib.rs3
-rw-r--r--openpgp/src/serialize/tpk.rs48
-rw-r--r--openpgp/src/tests.rs53
3 files changed, 62 insertions, 42 deletions
diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs
index 0b27440f..63179a34 100644
--- a/openpgp/src/lib.rs
+++ b/openpgp/src/lib.rs
@@ -132,6 +132,9 @@ mod fingerprint;
mod keyid;
#[cfg(test)]
+mod tests;
+
+#[cfg(test)]
use std::path::PathBuf;
#[cfg(test)]
diff --git a/openpgp/src/serialize/tpk.rs b/openpgp/src/serialize/tpk.rs
index 3a046572..21cd2047 100644
--- a/openpgp/src/serialize/tpk.rs
+++ b/openpgp/src/serialize/tpk.rs
@@ -447,48 +447,12 @@ mod test {
use parse::Parse;
use serialize::Serialize;
- fn test_tpk(name: &str) -> Result<TPK> {
- let path = format!("tests/data/keys/{}.pgp", name);
- TPK::from_file(path)
- }
-
- fn test_tsk(name: &str) -> Result<TPK> {
- let path = format!("tests/data/keys/{}-private.pgp", name);
- TPK::from_file(path)
- }
-
- const PUBLIC_TESTS: &[&str] = &[
- "dennis-simon-anton",
- "dsa2048-elgamal3072",
- "emmelie-dorothea-dina-samantha-awina-ed25519",
- "erika-corinna-daniela-simone-antonia-nistp256",
- "erika-corinna-daniela-simone-antonia-nistp384",
- "erika-corinna-daniela-simone-antonia-nistp521",
- "testy-new",
- "testy",
- "neal",
- "dkg-sigs-out-of-order",
- ];
- const SECRET_TESTS: &[&str] = &[
- "dennis-simon-anton",
- "dsa2048-elgamal3072",
- "emmelie-dorothea-dina-samantha-awina-ed25519",
- "erika-corinna-daniela-simone-antonia-nistp256",
- "erika-corinna-daniela-simone-antonia-nistp384",
- "erika-corinna-daniela-simone-antonia-nistp521",
- "testy-new",
- "testy-nistp256",
- "testy-nistp384",
- "testy-nistp521",
- "testy",
- ];
-
/// Demonstrates that public keys and all components are
/// serialized.
#[test]
fn roundtrip_tpk() {
- for test in PUBLIC_TESTS {
- let tpk = match test_tpk(dbg!(test)) {
+ for test in ::tests::TPKS {
+ let tpk = match TPK::from_bytes(test.bytes) {
Ok(t) => t,
Err(_) => continue,
};
@@ -504,8 +468,8 @@ mod test {
/// serialized.
#[test]
fn roundtrip_tsk() {
- for test in SECRET_TESTS {
- let tpk = test_tsk(test).unwrap();
+ for test in ::tests::TSKS {
+ let tpk = TPK::from_bytes(test.bytes).unwrap();
assert!(tpk.is_tsk());
let mut buf = Vec::new();
@@ -527,8 +491,8 @@ mod test {
/// reduces to TPK::serialize().
#[test]
fn reduce_to_tpk_serialize() {
- for test in SECRET_TESTS {
- let tpk = test_tsk(test).unwrap();
+ for test in ::tests::TSKS {
+ let tpk = TPK::from_bytes(test.bytes).unwrap();
assert!(tpk.is_tsk());
// First, use TPK::serialize().
diff --git a/openpgp/src/tests.rs b/openpgp/src/tests.rs
new file mode 100644
index 00000000..cc8aa569
--- /dev/null
+++ b/openpgp/src/tests.rs
@@ -0,0 +1,53 @@
+//! Test data for Sequoia.
+//!
+//! This module includes the test data from `openpgp/tests/data` in a
+//! structured way.
+
+use std::fmt;
+
+pub struct Test {
+ path: &'static str,
+ pub bytes: &'static [u8],
+}
+
+impl fmt::Display for Test {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "openpgp/tests/data/{}", self.path)
+ }
+}
+
+macro_rules! t {
+ ( $path: expr ) => {
+ &Test {
+ path: $path,
+ bytes: include_bytes!(concat!("../tests/data/", $path)),
+ }
+ }
+}
+
+pub const TPKS: &[&Test] = &[
+ t!("keys/dennis-simon-anton.pgp"),
+ t!("keys/dsa2048-elgamal3072.pgp"),
+ t!("keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp"),
+ t!("keys/erika-corinna-daniela-simone-antonia-nistp256.pgp"),
+ t!("keys/erika-corinna-daniela-simone-antonia-nistp384.pgp"),
+ t!("keys/erika-corinna-daniela-simone-antonia-nistp521.pgp"),
+ t!("keys/testy-new.pgp"),
+ t!("keys/testy.pgp"),
+ t!("keys/neal.pgp"),
+ t!("keys/dkg-sigs-out-of-order.pgp"),
+];
+
+pub const TSKS: &[&Test] = &[
+ t!("keys/dennis-simon-anton-private.pgp"),
+ t!("keys/dsa2048-elgamal3072-private.pgp"),
+ t!("keys/emmelie-dorothea-dina-samantha-awina-ed25519-private.pgp"),
+ t!("keys/erika-corinna-daniela-simone-antonia-nistp256-private.pgp"),
+ t!("keys/erika-corinna-daniela-simone-antonia-nistp384-private.pgp"),
+ t!("keys/erika-corinna-daniela-simone-antonia-nistp521-private.pgp"),
+ t!("keys/testy-new-private.pgp"),
+ t!("keys/testy-nistp256-private.pgp"),
+ t!("keys/testy-nistp384-private.pgp"),
+ t!("keys/testy-nistp521-private.pgp"),
+ t!("keys/testy-private.pgp"),
+];