From 7c3d89112dc0cdb4a8105592268bbb6fe9f035f8 Mon Sep 17 00:00:00 2001 From: johannesd3 Date: Wed, 31 Mar 2021 20:05:32 +0200 Subject: [PATCH] Fix clippy warnings --- audio/src/passthrough_decoder.rs | 2 +- core/src/apresolve.rs | 4 ++-- core/src/config.rs | 18 +++++++++--------- core/src/connection/codec.rs | 12 ++++++------ core/src/connection/handshake.rs | 10 +++++----- core/src/connection/mod.rs | 4 ++-- core/src/diffie_hellman.rs | 8 ++++---- core/src/mercury/mod.rs | 6 +++--- core/src/mercury/types.rs | 22 +++++++++++----------- core/src/spotify_id.rs | 6 +++--- src/main.rs | 4 +++- 11 files changed, 49 insertions(+), 47 deletions(-) diff --git a/audio/src/passthrough_decoder.rs b/audio/src/passthrough_decoder.rs index d519baf8..e064cba3 100644 --- a/audio/src/passthrough_decoder.rs +++ b/audio/src/passthrough_decoder.rs @@ -110,7 +110,7 @@ impl AudioDecoder for PassthroughDecoder { fn next_packet(&mut self) -> Result, AudioError> { // write headers if we are (re)starting - if self.bos == false { + if !self.bos { self.wtr .write_packet( self.ident.clone(), diff --git a/core/src/apresolve.rs b/core/src/apresolve.rs index c954dab5..85baba69 100644 --- a/core/src/apresolve.rs +++ b/core/src/apresolve.rs @@ -11,7 +11,7 @@ use super::AP_FALLBACK; const APRESOLVE_ENDPOINT: &str = "http://apresolve.spotify.com:80"; #[derive(Clone, Debug, Deserialize)] -struct APResolveData { +struct ApResolveData { ap_list: Vec, } @@ -41,7 +41,7 @@ async fn try_apresolve( }; let body = hyper::body::to_bytes(response.into_body()).await?; - let data: APResolveData = serde_json::from_slice(body.as_ref())?; + let data: ApResolveData = serde_json::from_slice(body.as_ref())?; let ap = if ap_port.is_some() || proxy.is_some() { data.ap_list.into_iter().find_map(|ap| { diff --git a/core/src/config.rs b/core/src/config.rs index a9e5ea2c..9c70c25b 100644 --- a/core/src/config.rs +++ b/core/src/config.rs @@ -29,9 +29,9 @@ pub enum DeviceType { Tablet = 2, Smartphone = 3, Speaker = 4, - TV = 5, - AVR = 6, - STB = 7, + Tv = 5, + Avr = 6, + Stb = 7, AudioDongle = 8, GameConsole = 9, CastAudio = 10, @@ -54,9 +54,9 @@ impl FromStr for DeviceType { "tablet" => Ok(Tablet), "smartphone" => Ok(Smartphone), "speaker" => Ok(Speaker), - "tv" => Ok(TV), - "avr" => Ok(AVR), - "stb" => Ok(STB), + "tv" => Ok(Tv), + "avr" => Ok(Avr), + "stb" => Ok(Stb), "audiodongle" => Ok(AudioDongle), "gameconsole" => Ok(GameConsole), "castaudio" => Ok(CastAudio), @@ -80,9 +80,9 @@ impl fmt::Display for DeviceType { Tablet => f.write_str("Tablet"), Smartphone => f.write_str("Smartphone"), Speaker => f.write_str("Speaker"), - TV => f.write_str("TV"), - AVR => f.write_str("AVR"), - STB => f.write_str("STB"), + Tv => f.write_str("TV"), + Avr => f.write_str("AVR"), + Stb => f.write_str("STB"), AudioDongle => f.write_str("AudioDongle"), GameConsole => f.write_str("GameConsole"), CastAudio => f.write_str("CastAudio"), diff --git a/core/src/connection/codec.rs b/core/src/connection/codec.rs index ead07b6e..299220f6 100644 --- a/core/src/connection/codec.rs +++ b/core/src/connection/codec.rs @@ -13,7 +13,7 @@ enum DecodeState { Payload(u8, usize), } -pub struct APCodec { +pub struct ApCodec { encode_nonce: u32, encode_cipher: Shannon, @@ -22,9 +22,9 @@ pub struct APCodec { decode_state: DecodeState, } -impl APCodec { - pub fn new(send_key: &[u8], recv_key: &[u8]) -> APCodec { - APCodec { +impl ApCodec { + pub fn new(send_key: &[u8], recv_key: &[u8]) -> ApCodec { + ApCodec { encode_nonce: 0, encode_cipher: Shannon::new(send_key), @@ -35,7 +35,7 @@ impl APCodec { } } -impl Encoder<(u8, Vec)> for APCodec { +impl Encoder<(u8, Vec)> for ApCodec { type Error = io::Error; fn encode(&mut self, item: (u8, Vec), buf: &mut BytesMut) -> io::Result<()> { @@ -60,7 +60,7 @@ impl Encoder<(u8, Vec)> for APCodec { } } -impl Decoder for APCodec { +impl Decoder for ApCodec { type Item = (u8, Bytes); type Error = io::Error; diff --git a/core/src/connection/handshake.rs b/core/src/connection/handshake.rs index 67a786ee..879df67c 100644 --- a/core/src/connection/handshake.rs +++ b/core/src/connection/handshake.rs @@ -7,16 +7,16 @@ use std::io; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; use tokio_util::codec::{Decoder, Framed}; -use super::codec::APCodec; -use crate::diffie_hellman::DHLocalKeys; +use super::codec::ApCodec; +use crate::diffie_hellman::DhLocalKeys; use crate::protocol; use crate::protocol::keyexchange::{APResponseMessage, ClientHello, ClientResponsePlaintext}; use crate::util; pub async fn handshake( mut connection: T, -) -> io::Result> { - let local_keys = DHLocalKeys::random(&mut thread_rng()); +) -> io::Result> { + let local_keys = DhLocalKeys::random(&mut thread_rng()); let gc = local_keys.public_key(); let mut accumulator = client_hello(&mut connection, gc).await?; let message: APResponseMessage = recv_packet(&mut connection, &mut accumulator).await?; @@ -29,7 +29,7 @@ pub async fn handshake( let shared_secret = local_keys.shared_secret(&remote_key); let (challenge, send_key, recv_key) = compute_keys(&shared_secret, &accumulator); - let codec = APCodec::new(&send_key, &recv_key); + let codec = ApCodec::new(&send_key, &recv_key); client_response(&mut connection, challenge).await?; diff --git a/core/src/connection/mod.rs b/core/src/connection/mod.rs index 56d579bd..d8a40129 100644 --- a/core/src/connection/mod.rs +++ b/core/src/connection/mod.rs @@ -1,7 +1,7 @@ mod codec; mod handshake; -pub use self::codec::APCodec; +pub use self::codec::ApCodec; pub use self::handshake::handshake; use std::io::{self, ErrorKind}; @@ -19,7 +19,7 @@ use crate::protocol::keyexchange::{APLoginFailed, ErrorCode}; use crate::proxytunnel; use crate::version; -pub type Transport = Framed; +pub type Transport = Framed; fn login_error_message(code: &ErrorCode) -> &'static str { pub use ErrorCode::*; diff --git a/core/src/diffie_hellman.rs b/core/src/diffie_hellman.rs index 85448098..42d1fd9c 100644 --- a/core/src/diffie_hellman.rs +++ b/core/src/diffie_hellman.rs @@ -17,19 +17,19 @@ pub static DH_PRIME: Lazy = Lazy::new(|| { ]) }); -pub struct DHLocalKeys { +pub struct DhLocalKeys { private_key: BigUint, public_key: BigUint, } -impl DHLocalKeys { - pub fn random(rng: &mut R) -> DHLocalKeys { +impl DhLocalKeys { + pub fn random(rng: &mut R) -> DhLocalKeys { let key_data = util::rand_vec(rng, 95); let private_key = BigUint::from_bytes_be(&key_data); let public_key = util::powm(&DH_GENERATOR, &private_key, &DH_PRIME); - DHLocalKeys { + DhLocalKeys { private_key, public_key, } diff --git a/core/src/mercury/mod.rs b/core/src/mercury/mod.rs index 1a68e15e..b920e7e6 100644 --- a/core/src/mercury/mod.rs +++ b/core/src/mercury/mod.rs @@ -82,7 +82,7 @@ impl MercuryManager { pub fn get>(&self, uri: T) -> MercuryFuture { self.request(MercuryRequest { - method: MercuryMethod::GET, + method: MercuryMethod::Get, uri: uri.into(), content_type: None, payload: Vec::new(), @@ -91,7 +91,7 @@ impl MercuryManager { pub fn send>(&self, uri: T, data: Vec) -> MercuryFuture { self.request(MercuryRequest { - method: MercuryMethod::SEND, + method: MercuryMethod::Send, uri: uri.into(), content_type: None, payload: vec![data], @@ -109,7 +109,7 @@ impl MercuryManager { { let uri = uri.into(); let request = self.request(MercuryRequest { - method: MercuryMethod::SUB, + method: MercuryMethod::Sub, uri: uri.clone(), content_type: None, payload: Vec::new(), diff --git a/core/src/mercury/types.rs b/core/src/mercury/types.rs index 57cedce5..402a954c 100644 --- a/core/src/mercury/types.rs +++ b/core/src/mercury/types.rs @@ -6,10 +6,10 @@ use crate::protocol; #[derive(Debug, PartialEq, Eq)] pub enum MercuryMethod { - GET, - SUB, - UNSUB, - SEND, + Get, + Sub, + Unsub, + Send, } #[derive(Debug)] @@ -33,10 +33,10 @@ pub struct MercuryError; impl ToString for MercuryMethod { fn to_string(&self) -> String { match *self { - MercuryMethod::GET => "GET", - MercuryMethod::SUB => "SUB", - MercuryMethod::UNSUB => "UNSUB", - MercuryMethod::SEND => "SEND", + MercuryMethod::Get => "GET", + MercuryMethod::Sub => "SUB", + MercuryMethod::Unsub => "UNSUB", + MercuryMethod::Send => "SEND", } .to_owned() } @@ -45,9 +45,9 @@ impl ToString for MercuryMethod { impl MercuryMethod { pub fn command(&self) -> u8 { match *self { - MercuryMethod::GET | MercuryMethod::SEND => 0xb2, - MercuryMethod::SUB => 0xb3, - MercuryMethod::UNSUB => 0xb4, + MercuryMethod::Get | MercuryMethod::Send => 0xb2, + MercuryMethod::Sub => 0xb3, + MercuryMethod::Unsub => 0xb4, } } } diff --git a/core/src/spotify_id.rs b/core/src/spotify_id.rs index 09d10975..801c6ac9 100644 --- a/core/src/spotify_id.rs +++ b/core/src/spotify_id.rs @@ -18,9 +18,9 @@ impl From<&str> for SpotifyAudioType { } } -impl Into<&str> for SpotifyAudioType { - fn into(self) -> &'static str { - match self { +impl From for &str { + fn from(audio_type: SpotifyAudioType) -> &'static str { + match audio_type { SpotifyAudioType::Track => "track", SpotifyAudioType::Podcast => "episode", SpotifyAudioType::NonPlayable => "unknown", diff --git a/src/main.rs b/src/main.rs index 1f67793e..cd2a7861 100644 --- a/src/main.rs +++ b/src/main.rs @@ -345,7 +345,9 @@ fn setup(args: &[String]) -> Setup { .map(|port| port.parse::().unwrap()) .unwrap_or(0); - let name = matches.opt_str("name").unwrap_or("Librespot".to_string()); + let name = matches + .opt_str("name") + .unwrap_or_else(|| "Librespot".to_string()); let credentials = { let cached_credentials = cache.as_ref().and_then(Cache::credentials);