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> {
|
fn next_packet(&mut self) -> Result<Option<AudioPacket>, AudioError> {
|
||||||
// write headers if we are (re)starting
|
// write headers if we are (re)starting
|
||||||
if self.bos == false {
|
if !self.bos {
|
||||||
self.wtr
|
self.wtr
|
||||||
.write_packet(
|
.write_packet(
|
||||||
self.ident.clone(),
|
self.ident.clone(),
|
||||||
|
|
|
@ -11,7 +11,7 @@ use super::AP_FALLBACK;
|
||||||
const APRESOLVE_ENDPOINT: &str = "http://apresolve.spotify.com:80";
|
const APRESOLVE_ENDPOINT: &str = "http://apresolve.spotify.com:80";
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
struct APResolveData {
|
struct ApResolveData {
|
||||||
ap_list: Vec<String>,
|
ap_list: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ async fn try_apresolve(
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = hyper::body::to_bytes(response.into_body()).await?;
|
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() {
|
let ap = if ap_port.is_some() || proxy.is_some() {
|
||||||
data.ap_list.into_iter().find_map(|ap| {
|
data.ap_list.into_iter().find_map(|ap| {
|
||||||
|
|
|
@ -29,9 +29,9 @@ pub enum DeviceType {
|
||||||
Tablet = 2,
|
Tablet = 2,
|
||||||
Smartphone = 3,
|
Smartphone = 3,
|
||||||
Speaker = 4,
|
Speaker = 4,
|
||||||
TV = 5,
|
Tv = 5,
|
||||||
AVR = 6,
|
Avr = 6,
|
||||||
STB = 7,
|
Stb = 7,
|
||||||
AudioDongle = 8,
|
AudioDongle = 8,
|
||||||
GameConsole = 9,
|
GameConsole = 9,
|
||||||
CastAudio = 10,
|
CastAudio = 10,
|
||||||
|
@ -54,9 +54,9 @@ impl FromStr for DeviceType {
|
||||||
"tablet" => Ok(Tablet),
|
"tablet" => Ok(Tablet),
|
||||||
"smartphone" => Ok(Smartphone),
|
"smartphone" => Ok(Smartphone),
|
||||||
"speaker" => Ok(Speaker),
|
"speaker" => Ok(Speaker),
|
||||||
"tv" => Ok(TV),
|
"tv" => Ok(Tv),
|
||||||
"avr" => Ok(AVR),
|
"avr" => Ok(Avr),
|
||||||
"stb" => Ok(STB),
|
"stb" => Ok(Stb),
|
||||||
"audiodongle" => Ok(AudioDongle),
|
"audiodongle" => Ok(AudioDongle),
|
||||||
"gameconsole" => Ok(GameConsole),
|
"gameconsole" => Ok(GameConsole),
|
||||||
"castaudio" => Ok(CastAudio),
|
"castaudio" => Ok(CastAudio),
|
||||||
|
@ -80,9 +80,9 @@ impl fmt::Display for DeviceType {
|
||||||
Tablet => f.write_str("Tablet"),
|
Tablet => f.write_str("Tablet"),
|
||||||
Smartphone => f.write_str("Smartphone"),
|
Smartphone => f.write_str("Smartphone"),
|
||||||
Speaker => f.write_str("Speaker"),
|
Speaker => f.write_str("Speaker"),
|
||||||
TV => f.write_str("TV"),
|
Tv => f.write_str("TV"),
|
||||||
AVR => f.write_str("AVR"),
|
Avr => f.write_str("AVR"),
|
||||||
STB => f.write_str("STB"),
|
Stb => f.write_str("STB"),
|
||||||
AudioDongle => f.write_str("AudioDongle"),
|
AudioDongle => f.write_str("AudioDongle"),
|
||||||
GameConsole => f.write_str("GameConsole"),
|
GameConsole => f.write_str("GameConsole"),
|
||||||
CastAudio => f.write_str("CastAudio"),
|
CastAudio => f.write_str("CastAudio"),
|
||||||
|
|
|
@ -13,7 +13,7 @@ enum DecodeState {
|
||||||
Payload(u8, usize),
|
Payload(u8, usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct APCodec {
|
pub struct ApCodec {
|
||||||
encode_nonce: u32,
|
encode_nonce: u32,
|
||||||
encode_cipher: Shannon,
|
encode_cipher: Shannon,
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ pub struct APCodec {
|
||||||
decode_state: DecodeState,
|
decode_state: DecodeState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl APCodec {
|
impl ApCodec {
|
||||||
pub fn new(send_key: &[u8], recv_key: &[u8]) -> APCodec {
|
pub fn new(send_key: &[u8], recv_key: &[u8]) -> ApCodec {
|
||||||
APCodec {
|
ApCodec {
|
||||||
encode_nonce: 0,
|
encode_nonce: 0,
|
||||||
encode_cipher: Shannon::new(send_key),
|
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;
|
type Error = io::Error;
|
||||||
|
|
||||||
fn encode(&mut self, item: (u8, Vec<u8>), buf: &mut BytesMut) -> io::Result<()> {
|
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 Item = (u8, Bytes);
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,16 @@ use std::io;
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||||
use tokio_util::codec::{Decoder, Framed};
|
use tokio_util::codec::{Decoder, Framed};
|
||||||
|
|
||||||
use super::codec::APCodec;
|
use super::codec::ApCodec;
|
||||||
use crate::diffie_hellman::DHLocalKeys;
|
use crate::diffie_hellman::DhLocalKeys;
|
||||||
use crate::protocol;
|
use crate::protocol;
|
||||||
use crate::protocol::keyexchange::{APResponseMessage, ClientHello, ClientResponsePlaintext};
|
use crate::protocol::keyexchange::{APResponseMessage, ClientHello, ClientResponsePlaintext};
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
|
||||||
pub async fn handshake<T: AsyncRead + AsyncWrite + Unpin>(
|
pub async fn handshake<T: AsyncRead + AsyncWrite + Unpin>(
|
||||||
mut connection: T,
|
mut connection: T,
|
||||||
) -> io::Result<Framed<T, APCodec>> {
|
) -> io::Result<Framed<T, ApCodec>> {
|
||||||
let local_keys = DHLocalKeys::random(&mut thread_rng());
|
let local_keys = DhLocalKeys::random(&mut thread_rng());
|
||||||
let gc = local_keys.public_key();
|
let gc = local_keys.public_key();
|
||||||
let mut accumulator = client_hello(&mut connection, gc).await?;
|
let mut accumulator = client_hello(&mut connection, gc).await?;
|
||||||
let message: APResponseMessage = recv_packet(&mut connection, &mut accumulator).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 shared_secret = local_keys.shared_secret(&remote_key);
|
||||||
let (challenge, send_key, recv_key) = compute_keys(&shared_secret, &accumulator);
|
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?;
|
client_response(&mut connection, challenge).await?;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod codec;
|
mod codec;
|
||||||
mod handshake;
|
mod handshake;
|
||||||
|
|
||||||
pub use self::codec::APCodec;
|
pub use self::codec::ApCodec;
|
||||||
pub use self::handshake::handshake;
|
pub use self::handshake::handshake;
|
||||||
|
|
||||||
use std::io::{self, ErrorKind};
|
use std::io::{self, ErrorKind};
|
||||||
|
@ -19,7 +19,7 @@ use crate::protocol::keyexchange::{APLoginFailed, ErrorCode};
|
||||||
use crate::proxytunnel;
|
use crate::proxytunnel;
|
||||||
use crate::version;
|
use crate::version;
|
||||||
|
|
||||||
pub type Transport = Framed<TcpStream, APCodec>;
|
pub type Transport = Framed<TcpStream, ApCodec>;
|
||||||
|
|
||||||
fn login_error_message(code: &ErrorCode) -> &'static str {
|
fn login_error_message(code: &ErrorCode) -> &'static str {
|
||||||
pub use ErrorCode::*;
|
pub use ErrorCode::*;
|
||||||
|
|
|
@ -17,19 +17,19 @@ pub static DH_PRIME: Lazy<BigUint> = Lazy::new(|| {
|
||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
||||||
pub struct DHLocalKeys {
|
pub struct DhLocalKeys {
|
||||||
private_key: BigUint,
|
private_key: BigUint,
|
||||||
public_key: BigUint,
|
public_key: BigUint,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DHLocalKeys {
|
impl DhLocalKeys {
|
||||||
pub fn random<R: Rng>(rng: &mut R) -> DHLocalKeys {
|
pub fn random<R: Rng>(rng: &mut R) -> DhLocalKeys {
|
||||||
let key_data = util::rand_vec(rng, 95);
|
let key_data = util::rand_vec(rng, 95);
|
||||||
|
|
||||||
let private_key = BigUint::from_bytes_be(&key_data);
|
let private_key = BigUint::from_bytes_be(&key_data);
|
||||||
let public_key = util::powm(&DH_GENERATOR, &private_key, &DH_PRIME);
|
let public_key = util::powm(&DH_GENERATOR, &private_key, &DH_PRIME);
|
||||||
|
|
||||||
DHLocalKeys {
|
DhLocalKeys {
|
||||||
private_key,
|
private_key,
|
||||||
public_key,
|
public_key,
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl MercuryManager {
|
||||||
|
|
||||||
pub fn get<T: Into<String>>(&self, uri: T) -> MercuryFuture<MercuryResponse> {
|
pub fn get<T: Into<String>>(&self, uri: T) -> MercuryFuture<MercuryResponse> {
|
||||||
self.request(MercuryRequest {
|
self.request(MercuryRequest {
|
||||||
method: MercuryMethod::GET,
|
method: MercuryMethod::Get,
|
||||||
uri: uri.into(),
|
uri: uri.into(),
|
||||||
content_type: None,
|
content_type: None,
|
||||||
payload: Vec::new(),
|
payload: Vec::new(),
|
||||||
|
@ -91,7 +91,7 @@ impl MercuryManager {
|
||||||
|
|
||||||
pub fn send<T: Into<String>>(&self, uri: T, data: Vec<u8>) -> MercuryFuture<MercuryResponse> {
|
pub fn send<T: Into<String>>(&self, uri: T, data: Vec<u8>) -> MercuryFuture<MercuryResponse> {
|
||||||
self.request(MercuryRequest {
|
self.request(MercuryRequest {
|
||||||
method: MercuryMethod::SEND,
|
method: MercuryMethod::Send,
|
||||||
uri: uri.into(),
|
uri: uri.into(),
|
||||||
content_type: None,
|
content_type: None,
|
||||||
payload: vec![data],
|
payload: vec![data],
|
||||||
|
@ -109,7 +109,7 @@ impl MercuryManager {
|
||||||
{
|
{
|
||||||
let uri = uri.into();
|
let uri = uri.into();
|
||||||
let request = self.request(MercuryRequest {
|
let request = self.request(MercuryRequest {
|
||||||
method: MercuryMethod::SUB,
|
method: MercuryMethod::Sub,
|
||||||
uri: uri.clone(),
|
uri: uri.clone(),
|
||||||
content_type: None,
|
content_type: None,
|
||||||
payload: Vec::new(),
|
payload: Vec::new(),
|
||||||
|
|
|
@ -6,10 +6,10 @@ use crate::protocol;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum MercuryMethod {
|
pub enum MercuryMethod {
|
||||||
GET,
|
Get,
|
||||||
SUB,
|
Sub,
|
||||||
UNSUB,
|
Unsub,
|
||||||
SEND,
|
Send,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -33,10 +33,10 @@ pub struct MercuryError;
|
||||||
impl ToString for MercuryMethod {
|
impl ToString for MercuryMethod {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
match *self {
|
match *self {
|
||||||
MercuryMethod::GET => "GET",
|
MercuryMethod::Get => "GET",
|
||||||
MercuryMethod::SUB => "SUB",
|
MercuryMethod::Sub => "SUB",
|
||||||
MercuryMethod::UNSUB => "UNSUB",
|
MercuryMethod::Unsub => "UNSUB",
|
||||||
MercuryMethod::SEND => "SEND",
|
MercuryMethod::Send => "SEND",
|
||||||
}
|
}
|
||||||
.to_owned()
|
.to_owned()
|
||||||
}
|
}
|
||||||
|
@ -45,9 +45,9 @@ impl ToString for MercuryMethod {
|
||||||
impl MercuryMethod {
|
impl MercuryMethod {
|
||||||
pub fn command(&self) -> u8 {
|
pub fn command(&self) -> u8 {
|
||||||
match *self {
|
match *self {
|
||||||
MercuryMethod::GET | MercuryMethod::SEND => 0xb2,
|
MercuryMethod::Get | MercuryMethod::Send => 0xb2,
|
||||||
MercuryMethod::SUB => 0xb3,
|
MercuryMethod::Sub => 0xb3,
|
||||||
MercuryMethod::UNSUB => 0xb4,
|
MercuryMethod::Unsub => 0xb4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,9 @@ impl From<&str> for SpotifyAudioType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<&str> for SpotifyAudioType {
|
impl From<SpotifyAudioType> for &str {
|
||||||
fn into(self) -> &'static str {
|
fn from(audio_type: SpotifyAudioType) -> &'static str {
|
||||||
match self {
|
match audio_type {
|
||||||
SpotifyAudioType::Track => "track",
|
SpotifyAudioType::Track => "track",
|
||||||
SpotifyAudioType::Podcast => "episode",
|
SpotifyAudioType::Podcast => "episode",
|
||||||
SpotifyAudioType::NonPlayable => "unknown",
|
SpotifyAudioType::NonPlayable => "unknown",
|
||||||
|
|
|
@ -345,7 +345,9 @@ fn setup(args: &[String]) -> Setup {
|
||||||
.map(|port| port.parse::<u16>().unwrap())
|
.map(|port| port.parse::<u16>().unwrap())
|
||||||
.unwrap_or(0);
|
.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 credentials = {
|
||||||
let cached_credentials = cache.as_ref().and_then(Cache::credentials);
|
let cached_credentials = cache.as_ref().and_then(Cache::credentials);
|
||||||
|
|
Loading…
Reference in a new issue