summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
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());
+ }
+}