Replace the apparently unmaintained hex crate with data-encoding

data-encoding was already a transitive dependency via tungstenite
This commit is contained in:
David Sheets 2023-12-01 16:38:59 +00:00
parent 886617e41c
commit ba314b63e4
5 changed files with 19 additions and 15 deletions

8
Cargo.lock generated
View file

@ -389,9 +389,9 @@ checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f"
[[package]] [[package]]
name = "data-encoding" name = "data-encoding"
version = "2.4.0" version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5"
[[package]] [[package]]
name = "der" name = "der"
@ -1331,10 +1331,10 @@ dependencies = [
name = "librespot" name = "librespot"
version = "0.5.0-dev" version = "0.5.0-dev"
dependencies = [ dependencies = [
"data-encoding",
"env_logger", "env_logger",
"futures-util", "futures-util",
"getopts", "getopts",
"hex",
"librespot-audio", "librespot-audio",
"librespot-connect", "librespot-connect",
"librespot-core", "librespot-core",
@ -1398,13 +1398,13 @@ dependencies = [
"base64 0.21.5", "base64 0.21.5",
"byteorder", "byteorder",
"bytes", "bytes",
"data-encoding",
"dns-sd", "dns-sd",
"env_logger", "env_logger",
"form_urlencoded", "form_urlencoded",
"futures-core", "futures-core",
"futures-util", "futures-util",
"governor", "governor",
"hex",
"hmac", "hmac",
"http", "http",
"httparse", "httparse",

View file

@ -50,10 +50,10 @@ path = "protocol"
version = "0.5.0-dev" version = "0.5.0-dev"
[dependencies] [dependencies]
data-encoding = "2.5"
env_logger = { version = "0.10", default-features = false, features = ["color", "humantime", "auto-color"] } env_logger = { version = "0.10", default-features = false, features = ["color", "humantime", "auto-color"] }
futures-util = { version = "0.3", default_features = false } futures-util = { version = "0.3", default_features = false }
getopts = "0.2" getopts = "0.2"
hex = "0.4"
log = "0.4" log = "0.4"
rpassword = "7.0" rpassword = "7.0"
sha1 = "0.10" sha1 = "0.10"

View file

@ -23,7 +23,6 @@ form_urlencoded = "1.0"
futures-core = "0.3" futures-core = "0.3"
futures-util = { version = "0.3", features = ["alloc", "bilock", "sink", "unstable"] } futures-util = { version = "0.3", features = ["alloc", "bilock", "sink", "unstable"] }
governor = { version = "0.6", default-features = false, features = ["std", "jitter"] } governor = { version = "0.6", default-features = false, features = ["std", "jitter"] }
hex = "0.4"
hmac = "0.12" hmac = "0.12"
httparse = "1.7" httparse = "1.7"
http = "0.2" http = "0.2"
@ -57,6 +56,7 @@ tokio-tungstenite = { version = "*", default-features = false, features = ["rust
tokio-util = { version = "0.7", features = ["codec"] } tokio-util = { version = "0.7", features = ["codec"] }
url = "2" url = "2"
uuid = { version = "1", default-features = false, features = ["fast-rng", "v4"] } uuid = { version = "1", default-features = false, features = ["fast-rng", "v4"] }
data-encoding = "2.5"
[build-dependencies] [build-dependencies]
rand = "0.8" rand = "0.8"

View file

@ -6,6 +6,7 @@ use std::{
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use bytes::Bytes; use bytes::Bytes;
use data_encoding::HEXUPPER_PERMISSIVE;
use futures_util::future::IntoStream; use futures_util::future::IntoStream;
use http::header::HeaderValue; use http::header::HeaderValue;
use hyper::{ use hyper::{
@ -279,20 +280,22 @@ impl SpClient {
let hash_cash_challenge = challenge.evaluate_hashcash_parameters(); let hash_cash_challenge = challenge.evaluate_hashcash_parameters();
let ctx = vec![]; let ctx = vec![];
let prefix = hex::decode(&hash_cash_challenge.prefix).map_err(|e| { let prefix = HEXUPPER_PERMISSIVE
.decode(hash_cash_challenge.prefix.as_bytes())
.map_err(|e| {
Error::failed_precondition(format!( Error::failed_precondition(format!(
"Unable to decode hash cash challenge: {e}" "Unable to decode hash cash challenge: {e}"
)) ))
})?; })?;
let length = hash_cash_challenge.length; let length = hash_cash_challenge.length;
let mut suffix = vec![0; 0x10]; let mut suffix = [0u8; 0x10];
let answer = Self::solve_hash_cash(&ctx, &prefix, length, &mut suffix); let answer = Self::solve_hash_cash(&ctx, &prefix, length, &mut suffix);
match answer { match answer {
Ok(_) => { Ok(_) => {
// the suffix must be in uppercase // the suffix must be in uppercase
let suffix = hex::encode(suffix).to_uppercase(); let suffix = HEXUPPER_PERMISSIVE.encode(&suffix);
let mut answer_message = ClientTokenRequest::new(); let mut answer_message = ClientTokenRequest::new();
answer_message.request_type = answer_message.request_type =
@ -302,7 +305,7 @@ impl SpClient {
let challenge_answers = answer_message.mut_challenge_answers(); let challenge_answers = answer_message.mut_challenge_answers();
let mut challenge_answer = ChallengeAnswer::new(); let mut challenge_answer = ChallengeAnswer::new();
challenge_answer.mut_hash_cash().suffix = suffix.to_string(); challenge_answer.mut_hash_cash().suffix = suffix;
challenge_answer.ChallengeType = challenge_answer.ChallengeType =
ChallengeType::CHALLENGE_HASH_CASH.into(); ChallengeType::CHALLENGE_HASH_CASH.into();

View file

@ -1,3 +1,4 @@
use data_encoding::HEXLOWER;
use futures_util::StreamExt; use futures_util::StreamExt;
use log::{debug, error, info, trace, warn}; use log::{debug, error, info, trace, warn};
use sha1::{Digest, Sha1}; use sha1::{Digest, Sha1};
@ -39,7 +40,7 @@ mod player_event_handler;
use player_event_handler::{run_program_on_sink_events, EventHandler}; use player_event_handler::{run_program_on_sink_events, EventHandler};
fn device_id(name: &str) -> String { fn device_id(name: &str) -> String {
hex::encode(Sha1::digest(name.as_bytes())) HEXLOWER.encode(&Sha1::digest(name.as_bytes()))
} }
fn usage(program: &str, opts: &getopts::Options) -> String { fn usage(program: &str, opts: &getopts::Options) -> String {