mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Fix clippy warnings
This commit is contained in:
parent
f5274f5ada
commit
7c3d89112d
11 changed files with 49 additions and 47 deletions
|
@ -110,7 +110,7 @@ impl<R: Read + Seek> AudioDecoder for PassthroughDecoder<R> {
|
|||
|
||||
fn next_packet(&mut self) -> Result<Option<AudioPacket>, AudioError> {
|
||||
// write headers if we are (re)starting
|
||||
if self.bos == false {
|
||||
if !self.bos {
|
||||
self.wtr
|
||||
.write_packet(
|
||||
self.ident.clone(),
|
||||
|
|
|
@ -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<String>,
|
||||
}
|
||||
|
||||
|
@ -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| {
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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<u8>)> for APCodec {
|
||||
impl Encoder<(u8, Vec<u8>)> for ApCodec {
|
||||
type Error = io::Error;
|
||||
|
||||
fn encode(&mut self, item: (u8, Vec<u8>), buf: &mut BytesMut) -> io::Result<()> {
|
||||
|
@ -60,7 +60,7 @@ impl Encoder<(u8, Vec<u8>)> for APCodec {
|
|||
}
|
||||
}
|
||||
|
||||
impl Decoder for APCodec {
|
||||
impl Decoder for ApCodec {
|
||||
type Item = (u8, Bytes);
|
||||
type Error = io::Error;
|
||||
|
||||
|
|
|
@ -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<T: AsyncRead + AsyncWrite + Unpin>(
|
||||
mut connection: T,
|
||||
) -> io::Result<Framed<T, APCodec>> {
|
||||
let local_keys = DHLocalKeys::random(&mut thread_rng());
|
||||
) -> io::Result<Framed<T, ApCodec>> {
|
||||
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<T: AsyncRead + AsyncWrite + Unpin>(
|
|||
|
||||
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?;
|
||||
|
||||
|
|
|
@ -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<TcpStream, APCodec>;
|
||||
pub type Transport = Framed<TcpStream, ApCodec>;
|
||||
|
||||
fn login_error_message(code: &ErrorCode) -> &'static str {
|
||||
pub use ErrorCode::*;
|
||||
|
|
|
@ -17,19 +17,19 @@ pub static DH_PRIME: Lazy<BigUint> = Lazy::new(|| {
|
|||
])
|
||||
});
|
||||
|
||||
pub struct DHLocalKeys {
|
||||
pub struct DhLocalKeys {
|
||||
private_key: BigUint,
|
||||
public_key: BigUint,
|
||||
}
|
||||
|
||||
impl DHLocalKeys {
|
||||
pub fn random<R: Rng>(rng: &mut R) -> DHLocalKeys {
|
||||
impl DhLocalKeys {
|
||||
pub fn random<R: Rng>(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,
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ impl MercuryManager {
|
|||
|
||||
pub fn get<T: Into<String>>(&self, uri: T) -> MercuryFuture<MercuryResponse> {
|
||||
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<T: Into<String>>(&self, uri: T, data: Vec<u8>) -> MercuryFuture<MercuryResponse> {
|
||||
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(),
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ impl From<&str> for SpotifyAudioType {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<&str> for SpotifyAudioType {
|
||||
fn into(self) -> &'static str {
|
||||
match self {
|
||||
impl From<SpotifyAudioType> for &str {
|
||||
fn from(audio_type: SpotifyAudioType) -> &'static str {
|
||||
match audio_type {
|
||||
SpotifyAudioType::Track => "track",
|
||||
SpotifyAudioType::Podcast => "episode",
|
||||
SpotifyAudioType::NonPlayable => "unknown",
|
||||
|
|
|
@ -345,7 +345,9 @@ fn setup(args: &[String]) -> Setup {
|
|||
.map(|port| port.parse::<u16>().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);
|
||||
|
|
Loading…
Reference in a new issue