summaryrefslogtreecommitdiffstats
path: root/store/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'store/src/lib.rs')
-rw-r--r--store/src/lib.rs139
1 files changed, 68 insertions, 71 deletions
diff --git a/store/src/lib.rs b/store/src/lib.rs
index 1d2d65ac..5a718128 100644
--- a/store/src/lib.rs
+++ b/store/src/lib.rs
@@ -16,12 +16,10 @@
//!
//! [network policy]: ../sequoia_core/enum.NetworkPolicy.html
//!
-//! # Example
+//! # Examples
//!
//! ```
-//! # extern crate sequoia_openpgp as openpgp;
-//! # extern crate sequoia_core;
-//! # extern crate sequoia_store;
+//! # use sequoia_openpgp as openpgp;
//! # use openpgp::Fingerprint;
//! # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
//! # use sequoia_store::*;
@@ -50,14 +48,11 @@
#![warn(missing_docs)]
-extern crate capnp;
+use capnp;
#[macro_use]
extern crate capnp_rpc;
-extern crate futures;
-extern crate rand;
-extern crate rusqlite;
-extern crate tokio_core;
-extern crate tokio_io;
+use futures;
+use tokio_core;
use std::cell::RefCell;
use std::fmt;
@@ -69,12 +64,10 @@ use futures::{Future};
use std::time;
use tokio_core::reactor::Core;
-extern crate sequoia_openpgp as openpgp;
+use sequoia_openpgp as openpgp;
#[allow(unused_imports)]
-#[macro_use]
-extern crate sequoia_core;
-extern crate sequoia_ipc;
-extern crate sequoia_net;
+use sequoia_core;
+use sequoia_ipc;
use crate::openpgp::Fingerprint;
use crate::openpgp::KeyID;
@@ -133,12 +126,10 @@ impl Store {
/// Imports a key into the common key pool.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
/// # use openpgp::Cert;
/// # use openpgp::parse::Parse;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
@@ -169,12 +160,10 @@ impl Store {
/// Looks up a key in the common key pool.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
/// # use openpgp::Cert;
/// # use openpgp::parse::Parse;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
@@ -204,12 +193,10 @@ impl Store {
/// Looks up a key in the common key pool by KeyID.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
/// # use openpgp::Cert;
/// # use openpgp::parse::Parse;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
@@ -240,12 +227,10 @@ impl Store {
///
/// The KeyID may also reference a subkey.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
/// # use openpgp::{Cert, KeyID};
/// # use openpgp::parse::Parse;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
@@ -357,12 +342,10 @@ impl Mapping {
/// Adds a key identified by fingerprint to the mapping.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
/// # use openpgp::Fingerprint;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
/// # use sequoia_store::*;
@@ -388,12 +371,10 @@ impl Mapping {
/// Imports a key into the mapping.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
/// # use openpgp::Cert;
/// # use openpgp::parse::Parse;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
@@ -423,12 +404,10 @@ impl Mapping {
/// Returns the binding for the given label.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
/// # use openpgp::Fingerprint;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
/// # use sequoia_store::*;
@@ -459,12 +438,10 @@ impl Mapping {
///
/// The KeyID may also reference a subkey.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
/// # use openpgp::{Cert, KeyID};
/// # use openpgp::parse::Parse;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
@@ -504,12 +481,11 @@ impl Mapping {
/// Deletes this mapping.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # #[macro_use] extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
+ /// # #[macro_use] use sequoia_core;
/// # use openpgp::Fingerprint;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
/// # use sequoia_store::*;
@@ -596,12 +572,10 @@ impl Binding {
/// Returns stats for this binding.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
/// # use openpgp::Fingerprint;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
/// # use sequoia_store::*;
@@ -659,12 +633,11 @@ impl Binding {
/// conflict, either by ignoring the new key, or by using
/// `Binding::rotate` to force a rotation.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # #[macro_use] extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
+ /// # #[macro_use] use sequoia_core;
/// # use openpgp::Cert;
/// # use openpgp::parse::Parse;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
@@ -714,12 +687,11 @@ impl Binding {
/// You could simply ask Alice to call her communication partner
/// Bob and confirm that he rotated his keys.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # #[macro_use] extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
+ /// # #[macro_use] use sequoia_core;
/// # use openpgp::Cert;
/// # use openpgp::parse::Parse;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
@@ -759,12 +731,11 @@ impl Binding {
/// Deletes this binding.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # #[macro_use] extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
+ /// # #[macro_use] use sequoia_core;
/// # use openpgp::Fingerprint;
/// # use sequoia_core::{Context, NetworkPolicy, IPCPolicy};
/// # use sequoia_store::*;
@@ -865,12 +836,11 @@ impl Key {
/// If the new key does not match the current key,
/// `Error::Conflict` is returned.
///
- /// # Example
+ /// # Examples
///
/// ```
- /// # extern crate sequoia_openpgp as openpgp;
- /// # #[macro_use] extern crate sequoia_core;
- /// # extern crate sequoia_store;
+ /// # use sequoia_openpgp as openpgp;
+ /// # #[macro_use] use sequoia_core;
/// # use openpgp::Fingerprint;
/// # use openpgp::Cert;
/// # use openpgp::parse::Parse;
@@ -1212,6 +1182,33 @@ mod test {
use super::*;
use crate::openpgp::parse::Parse;
+ // Like assert!, but checks a pattern.
+ //
+ // assert_match!(Some(_) = x);
+ //
+ // Note: For modules to see this macro, we need to define it before we
+ // declare the modules.
+ #[allow(unused_macros)]
+ macro_rules! assert_match {
+ ( $error: pat = $expr:expr, $fmt:expr, $($pargs:expr),* ) => {{
+ let x = $expr;
+ if let $error = x {
+ /* Pass. */
+ } else {
+ let extra = format!($fmt, $($pargs),*);
+ panic!("Expected {}, got {:?}{}{}",
+ stringify!($error), x,
+ if $fmt.len() > 0 { ": " } else { "." }, extra);
+ }
+ }};
+ ( $error: pat = $expr: expr, $fmt:expr ) => {
+ assert_match!($error = $expr, $fmt, );
+ };
+ ( $error: pat = $expr: expr ) => {
+ assert_match!($error = $expr, "");
+ };
+ }
+
macro_rules! bytes {
( $x:expr ) => { include_bytes!(concat!("../../openpgp/tests/data/keys/", $x)) };
}