From 446dfdbcb63af00daa3a777958419e1dfb6fc737 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 11 Sep 2019 16:12:21 +0200 Subject: openpgp: Make Parse::from_bytes polymorphic over AsRef<[u8]>. - A drawback of this change is that currently AsRef<[u8]> is not implemented for [u8; _], only for specific lengths. This is a compiler limitation that may be lifted in the future. This limitation required fixing some tests, notably those using include_bytes!. - Fixes #296. --- store/src/lib.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'store/src') diff --git a/store/src/lib.rs b/store/src/lib.rs index 9e710a9b..59e73063 100644 --- a/store/src/lib.rs +++ b/store/src/lib.rs @@ -157,7 +157,7 @@ impl Store { /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let tpk = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// let key = Store::import(&ctx, &tpk)?; /// assert_eq!(key.tpk()?.fingerprint(), tpk.fingerprint()); /// # Ok(()) @@ -193,7 +193,7 @@ impl Store { /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let tpk = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// Store::import(&ctx, &tpk)?; /// let key = Store::lookup(&ctx, &tpk.fingerprint())?; /// assert_eq!(key.tpk()?.fingerprint(), tpk.fingerprint()); @@ -228,7 +228,7 @@ impl Store { /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let tpk = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// Store::import(&ctx, &tpk)?; /// let key = Store::lookup_by_keyid(&ctx, &tpk.fingerprint().to_keyid())?; /// assert_eq!(key.tpk()?.fingerprint(), tpk.fingerprint()); @@ -264,7 +264,7 @@ impl Store { /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let tpk = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/neal.pgp")) + /// # &include_bytes!("../../openpgp/tests/data/keys/neal.pgp")[..]) /// # .unwrap(); /// Store::import(&ctx, &tpk)?; /// @@ -412,7 +412,7 @@ impl Mapping { /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let tpk = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; /// mapping.import("Testy McTestface", &tpk)?; /// # Ok(()) @@ -483,7 +483,7 @@ impl Mapping { /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let tpk = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp")) + /// # &include_bytes!("../../openpgp/tests/data/keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp")[..]) /// # .unwrap(); /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; /// mapping.import("Emmelie", &tpk)?; @@ -683,9 +683,9 @@ impl Binding { /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let old = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// # let new = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")[..]).unwrap(); /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; /// mapping.import("Testy McTestface", &old)?; /// // later... @@ -738,9 +738,9 @@ impl Binding { /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let old = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// # let new = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")[..]).unwrap(); /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; /// mapping.import("Testy McTestface", &old)?; /// // later... @@ -890,9 +890,9 @@ impl Key { /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let old = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// # let new = TPK::from_bytes( - /// # include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")).unwrap(); + /// # &include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")[..]).unwrap(); /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; /// let fp = Fingerprint::from_hex("3E8877C877274692975189F5D03F6F865226FE8B").unwrap(); /// let binding = mapping.add("Testy McTestface", &fp)?; @@ -1267,7 +1267,7 @@ mod test { .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); - let tpk = TPK::from_bytes(bytes!("testy.pgp")).unwrap(); + let tpk = TPK::from_bytes(&bytes!("testy.pgp")[..]).unwrap(); mapping.import("Mr. McTestface", &tpk).unwrap(); let binding = mapping.lookup("Mr. McTestface").unwrap(); let tpk_retrieved = binding.tpk().unwrap(); @@ -1295,7 +1295,7 @@ mod test { .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); - let tpk = TPK::from_bytes(bytes!("testy.pgp")).unwrap(); + let tpk = TPK::from_bytes(&bytes!("testy.pgp")[..]).unwrap(); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); let binding = mapping.add("Mister B.", &fp).unwrap(); let r = binding.import(&tpk); -- cgit v1.2.3