summaryrefslogtreecommitdiffstats
path: root/sq
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-01-15 12:15:55 +0100
committerJustus Winter <justus@sequoia-pgp.org>2021-01-15 12:15:55 +0100
commit07ed37f31e6a23f68d92bd2a9b24763c638e0549 (patch)
tree0ac8103acbdc2fb88d54d797f87779acda9d6e7f /sq
parent12b0c76b4fef2442eaead7759d48b209a57d5eef (diff)
sq: Make networking features optional.
Diffstat (limited to 'sq')
-rw-r--r--sq/Cargo.toml6
-rw-r--r--sq/src/commands/mod.rs1
-rw-r--r--sq/src/sq.rs10
-rw-r--r--sq/src/sq_cli.rs74
4 files changed, 54 insertions, 37 deletions
diff --git a/sq/Cargo.toml b/sq/Cargo.toml
index cf91402e..e12e8786 100644
--- a/sq/Cargo.toml
+++ b/sq/Cargo.toml
@@ -26,14 +26,14 @@ buffered-reader = { path = "../buffered-reader", version = "1.0.0", default-feat
sequoia-openpgp = { path = "../openpgp", version = "1.0.0", default-features = false }
sequoia-autocrypt = { path = "../autocrypt", version = "0.22", default-features = false }
sequoia-ipc = { path = "../ipc", version = "0.22", default-features = false }
-sequoia-net = { path = "../net", version = "0.22", default-features = false }
+sequoia-net = { path = "../net", version = "0.22", default-features = false, optional = true }
anyhow = "1.0.18"
chrono = "0.4.10"
clap = "2.33"
itertools = "0.9"
tempfile = "3.1"
term_size = "0.3"
-tokio = { version = "0.2.19", features = ["rt-core", "io-util", "io-driver"] }
+tokio = { version = "0.2.19", features = ["rt-core", "io-util", "io-driver"], optional = true }
rpassword = "5.0"
[build-dependencies]
@@ -52,9 +52,11 @@ path = "src/sq-usage.rs"
default = [
"buffered-reader/compression",
"sequoia-openpgp/default",
+ "net",
]
crypto-nettle = ["sequoia-openpgp/crypto-nettle"]
crypto-cng = ["sequoia-openpgp/crypto-cng"]
compression = ["buffered-reader/compression", "sequoia-openpgp/compression"]
compression-deflate = ["buffered-reader/compression-deflate", "sequoia-openpgp/compression-deflate"]
compression-bzip2 = ["buffered-reader/compression-bzip2", "sequoia-openpgp/compression-bzip2"]
+net = ["sequoia-net", "tokio"]
diff --git a/sq/src/commands/mod.rs b/sq/src/commands/mod.rs
index cd40d255..83a4f398 100644
--- a/sq/src/commands/mod.rs
+++ b/sq/src/commands/mod.rs
@@ -42,6 +42,7 @@ pub mod key;
pub mod merge_signatures;
pub use self::merge_signatures::merge_signatures;
pub mod certring;
+#[cfg(feature = "net")]
pub mod net;
/// Returns suitable signing keys from a given list of Certs.
diff --git a/sq/src/sq.rs b/sq/src/sq.rs
index 39c30527..09412793 100644
--- a/sq/src/sq.rs
+++ b/sq/src/sq.rs
@@ -4,7 +4,6 @@ use anyhow::Context as _;
use std::fs::OpenOptions;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
-use std::process::exit;
use chrono::{DateTime, offset::Utc};
use buffered_reader::File;
@@ -23,6 +22,7 @@ use crate::openpgp::parse::Parse;
use crate::openpgp::serialize::{Serialize, stream::{Message, Armorer}};
use crate::openpgp::cert::prelude::*;
use crate::openpgp::policy::StandardPolicy as P;
+#[cfg(feature = "net")]
use sequoia_net as net;
mod sq_cli;
@@ -105,6 +105,7 @@ fn load_certs<'a, I>(files: I) -> openpgp::Result<Vec<Cert>>
}
/// Serializes a keyring, adding descriptive headers if armored.
+#[allow(dead_code)]
fn serialize_keyring(mut output: &mut dyn io::Write, certs: &[Cert], binary: bool)
-> openpgp::Result<()> {
// Handle the easy options first. No armor no cry:
@@ -227,6 +228,7 @@ fn help_warning(arg: &str) {
#[allow(dead_code)]
pub struct Config {
force: bool,
+ #[cfg(feature = "net")]
network_policy: net::Policy,
}
@@ -245,6 +247,7 @@ fn main() -> Result<()> {
.collect();
policy.good_critical_notations(&known_notations);
+ #[cfg(feature = "net")]
let network_policy = match matches.value_of("policy") {
None => net::Policy::Encrypted,
Some("offline") => net::Policy::Offline,
@@ -253,13 +256,14 @@ fn main() -> Result<()> {
Some("insecure") => net::Policy::Insecure,
Some(_) => {
eprintln!("Bad network policy, must be offline, anonymized, encrypted, or insecure.");
- exit(1);
+ std::process::exit(1);
},
};
let force = matches.is_present("force");
let config = Config {
force,
+ #[cfg(feature = "net")]
network_policy,
};
@@ -487,6 +491,7 @@ fn main() -> Result<()> {
_ => unreachable!(),
},
+ #[cfg(feature = "net")]
("keyserver", Some(m)) =>
commands::net::dispatch_keyserver(config, m)?,
@@ -496,6 +501,7 @@ fn main() -> Result<()> {
_ => unreachable!(),
},
+ #[cfg(feature = "net")]
("wkd", Some(m)) => commands::net::dispatch_wkd(config, m)?,
_ => unreachable!(),
}
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index 29ced67d..86e86310 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -7,7 +7,7 @@
use clap::{App, Arg, ArgGroup, SubCommand, AppSettings};
pub fn build() -> App<'static, 'static> {
- App::new("sq")
+ let app = App::new("sq")
.version(env!("CARGO_PKG_VERSION"))
.about("Sequoia is an implementation of OpenPGP. This is a command-line frontend.")
.setting(AppSettings::SubcommandRequiredElseHelp)
@@ -285,35 +285,6 @@ pub fn build() -> App<'static, 'static> {
.long("certifications")
.help("Print third-party certifications")))
- .subcommand(SubCommand::with_name("keyserver")
- .display_order(40)
- .about("Interacts with keyservers")
- .setting(AppSettings::SubcommandRequiredElseHelp)
- .arg(Arg::with_name("server").value_name("URI")
- .long("server")
- .short("s")
- .help("Sets the keyserver to use"))
- .subcommand(SubCommand::with_name("get")
- .about("Retrieves a key")
- .arg(Arg::with_name("output").value_name("FILE")
- .long("output")
- .short("o")
- .help("Sets the output file to use"))
- .arg(Arg::with_name("binary")
- .long("binary")
- .short("B")
- .help("Don't ASCII-armor encode the OpenPGP data"))
- .arg(Arg::with_name("query").value_name("QUERY")
- .required(true)
- .help(
- "Fingerprint, KeyID, or email \
- address of the cert(s) to retrieve"
- )))
- .subcommand(SubCommand::with_name("send")
- .about("Sends a key")
- .arg(Arg::with_name("input").value_name("FILE")
- .help("Sets the input file to use"))))
-
.subcommand(
SubCommand::with_name("key")
.about("Manipulates keys")
@@ -592,7 +563,42 @@ pub fn build() -> App<'static, 'static> {
.long("binary")
.short("B")
.help("Don't ASCII-armor encode the \
- OpenPGP data"))))
+ OpenPGP data"))));
+
+ let app = if ! cfg!(feature = "net") {
+ // Without networking support.
+ app
+ } else {
+ // With networking support.
+ app
+ .subcommand(SubCommand::with_name("keyserver")
+ .display_order(40)
+ .about("Interacts with keyservers")
+ .setting(AppSettings::SubcommandRequiredElseHelp)
+ .arg(Arg::with_name("server").value_name("URI")
+ .long("server")
+ .short("s")
+ .help("Sets the keyserver to use"))
+ .subcommand(SubCommand::with_name("get")
+ .about("Retrieves a key")
+ .arg(Arg::with_name("output").value_name("FILE")
+ .long("output")
+ .short("o")
+ .help("Sets the output file to use"))
+ .arg(Arg::with_name("binary")
+ .long("binary")
+ .short("B")
+ .help("Don't ASCII-armor encode the OpenPGP data"))
+ .arg(Arg::with_name("query").value_name("QUERY")
+ .required(true)
+ .help(
+ "Fingerprint, KeyID, or email \
+ address of the cert(s) to retrieve"
+ )))
+ .subcommand(SubCommand::with_name("send")
+ .about("Sends a key")
+ .arg(Arg::with_name("input").value_name("FILE")
+ .help("Sets the input file to use"))))
.subcommand(SubCommand::with_name("wkd")
.about("Interacts with Web Key Directories")
@@ -645,6 +651,8 @@ pub fn build() -> App<'static, 'static> {
.short("d")
.help("Use the direct method. \
[default: advanced method]"))
- )
- )
+ ))
+ };
+
+ app
}