Make rust-tls work (through ring)
This commit is contained in:
parent
78ee947d44
commit
01a4f68e20
7 changed files with 77 additions and 27 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1661,6 +1661,7 @@ name = "librqbit-sha1-wrapper"
|
||||||
version = "3.0.0"
|
version = "3.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crypto-hash",
|
"crypto-hash",
|
||||||
|
"ring",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ repository = "https://github.com/ikatson/rqbit"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[features]
|
||||||
|
default = ["sha1-crypto-hash"]
|
||||||
|
sha1-crypto-hash = ["sha1w/sha1-crypto-hash"]
|
||||||
|
sha1-ring = ["sha1w/sha1-ring"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ http-api = ["axum", "tower-http"]
|
||||||
upnp-serve-adapter = ["upnp-serve"]
|
upnp-serve-adapter = ["upnp-serve"]
|
||||||
webui = []
|
webui = []
|
||||||
timed_existence = []
|
timed_existence = []
|
||||||
default-tls = ["reqwest/default-tls"]
|
default-tls = ["reqwest/default-tls", "sha1w/sha1-crypto-hash"]
|
||||||
rust-tls = ["reqwest/rustls-tls"]
|
rust-tls = ["reqwest/rustls-tls", "sha1w/sha1-ring"]
|
||||||
storage_middleware = ["lru"]
|
storage_middleware = ["lru"]
|
||||||
storage_examples = []
|
storage_examples = []
|
||||||
tracing-subscriber-utils = ["tracing-subscriber"]
|
tracing-subscriber-utils = ["tracing-subscriber"]
|
||||||
|
|
@ -35,7 +35,7 @@ tracker_comms = { path = "../tracker_comms", default-features = false, package =
|
||||||
buffers = { path = "../buffers", package = "librqbit-buffers", version = "4.1" }
|
buffers = { path = "../buffers", package = "librqbit-buffers", version = "4.1" }
|
||||||
librqbit-core = { path = "../librqbit_core", version = "4" }
|
librqbit-core = { path = "../librqbit_core", version = "4" }
|
||||||
clone_to_owned = { path = "../clone_to_owned", package = "librqbit-clone-to-owned", version = "3" }
|
clone_to_owned = { path = "../clone_to_owned", package = "librqbit-clone-to-owned", version = "3" }
|
||||||
peer_binary_protocol = { path = "../peer_binary_protocol", package = "librqbit-peer-protocol", version = "4.1" }
|
peer_binary_protocol = { path = "../peer_binary_protocol", default-features = false, package = "librqbit-peer-protocol", version = "4.1" }
|
||||||
sha1w = { path = "../sha1w", default-features = false, package = "librqbit-sha1-wrapper", version = "3.0.0" }
|
sha1w = { path = "../sha1w", default-features = false, package = "librqbit-sha1-wrapper", version = "3.0.0" }
|
||||||
dht = { path = "../dht", package = "librqbit-dht", version = "5.1.0" }
|
dht = { path = "../dht", package = "librqbit-dht", version = "5.1.0" }
|
||||||
librqbit-upnp = { path = "../upnp", version = "0.1.1" }
|
librqbit-upnp = { path = "../upnp", version = "0.1.1" }
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ repository = "https://github.com/ikatson/rqbit"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
bincode = "1"
|
bincode = "1"
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,13 @@ documentation = "https://docs.rs/librqbit-sha1-wrapper"
|
||||||
repository = "https://github.com/ikatson/rqbit"
|
repository = "https://github.com/ikatson/rqbit"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html#
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["sha1-crypto-hash"]
|
||||||
|
sha1-crypto-hash = ["crypto-hash"]
|
||||||
|
sha1-ring = ["ring"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crypto-hash = "0.3"
|
crypto-hash = { version = "0.3", optional = true }
|
||||||
|
ring = { version = "0.17", optional = true }
|
||||||
|
|
|
||||||
|
|
@ -5,35 +5,75 @@
|
||||||
// openssl is 2-3x faster than rust's sha1.
|
// openssl is 2-3x faster than rust's sha1.
|
||||||
// system library is the best choice probably (it's the default anyway).
|
// system library is the best choice probably (it's the default anyway).
|
||||||
|
|
||||||
pub type Sha1 = Sha1System;
|
|
||||||
|
|
||||||
pub trait ISha1 {
|
pub trait ISha1 {
|
||||||
fn new() -> Self;
|
fn new() -> Self;
|
||||||
fn update(&mut self, buf: &[u8]);
|
fn update(&mut self, buf: &[u8]);
|
||||||
fn finish(self) -> [u8; 20];
|
fn finish(self) -> [u8; 20];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Sha1System {
|
#[cfg(feature = "sha1-crypto-hash")]
|
||||||
inner: crypto_hash::Hasher,
|
mod crypto_hash_impl {
|
||||||
}
|
use super::ISha1;
|
||||||
|
|
||||||
impl ISha1 for Sha1System {
|
pub struct Sha1CryptoHash {
|
||||||
fn new() -> Self {
|
inner: crypto_hash::Hasher,
|
||||||
Self {
|
}
|
||||||
inner: crypto_hash::Hasher::new(crypto_hash::Algorithm::SHA1),
|
|
||||||
|
impl ISha1 for Sha1CryptoHash {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
inner: crypto_hash::Hasher::new(crypto_hash::Algorithm::SHA1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, buf: &[u8]) {
|
||||||
|
use std::io::Write;
|
||||||
|
self.inner.write_all(buf).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn finish(mut self) -> [u8; 20] {
|
||||||
|
let result = self.inner.finish();
|
||||||
|
debug_assert_eq!(result.len(), 20);
|
||||||
|
let mut result_arr = [0u8; 20];
|
||||||
|
result_arr.copy_from_slice(&result);
|
||||||
|
result_arr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update(&mut self, buf: &[u8]) {
|
#[cfg(feature = "sha1-ring")]
|
||||||
use std::io::Write;
|
mod ring_impl {
|
||||||
self.inner.write_all(buf).unwrap();
|
use super::ISha1;
|
||||||
|
|
||||||
|
use ring::digest::{Context, SHA1_FOR_LEGACY_USE_ONLY as SHA1};
|
||||||
|
|
||||||
|
pub struct Sha1Ring {
|
||||||
|
ctx: Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish(mut self) -> [u8; 20] {
|
impl ISha1 for Sha1Ring {
|
||||||
let result = self.inner.finish();
|
fn new() -> Self {
|
||||||
debug_assert_eq!(result.len(), 20);
|
Self {
|
||||||
let mut result_arr = [0u8; 20];
|
ctx: Context::new(&SHA1),
|
||||||
result_arr.copy_from_slice(&result);
|
}
|
||||||
result_arr
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, buf: &[u8]) {
|
||||||
|
self.ctx.update(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn finish(self) -> [u8; 20] {
|
||||||
|
let result = self.ctx.finish();
|
||||||
|
debug_assert_eq!(result.as_ref().len(), 20);
|
||||||
|
let mut result_arr = [0u8; 20];
|
||||||
|
result_arr.copy_from_slice(result.as_ref());
|
||||||
|
result_arr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "sha1-crypto-hash")]
|
||||||
|
pub type Sha1 = crypto_hash_impl::Sha1CryptoHash;
|
||||||
|
|
||||||
|
#[cfg(feature = "sha1-ring")]
|
||||||
|
pub type Sha1 = ring_impl::Sha1Ring;
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ quick-xml = "0.36.1"
|
||||||
http = "1.1.0"
|
http = "1.1.0"
|
||||||
httparse = "1.9.4"
|
httparse = "1.9.4"
|
||||||
uuid = { version = "1.10.0", features = ["v4"] }
|
uuid = { version = "1.10.0", features = ["v4"] }
|
||||||
librqbit-upnp = { path = "../upnp" }
|
librqbit-upnp = { path = "../upnp", default-features = false }
|
||||||
gethostname = "0.5.0"
|
gethostname = "0.5.0"
|
||||||
librqbit-sha1-wrapper = { path = "../sha1w" }
|
librqbit-sha1-wrapper = { path = "../sha1w", default-features = false }
|
||||||
librqbit-core = { path = "../librqbit_core" }
|
librqbit-core = { path = "../librqbit_core", default-features = false }
|
||||||
mime_guess = "2.0.5"
|
mime_guess = "2.0.5"
|
||||||
url = "2.5.2"
|
url = "2.5.2"
|
||||||
parking_lot = "0.12.3"
|
parking_lot = "0.12.3"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue