summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-02-27 11:22:43 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-02-27 11:50:59 +0100
commit5ea307c381f868f26f7486496eae565a9801e156 (patch)
tree2597c5a59ed616bd2a739fa2a9bee4b924cba2f5 /net
parentb877510b28d4c32eac894aaabed976ca2f07bed3 (diff)
net: If no protocol is given, assume hkps.
- Also, add a test. - Fixes #201.
Diffstat (limited to 'net')
-rw-r--r--net/src/async.rs3
-rw-r--r--net/src/lib.rs24
2 files changed, 26 insertions, 1 deletions
diff --git a/net/src/async.rs b/net/src/async.rs
index df82a7aa..75885272 100644
--- a/net/src/async.rs
+++ b/net/src/async.rs
@@ -42,7 +42,8 @@ const DNS_WORKER: usize = 4;
impl KeyServer {
/// Returns a handle for the given URI.
pub fn new(ctx: &Context, uri: &str, _handle: &Handle) -> Result<Self> {
- let uri: Url = uri.parse()?;
+ let uri: Url = uri.parse()
+ .or_else(|_| format!("hkps://{}", uri).parse())?;
let client: Box<AClient> = match uri.scheme() {
"hkp" => Box::new(Client::new()),
diff --git a/net/src/lib.rs b/net/src/lib.rs
index 1aee2eb1..fc674df5 100644
--- a/net/src/lib.rs
+++ b/net/src/lib.rs
@@ -192,3 +192,27 @@ impl From<url::ParseError> for Error {
Error::UriError(e)
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn uris() {
+ let ctx = Context::configure("foo")
+ .network_policy(sequoia_core::NetworkPolicy::Insecure)
+ .build().unwrap();
+
+ assert!(KeyServer::new(&ctx, "keys.openpgp.org").is_ok());
+ assert!(KeyServer::new(&ctx, "hkp://keys.openpgp.org").is_ok());
+ assert!(KeyServer::new(&ctx, "hkps://keys.openpgp.org").is_ok());
+
+ let ctx = Context::configure("foo")
+ .network_policy(sequoia_core::NetworkPolicy::Encrypted)
+ .build().unwrap();
+
+ assert!(KeyServer::new(&ctx, "keys.openpgp.org").is_ok());
+ assert!(KeyServer::new(&ctx, "hkp://keys.openpgp.org").is_err());
+ assert!(KeyServer::new(&ctx, "hkps://keys.openpgp.org").is_ok());
+ }
+}