diff options
Diffstat (limited to 'store')
-rw-r--r-- | store/src/backend/mod.rs | 68 | ||||
-rw-r--r-- | store/src/lib.rs | 173 | ||||
-rw-r--r-- | store/tests/ipc-policy.rs | 17 |
3 files changed, 128 insertions, 130 deletions
diff --git a/store/src/backend/mod.rs b/store/src/backend/mod.rs index 9947b28c..8e913436 100644 --- a/store/src/backend/mod.rs +++ b/store/src/backend/mod.rs @@ -285,10 +285,10 @@ impl MappingServer { MappingServer{c: c, id: id} } - fn open(c: Rc<Connection>, realm: &str, policy: core::NetworkPolicy, name: &str) + fn open(c: Rc<Connection>, realm: &str, policy: net::Policy, name: &str) -> Result<Self> { // We cannot implement ToSql and friends for - // core::NetworkPolicy, hence we need to do it by foot. + // net::Policy, hence we need to do it by foot. let p: u8 = (&policy).into(); c.execute( @@ -300,14 +300,14 @@ impl MappingServer { |row| Ok((row.get(0)?, row.get(1)?)))?; // We cannot implement FromSql and friends for - // core::NetworkPolicy, hence we need to do it by foot. + // net::Policy, hence we need to do it by foot. if mapping_policy < 0 || mapping_policy > 3 { return Err(super::Error::ProtocolError.into()); } - let mapping_policy = core::NetworkPolicy::from(mapping_policy as u8); + let mapping_policy = net::Policy::from(mapping_policy as u8); if mapping_policy != policy { - return Err(core::Error::NetworkPolicyViolation(mapping_policy) + return Err(net::Error::PolicyViolation(mapping_policy) .into()); } @@ -839,7 +839,7 @@ impl KeyServer { } /// Returns when the next key using the given policy should be updated. - fn next_update_at(c: &Rc<Connection>, network_policy: core::NetworkPolicy) + fn next_update_at(c: &Rc<Connection>, network_policy: net::Policy) -> Option<Timestamp> { let network_policy_u8 = u8::from(&network_policy); @@ -856,7 +856,7 @@ impl KeyServer { } /// Returns the number of keys using the given policy. - fn need_update(c: &Rc<Connection>, network_policy: core::NetworkPolicy) + fn need_update(c: &Rc<Connection>, network_policy: net::Policy) -> Result<u32> { let network_policy_u8 = u8::from(&network_policy); @@ -872,11 +872,11 @@ impl KeyServer { /// Helper for `update`. fn update_helper(c: &Rc<Connection>, - network_policy: core::NetworkPolicy) + network_policy: net::Policy) -> Result<(KeyServer, openpgp::KeyID, net::KeyServer)> { - assert!(network_policy != core::NetworkPolicy::Offline); + assert!(network_policy != net::Policy::Offline); let network_policy_u8 = u8::from(&network_policy); // Select the key that was updated least recently. @@ -892,9 +892,7 @@ impl KeyServer { let fingerprint = fingerprint.parse::<openpgp::Fingerprint>() .map_err(|_| node::Error::SystemError)?; - let ctx = core::Context::configure() - .network_policy(network_policy).build()?; - let keyserver = net::KeyServer::keys_openpgp_org(&ctx)?; + let keyserver = net::KeyServer::keys_openpgp_org(network_policy)?; Ok((KeyServer::new(c.clone(), id), fingerprint.into(), @@ -903,7 +901,7 @@ impl KeyServer { /// Updates the key that was least recently updated. async fn update(c: &Rc<Connection>, - network_policy: core::NetworkPolicy) + network_policy: net::Policy) -> Result<Duration> { let (key, id, mut keyserver) = Self::update_helper(c, network_policy)?; @@ -938,7 +936,7 @@ impl KeyServer { /// Perform periodic housekeeping. async fn start_housekeeping(c: Rc<Connection>) { loop { - let duration = Self::update(&c, core::NetworkPolicy::Encrypted).await; + let duration = Self::update(&c, net::Policy::Encrypted).await; let duration = duration.unwrap_or(min_sleep_time()); tokio::time::delay_for(random_duration(duration)).await; @@ -1110,11 +1108,11 @@ impl node::mapping_iter::Server for MappingIterServer { |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)))); // We cannot implement FromSql and friends for - // core::NetworkPolicy, hence we need to do it by foot. + // net::Policy, hence we need to do it by foot. if network_policy < 0 || network_policy > 3 { fail!(node::Error::SystemError); } - let network_policy = core::NetworkPolicy::from(network_policy as u8); + let network_policy = net::Policy::from(network_policy as u8); let mut entry = pry!(results.get().get_result()).init_ok(); entry.set_realm(&realm); @@ -1255,17 +1253,17 @@ impl From<anyhow::Error> for node::Error { } } - if let Some(e) = e.downcast_ref::<core::Error>() { + if let Some(e) = e.downcast_ref::<net::Error>() { return match e { - &core::Error::NetworkPolicyViolation(p) => + &net::Error::PolicyViolation(p) => match p { - core::NetworkPolicy::Offline => + net::Policy::Offline => node::Error::NetworkPolicyViolationOffline, - core::NetworkPolicy::Anonymized => + net::Policy::Anonymized => node::Error::NetworkPolicyViolationAnonymized, - core::NetworkPolicy::Encrypted => + net::Policy::Encrypted => node::Error::NetworkPolicyViolationEncrypted, - core::NetworkPolicy::Insecure => + net::Policy::Insecure => node::Error::NetworkPolicyViolationInsecure, }, _ => unreachable!(), @@ -1399,30 +1397,30 @@ CREATE TABLE log ( /* Miscellaneous. */ -impl<'a> From<&'a core::NetworkPolicy> for node::NetworkPolicy { - fn from(policy: &core::NetworkPolicy) -> Self { +impl<'a> From<&'a net::Policy> for node::NetworkPolicy { + fn from(policy: &net::Policy) -> Self { match policy { - &core::NetworkPolicy::Offline => node::NetworkPolicy::Offline, - &core::NetworkPolicy::Anonymized => node::NetworkPolicy::Anonymized, - &core::NetworkPolicy::Encrypted => node::NetworkPolicy::Encrypted, - &core::NetworkPolicy::Insecure => node::NetworkPolicy::Insecure, + &net::Policy::Offline => node::NetworkPolicy::Offline, + &net::Policy::Anonymized => node::NetworkPolicy::Anonymized, + &net::Policy::Encrypted => node::NetworkPolicy::Encrypted, + &net::Policy::Insecure => node::NetworkPolicy::Insecure, } } } -impl From<core::NetworkPolicy> for node::NetworkPolicy { - fn from(policy: core::NetworkPolicy) -> Self { +impl From<net::Policy> for node::NetworkPolicy { + fn from(policy: net::Policy) -> Self { (&policy).into() } } -impl From<node::NetworkPolicy> for core::NetworkPolicy { +impl From<node::NetworkPolicy> for net::Policy { fn from(policy: node::NetworkPolicy) -> Self { match policy { - node::NetworkPolicy::Offline => core::NetworkPolicy::Offline, - node::NetworkPolicy::Anonymized => core::NetworkPolicy::Anonymized, - node::NetworkPolicy::Encrypted => core::NetworkPolicy::Encrypted, - node::NetworkPolicy::Insecure => core::NetworkPolicy::Insecure, + node::NetworkPolicy::Offline => net::Policy::Offline, + node::NetworkPolicy::Anonymized => net::Policy::Anonymized, + node::NetworkPolicy::Encrypted => net::Policy::Encrypted, + node::NetworkPolicy::Insecure => net::Policy::Insecure, } } } diff --git a/store/src/lib.rs b/store/src/lib.rs index d91bd59c..93b6402c 100644 --- a/store/src/lib.rs +++ b/store/src/lib.rs @@ -14,22 +14,23 @@ //! Sequoia updates keys in compliance with the [network policy] used //! to create the mapping. //! -//! [network policy]: ../sequoia_core/enum.NetworkPolicy.html +//! [network policy]: ../sequoia_net/enum.Policy.html //! //! # Examples //! //! ``` //! # use sequoia_openpgp as openpgp; //! # use openpgp::Fingerprint; -//! # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; +//! # use sequoia_core::{Context, IPCPolicy}; +//! # use sequoia_net as net; //! # use sequoia_store::*; //! # fn main() { f().unwrap(); } //! # fn f() -> Result<()> { //! # let ctx = Context::configure() -//! # .network_policy(NetworkPolicy::Offline) //! # .ipc_policy(IPCPolicy::Internal) //! # .ephemeral().build()?; -//! let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; +//! let mapping = Mapping::open(&ctx, net::Policy::Offline, +//! REALM_CONTACTS, "default")?; //! //! let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); //! let binding = mapping.add("Mister B.", &fp)?; @@ -63,7 +64,7 @@ use capnp_rpc::rpc_twoparty_capnp::Side; use sequoia_openpgp as openpgp; #[allow(unused_imports)] -use sequoia_core; +use sequoia_core as core; use sequoia_ipc; use crate::openpgp::Fingerprint; @@ -71,9 +72,9 @@ use crate::openpgp::KeyID; use crate::openpgp::Cert; use crate::openpgp::parse::Parse; use crate::openpgp::serialize::Serialize; -use sequoia_core as core; use sequoia_core::Context; use sequoia_ipc as ipc; +use sequoia_net as net; #[allow(dead_code)] mod store_protocol_capnp; use crate::store_protocol_capnp::node; @@ -151,12 +152,11 @@ impl Store { /// # use sequoia_openpgp as openpgp; /// # use openpgp::Cert; /// # use openpgp::parse::Parse; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; /// # use sequoia_store::{Store, Result}; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let cert = Cert::from_bytes( @@ -185,12 +185,11 @@ impl Store { /// # use sequoia_openpgp as openpgp; /// # use openpgp::Cert; /// # use openpgp::parse::Parse; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; /// # use sequoia_store::{Store, Result}; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let cert = Cert::from_bytes( @@ -218,12 +217,11 @@ impl Store { /// # use sequoia_openpgp as openpgp; /// # use openpgp::Cert; /// # use openpgp::parse::Parse; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; /// # use sequoia_store::{Store, Result}; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let cert = Cert::from_bytes( @@ -252,12 +250,11 @@ impl Store { /// # use sequoia_openpgp as openpgp; /// # use openpgp::{Cert, KeyID}; /// # use openpgp::parse::Parse; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; /// # use sequoia_store::{Store, Result}; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let cert = Cert::from_bytes( @@ -333,12 +330,13 @@ impl Mapping { /// of the context that created the mapping in the first place. /// Opening the mapping with a different network policy is /// forbidden. - pub fn open(c: &Context, realm: &str, name: &str) -> Result<Self> { + pub fn open(c: &Context, p: net::Policy, realm: &str, name: &str) + -> Result<Self> { let (mut core, client) = Store::connect(c)?; let mut request = client.open_request(); request.get().set_realm(realm); - request.get().set_network_policy(c.network_policy().into()); + request.get().set_network_policy(p.into()); request.get().set_ephemeral(c.ephemeral()); request.get().set_name(name); @@ -366,15 +364,16 @@ impl Mapping { /// ``` /// # use sequoia_openpgp as openpgp; /// # use openpgp::Fingerprint; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); /// mapping.add("Mister B.", &fp)?; /// # Ok(()) @@ -396,17 +395,18 @@ impl Mapping { /// # use sequoia_openpgp as openpgp; /// # use openpgp::Cert; /// # use openpgp::parse::Parse; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let cert = Cert::from_bytes( /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// mapping.import("Testy McTestface", &cert)?; /// # Ok(()) /// # } @@ -428,20 +428,22 @@ impl Mapping { /// ``` /// # use sequoia_openpgp as openpgp; /// # use openpgp::Fingerprint; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); /// mapping.add("Mister B.", &fp)?; /// drop(mapping); /// // ... - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// let binding = mapping.lookup("Mister B.")?; /// # Ok(()) /// # } @@ -463,18 +465,19 @@ impl Mapping { /// # use sequoia_openpgp as openpgp; /// # use openpgp::{Cert, KeyID}; /// # use openpgp::parse::Parse; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let cert = Cert::from_bytes( /// # &include_bytes!("../../openpgp/tests/data/keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp")[..]) /// # .unwrap(); - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// mapping.import("Emmelie", &cert)?; /// /// // Lookup by the primary key's KeyID. @@ -506,20 +509,22 @@ impl Mapping { /// # use sequoia_openpgp as openpgp; /// # #[macro_use] use sequoia_core; /// # use openpgp::Fingerprint; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); /// mapping.add("Mister B.", &fp)?; /// mapping.delete()?; /// // ... - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// let binding = mapping.lookup("Mister B."); /// assert!(binding.is_err()); // not found /// # Ok(()) @@ -596,15 +601,16 @@ impl Binding { /// ``` /// # use sequoia_openpgp as openpgp; /// # use openpgp::Fingerprint; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// /// let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); /// let binding = mapping.add("Mister B.", &fp)?; @@ -659,19 +665,20 @@ impl Binding { /// # #[macro_use] use sequoia_core; /// # use openpgp::Cert; /// # use openpgp::parse::Parse; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let old = Cert::from_bytes( /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// # let new = Cert::from_bytes( /// # &include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")[..]).unwrap(); - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// mapping.import("Testy McTestface", &old)?; /// // later... /// let binding = mapping.lookup("Testy McTestface")?; @@ -713,19 +720,20 @@ impl Binding { /// # #[macro_use] use sequoia_core; /// # use openpgp::Cert; /// # use openpgp::parse::Parse; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let old = Cert::from_bytes( /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// # let new = Cert::from_bytes( /// # &include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")[..]).unwrap(); - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// mapping.import("Testy McTestface", &old)?; /// // later... /// let binding = mapping.lookup("Testy McTestface")?; @@ -756,15 +764,16 @@ impl Binding { /// # use sequoia_openpgp as openpgp; /// # #[macro_use] use sequoia_core; /// # use openpgp::Fingerprint; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); /// let binding = mapping.add("Mister B.", &fp)?; /// binding.delete()?; @@ -863,19 +872,20 @@ impl Key { /// # use openpgp::Fingerprint; /// # use openpgp::Cert; /// # use openpgp::parse::Parse; - /// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy}; + /// # use sequoia_core::{Context, IPCPolicy}; + /// # use sequoia_net as net; /// # use sequoia_store::*; /// # fn main() { f().unwrap(); } /// # fn f() -> Result<()> { /// # let ctx = Context::configure() - /// # .network_policy(NetworkPolicy::Offline) /// # .ipc_policy(IPCPolicy::Internal) /// # .ephemeral().build()?; /// # let old = Cert::from_bytes( /// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap(); /// # let new = Cert::from_bytes( /// # &include_bytes!("../../openpgp/tests/data/keys/testy-new.pgp")[..]).unwrap(); - /// let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default")?; + /// let mapping = Mapping::open(&ctx, net::Policy::Offline, + /// REALM_CONTACTS, "default")?; /// let fp = "3E8877C877274692975189F5D03F6F865226FE8B".parse().unwrap(); /// let binding = mapping.add("Testy McTestface", &fp)?; /// let key = binding.key()?; @@ -1036,7 +1046,7 @@ pub struct MappingIter { } impl Iterator for MappingIter { - type Item = (String, String, core::NetworkPolicy, Mapping); + type Item = (String, String, net::Policy, Mapping); fn next(&mut self) -> Option<Self::Item> { let request = self.iter.next_request(); @@ -1152,13 +1162,13 @@ impl From<node::Error> for anyhow::Error { node::Error::MalformedFingerprint => Error::MalformedFingerprint.into(), node::Error::NetworkPolicyViolationOffline => - core::Error::NetworkPolicyViolation(core::NetworkPolicy::Offline).into(), + net::Error::PolicyViolation(net::Policy::Offline).into(), node::Error::NetworkPolicyViolationAnonymized => - core::Error::NetworkPolicyViolation(core::NetworkPolicy::Anonymized).into(), + net::Error::PolicyViolation(net::Policy::Anonymized).into(), node::Error::NetworkPolicyViolationEncrypted => - core::Error::NetworkPolicyViolation(core::NetworkPolicy::Encrypted).into(), + net::Error::PolicyViolation(net::Policy::Encrypted).into(), node::Error::NetworkPolicyViolationInsecure => - core::Error::NetworkPolicyViolation(core::NetworkPolicy::Insecure).into(), + net::Error::PolicyViolation(net::Policy::Insecure).into(), } } } @@ -1232,34 +1242,34 @@ mod test { ( $x:expr ) => { include_bytes!(concat!("../../openpgp/tests/data/keys/", $x)) }; } + const P: net::Policy = net::Policy::Offline; + #[test] fn mapping_network_policy_mismatch() { let ctx = core::Context::configure() .ephemeral() - .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); // Create mapping. - Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); let ctx2 = core::Context::configure() .home(ctx.home()) - .network_policy(core::NetworkPolicy::Encrypted) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let mapping = Mapping::open(&ctx2, REALM_CONTACTS, "default"); - assert_match!(core::Error::NetworkPolicyViolation(_) - = mapping.err().unwrap().downcast::<core::Error>().unwrap()); + let mapping = Mapping::open(&ctx2, net::Policy::Encrypted, + REALM_CONTACTS, "default"); + assert_match!(net::Error::PolicyViolation(_) + = mapping.err().unwrap().downcast::<net::Error>().unwrap()); } #[test] fn import_key() { let ctx = core::Context::configure() .ephemeral() - .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); let cert = Cert::from_bytes(&bytes!("testy.pgp")[..]).unwrap(); mapping.import("Mr. McTestface", &cert).unwrap(); let binding = mapping.lookup("Mr. McTestface").unwrap(); @@ -1271,10 +1281,9 @@ mod test { fn key_not_found() { let ctx = core::Context::configure() .ephemeral() - .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); let r = mapping.lookup("I do not exist"); assert_match!(Error::NotFound = r.err().unwrap().downcast::<Error>().unwrap()); @@ -1284,10 +1293,9 @@ mod test { fn add_then_import_wrong_key() { let ctx = core::Context::configure() .ephemeral() - .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); let cert = Cert::from_bytes(&bytes!("testy.pgp")[..]).unwrap(); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); let binding = mapping.add("Mister B.", &fp).unwrap(); @@ -1300,10 +1308,9 @@ mod test { fn add_then_add_different_key() { let ctx = core::Context::configure() .ephemeral() - .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); let b = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); mapping.add("Mister B.", &b).unwrap(); let c = Fingerprint::from_bytes(b"cccccccccccccccccccc"); @@ -1316,11 +1323,10 @@ mod test { fn delete_mapping_twice() { let ctx = core::Context::configure() .ephemeral() - .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let s0 = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); - let s1 = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let s0 = Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); + let s1 = Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); s0.delete().unwrap(); s1.delete().unwrap(); } @@ -1329,11 +1335,10 @@ mod test { fn delete_mapping_then_use() { let ctx = core::Context::configure() .ephemeral() - .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let s0 = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); - let s1 = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let s0 = Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); + let s1 = Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); s0.delete().unwrap(); let binding = s1.lookup("Foobarbaz"); assert_match!(Error::NotFound @@ -1348,10 +1353,9 @@ mod test { fn delete_binding_twice() { let ctx = core::Context::configure() .ephemeral() - .network_policy(core::NetworkPolicy::Offline) .ipc_policy(core::IPCPolicy::Internal) .build().unwrap(); - let mapping = Mapping::open(&ctx, REALM_CONTACTS, "default").unwrap(); + let mapping = Mapping::open(&ctx, P, REALM_CONTACTS, "default").unwrap(); let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); let b0 = mapping.add("Mister B.", &fp).unwrap(); let b1 = mapping.lookup("Mister B.").unwrap(); @@ -1363,10 +1367,9 @@ mod test { fn delete_binding_then_use() { let ctx = core::Context::co |