summaryrefslogtreecommitdiffstats
path: root/tool
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-05-15 16:28:11 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-05-15 16:29:55 +0200
commita25ef6974e0ba3989f6205c19a1f9ccfc81db584 (patch)
tree4ce3b386923515a662051c40f67a135ee15681f6 /tool
parent36e2d97ac013e023feb27df939c3f6d6e32d8669 (diff)
core, store, tool: Use realm instead of domain.
- Remove the domain parameter from core::Context. - Replace it with a realm to be passed in when opening a store. - For sq, merge store name and realm into the --store parameter. - Fixes #105.
Diffstat (limited to 'tool')
-rw-r--r--tool/src/sq.rs39
-rw-r--r--tool/src/sq_cli.rs11
2 files changed, 26 insertions, 24 deletions
diff --git a/tool/src/sq.rs b/tool/src/sq.rs
index 1902e8bd..b18bada4 100644
--- a/tool/src/sq.rs
+++ b/tool/src/sq.rs
@@ -100,15 +100,20 @@ fn real_main() -> Result<(), failure::Error> {
},
};
let force = matches.is_present("force");
- let domain_name =
- matches.value_of("domain").unwrap_or("org.sequoia-pgp.sq");
- let mut builder = Context::configure(domain_name)
+ let (realm_name, store_name) = {
+ let s = matches.value_of("store").expect("has a default value");
+ if let Some(i) = s.find('/') {
+ (&s[..i], &s[i+1..])
+ } else {
+ (s, "default")
+ }
+ };
+ let mut builder = Context::configure()
.network_policy(policy);
if let Some(dir) = matches.value_of("home") {
builder = builder.home(dir);
}
let ctx = builder.build()?;
- let store_name = matches.value_of("store").unwrap_or("default");
match matches.subcommand() {
("decrypt", Some(m)) => {
@@ -122,7 +127,7 @@ fn real_main() -> Result<(), failure::Error> {
let secrets = m.values_of("secret-key-file")
.map(load_tpks)
.unwrap_or(Ok(vec![]))?;
- let mut store = Store::open(&ctx, store_name)
+ let mut store = Store::open(&ctx, realm_name, store_name)
.context("Failed to open the store")?;
commands::decrypt(&ctx, &mut store,
&mut input, &mut output,
@@ -140,7 +145,7 @@ fn real_main() -> Result<(), failure::Error> {
} else {
output
};
- let mut store = Store::open(&ctx, store_name)
+ let mut store = Store::open(&ctx, realm_name, store_name)
.context("Failed to open the store")?;
let recipients = m.values_of("recipient")
.map(|r| r.collect())
@@ -181,7 +186,7 @@ fn real_main() -> Result<(), failure::Error> {
let tpks = m.values_of("public-key-file")
.map(load_tpks)
.unwrap_or(Ok(vec![]))?;
- let mut store = Store::open(&ctx, store_name)
+ let mut store = Store::open(&ctx, realm_name, store_name)
.context("Failed to open the store")?;
commands::verify(&ctx, &mut store, &mut input,
detached.as_mut().map(|r| r as &mut io::Read),
@@ -335,12 +340,12 @@ fn real_main() -> Result<(), failure::Error> {
}
},
("store", Some(m)) => {
- let store = Store::open(&ctx, store_name)
+ let store = Store::open(&ctx, realm_name, store_name)
.context("Failed to open the store")?;
match m.subcommand() {
("list", Some(_)) => {
- list_bindings(&store, domain_name, store_name)?;
+ list_bindings(&store, realm_name, store_name)?;
},
("add", Some(m)) => {
let fp = Fingerprint::from_hex(m.value_of("fingerprint").unwrap())
@@ -403,12 +408,12 @@ fn real_main() -> Result<(), failure::Error> {
("stores", Some(m)) => {
let mut table = Table::new();
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
- table.set_titles(row!["domain", "name", "network policy"]);
+ table.set_titles(row!["realm", "name", "network policy"]);
- for (domain, name, network_policy, _)
+ for (realm, name, network_policy, _)
in Store::list(&ctx, m.value_of("prefix").unwrap_or(""))? {
table.add_row(Row::new(vec![
- Cell::new(&domain),
+ Cell::new(&realm),
Cell::new(&name),
Cell::new(&format!("{:?}", network_policy))
]));
@@ -417,9 +422,9 @@ fn real_main() -> Result<(), failure::Error> {
table.printstd();
},
("bindings", Some(m)) => {
- for (domain, name, _, store)
+ for (realm, name, _, store)
in Store::list(&ctx, m.value_of("prefix").unwrap_or(""))? {
- list_bindings(&store, &domain, &name)?;
+ list_bindings(&store, &realm, &name)?;
}
},
("keys", Some(_)) => {
@@ -459,13 +464,13 @@ fn real_main() -> Result<(), failure::Error> {
return Ok(())
}
-fn list_bindings(store: &Store, domain: &str, name: &str) -> Result<(), failure::Error> {
+fn list_bindings(store: &Store, realm: &str, name: &str) -> Result<(), failure::Error> {
if store.iter()?.count() == 0 {
- println!("No label-key bindings in the \"{}/{}\" store.", domain, name);
+ println!("No label-key bindings in the \"{}/{}\" store.", realm, name);
return Ok(());
}
- println!("Domain: {:?}, store: {:?}:", domain, name);
+ println!("Realm: {:?}, store: {:?}:", realm, name);
let mut table = Table::new();
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
diff --git a/tool/src/sq_cli.rs b/tool/src/sq_cli.rs
index a75d1349..6b9f0fc2 100644
--- a/tool/src/sq_cli.rs
+++ b/tool/src/sq_cli.rs
@@ -14,14 +14,11 @@ pub fn build() -> App<'static, 'static> {
.arg(Arg::with_name("home").value_name("DIRECTORY")
.long("home")
.help("Sets the home directory to use"))
- .arg(Arg::with_name("domain").value_name("DOMAIN")
- .long("domain")
- .short("d")
- .help("Sets the domain to use"))
.arg(Arg::with_name("store").value_name("STORE")
.long("store")
.short("s")
- .help("Sets the store to use (default: 'default')"))
+ .default_value("org.sequoia-pgp.contacts/default")
+ .help("Sets the realm and store to use"))
.arg(Arg::with_name("policy").value_name("NETWORK-POLICY")
.long("policy")
.short("p")
@@ -327,11 +324,11 @@ pub fn build() -> App<'static, 'static> {
.subcommand(SubCommand::with_name("stores")
.about("Lists key stores")
.arg(Arg::with_name("prefix").value_name("PREFIX")
- .help("List only stores with the given domain prefix")))
+ .help("List only stores with the given realm prefix")))
.subcommand(SubCommand::with_name("bindings")
.about("Lists all bindings in all key stores")
.arg(Arg::with_name("prefix").value_name("PREFIX")
- .help("List only bindings from stores with the given domain prefix")))
+ .help("List only bindings from stores with the given realm prefix")))
.subcommand(SubCommand::with_name("keys")
.about("Lists all keys in the common key pool"))
.subcommand(SubCommand::with_name("log")