Skip to content

Commit ba314b6

Browse files
committed
Replace the apparently unmaintained hex crate with data-encoding
data-encoding was already a transitive dependency via tungstenite
1 parent 886617e commit ba314b6

5 files changed

Lines changed: 19 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ path = "protocol"
5050
version = "0.5.0-dev"
5151

5252
[dependencies]
53+
data-encoding = "2.5"
5354
env_logger = { version = "0.10", default-features = false, features = ["color", "humantime", "auto-color"] }
5455
futures-util = { version = "0.3", default_features = false }
5556
getopts = "0.2"
56-
hex = "0.4"
5757
log = "0.4"
5858
rpassword = "7.0"
5959
sha1 = "0.10"

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ form_urlencoded = "1.0"
2323
futures-core = "0.3"
2424
futures-util = { version = "0.3", features = ["alloc", "bilock", "sink", "unstable"] }
2525
governor = { version = "0.6", default-features = false, features = ["std", "jitter"] }
26-
hex = "0.4"
2726
hmac = "0.12"
2827
httparse = "1.7"
2928
http = "0.2"
@@ -57,6 +56,7 @@ tokio-tungstenite = { version = "*", default-features = false, features = ["rust
5756
tokio-util = { version = "0.7", features = ["codec"] }
5857
url = "2"
5958
uuid = { version = "1", default-features = false, features = ["fast-rng", "v4"] }
59+
data-encoding = "2.5"
6060

6161
[build-dependencies]
6262
rand = "0.8"

core/src/spclient.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66

77
use byteorder::{BigEndian, ByteOrder};
88
use bytes::Bytes;
9+
use data_encoding::HEXUPPER_PERMISSIVE;
910
use futures_util::future::IntoStream;
1011
use http::header::HeaderValue;
1112
use hyper::{
@@ -279,20 +280,22 @@ impl SpClient {
279280
let hash_cash_challenge = challenge.evaluate_hashcash_parameters();
280281

281282
let ctx = vec![];
282-
let prefix = hex::decode(&hash_cash_challenge.prefix).map_err(|e| {
283-
Error::failed_precondition(format!(
284-
"Unable to decode hash cash challenge: {e}"
285-
))
286-
})?;
283+
let prefix = HEXUPPER_PERMISSIVE
284+
.decode(hash_cash_challenge.prefix.as_bytes())
285+
.map_err(|e| {
286+
Error::failed_precondition(format!(
287+
"Unable to decode hash cash challenge: {e}"
288+
))
289+
})?;
287290
let length = hash_cash_challenge.length;
288291

289-
let mut suffix = vec![0; 0x10];
292+
let mut suffix = [0u8; 0x10];
290293
let answer = Self::solve_hash_cash(&ctx, &prefix, length, &mut suffix);
291294

292295
match answer {
293296
Ok(_) => {
294297
// the suffix must be in uppercase
295-
let suffix = hex::encode(suffix).to_uppercase();
298+
let suffix = HEXUPPER_PERMISSIVE.encode(&suffix);
296299

297300
let mut answer_message = ClientTokenRequest::new();
298301
answer_message.request_type =
@@ -302,7 +305,7 @@ impl SpClient {
302305
let challenge_answers = answer_message.mut_challenge_answers();
303306

304307
let mut challenge_answer = ChallengeAnswer::new();
305-
challenge_answer.mut_hash_cash().suffix = suffix.to_string();
308+
challenge_answer.mut_hash_cash().suffix = suffix;
306309
challenge_answer.ChallengeType =
307310
ChallengeType::CHALLENGE_HASH_CASH.into();
308311

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use data_encoding::HEXLOWER;
12
use futures_util::StreamExt;
23
use log::{debug, error, info, trace, warn};
34
use sha1::{Digest, Sha1};
@@ -39,7 +40,7 @@ mod player_event_handler;
3940
use player_event_handler::{run_program_on_sink_events, EventHandler};
4041

4142
fn device_id(name: &str) -> String {
42-
hex::encode(Sha1::digest(name.as_bytes()))
43+
HEXLOWER.encode(&Sha1::digest(name.as_bytes()))
4344
}
4445

4546
fn usage(program: &str, opts: &getopts::Options) -> String {

0 commit comments

Comments
 (0)