summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorIgor Matuszewski <igor@sequoia-pgp.org>2019-12-18 21:23:45 +0100
committerIgor Matuszewski <igor@sequoia-pgp.org>2019-12-20 14:40:49 +0100
commitdc578999ea706417f4fd1a877ecc06840e58d5b0 (patch)
tree047fe1650933d32ff387320dba9a9587920d3810 /net
parentc643f14f44f7df7bb87c3ad48258c0c8da0eabd5 (diff)
net: Use openpgp crypto API for SHA1 hash
Diffstat (limited to 'net')
-rw-r--r--net/Cargo.toml1
-rw-r--r--net/src/lib.rs1
-rw-r--r--net/src/wkd.rs21
3 files changed, 9 insertions, 14 deletions
diff --git a/net/Cargo.toml b/net/Cargo.toml
index 73400201..eed53733 100644
--- a/net/Cargo.toml
+++ b/net/Cargo.toml
@@ -31,7 +31,6 @@ hyper = "0.12"
hyper-tls = "0.3"
libc = "0.2.33"
native-tls = "0.2.0"
-nettle = "5.0"
percent-encoding = "2.1"
tempfile = "3.1"
tokio-core = "0.1"
diff --git a/net/src/lib.rs b/net/src/lib.rs
index 8f91ce18..f7add939 100644
--- a/net/src/lib.rs
+++ b/net/src/lib.rs
@@ -45,7 +45,6 @@ extern crate http;
extern crate hyper;
extern crate hyper_tls;
extern crate native_tls;
-extern crate nettle;
extern crate tokio_core;
extern crate tokio_io;
extern crate percent_encoding;
diff --git a/net/src/wkd.rs b/net/src/wkd.rs
index 286b8562..a4134110 100644
--- a/net/src/wkd.rs
+++ b/net/src/wkd.rs
@@ -26,12 +26,6 @@ use failure::ResultExt;
use futures::{future, Future, Stream};
use hyper::{Uri, Client};
use hyper_tls::HttpsConnector;
-// Hash implements the traits for Sha1
-// Sha1 is used to obtain a 20 bytes digest that after zbase32 encoding can
-// be used as file name
-use nettle::{
- Hash, hash::insecure_do_not_use::Sha1,
-};
use url;
use crate::openpgp::{
@@ -40,6 +34,7 @@ use crate::openpgp::{
};
use crate::openpgp::parse::Parse;
use crate::openpgp::serialize::Serialize;
+use crate::openpgp::types::HashAlgorithm;
use crate::openpgp::cert::CertParser;
use super::{Result, Error};
@@ -204,13 +199,15 @@ impl Url {
/// described in [RFC6189], section 5.1.6. The resulting string has a
/// fixed length of 32 octets.
fn encode_local_part<S: AsRef<str>>(local_part: S) -> String {
- let mut hasher = Sha1::default();
- hasher.update(local_part.as_ref().as_bytes());
- // Declare and assign a 20 bytes length vector to use in hasher.result
- let mut local_hash = vec![0; 20];
- hasher.digest(&mut local_hash);
+ let local_part = local_part.as_ref();
+
+ let mut digest = vec![0; 20];
+ let mut ctx = HashAlgorithm::SHA1.context().expect("must be implemented");
+ ctx.update(local_part.as_bytes());
+ ctx.digest(&mut digest);
+
// After z-base-32 encoding 20 bytes, it will be 32 bytes long.
- zbase32::encode_full_bytes(&local_hash[..])
+ zbase32::encode_full_bytes(&digest[..])
}