1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-04 10:19:27 +02:00

Small refactor of librespot-core

* Remove default impl for `SessionConfig`
* Move util mod to single file
* Restore privacy of mods
* Move `fn get_credentials` to application
* Remove `extern crate` statements
This commit is contained in:
johannesd3 2021-02-10 22:40:33 +01:00 committed by Johannesd3
parent c0942f14e8
commit 9253be7bc9
8 changed files with 31 additions and 85 deletions

View file

@ -142,30 +142,6 @@ where
base64::decode(&v).map_err(|e| serde::de::Error::custom(e.to_string()))
}
pub fn get_credentials<F: FnOnce(&String) -> String>(
username: Option<String>,
password: Option<String>,
cached_credentials: Option<Credentials>,
prompt: F,
) -> Option<Credentials> {
match (username, password, cached_credentials) {
(Some(username), Some(password), _) => Some(Credentials::with_password(username, password)),
(Some(ref username), _, Some(ref credentials)) if *username == credentials.username => {
Some(credentials.clone())
}
(Some(username), None, _) => Some(Credentials::with_password(
username.clone(),
prompt(&username),
)),
(None, _, Some(credentials)) => Some(credentials),
(None, _, None) => None,
}
}
error_chain! {
types {
AuthenticationError, AuthenticationErrorKind, AuthenticationResultExt, AuthenticationResult;

View file

@ -1,9 +1,6 @@
use std::fmt;
use std::str::FromStr;
use url::Url;
use uuid::Uuid;
use crate::version;
#[derive(Clone, Debug)]
pub struct SessionConfig {
@ -13,18 +10,6 @@ pub struct SessionConfig {
pub ap_port: Option<u16>,
}
impl Default for SessionConfig {
fn default() -> SessionConfig {
let device_id = Uuid::new_v4().to_hyphenated().to_string();
SessionConfig {
user_agent: version::version_string(),
device_id: device_id,
proxy: None,
ap_port: None,
}
}
}
#[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub enum DeviceType {
Unknown = 0,

View file

@ -8,43 +8,19 @@ extern crate serde_derive;
extern crate pin_project_lite;
#[macro_use]
extern crate error_chain;
extern crate aes;
extern crate base64;
extern crate byteorder;
extern crate bytes;
extern crate futures;
extern crate hmac;
extern crate httparse;
extern crate hyper;
extern crate num_bigint;
extern crate num_integer;
extern crate num_traits;
extern crate once_cell;
extern crate pbkdf2;
extern crate protobuf;
extern crate rand;
extern crate serde;
extern crate serde_json;
extern crate sha1;
extern crate shannon;
pub extern crate tokio;
extern crate tokio_util;
extern crate tower_service;
extern crate url;
extern crate uuid;
extern crate librespot_protocol as protocol;
use librespot_protocol as protocol;
#[macro_use]
mod component;
pub mod apresolve;
mod apresolve;
pub mod audio_key;
pub mod authentication;
pub mod cache;
pub mod channel;
pub mod config;
pub mod connection;
mod connection;
pub mod diffie_hellman;
pub mod keymaster;
pub mod mercury;