mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-04 18:29:45 +02:00
Prevent a few potential panics
This commit is contained in:
parent
e51f475a00
commit
9b6e02fa0d
4 changed files with 15 additions and 3 deletions
|
@ -15,6 +15,8 @@ use crate::{protocol::authentication::AuthenticationType, Error};
|
|||
pub enum AuthenticationError {
|
||||
#[error("unknown authentication type {0}")]
|
||||
AuthType(u32),
|
||||
#[error("invalid key")]
|
||||
Key,
|
||||
}
|
||||
|
||||
impl From<AuthenticationError> for Error {
|
||||
|
@ -90,6 +92,10 @@ impl Credentials {
|
|||
|
||||
let key = {
|
||||
let mut key = [0u8; 24];
|
||||
if key.len() < 20 {
|
||||
return Err(AuthenticationError::Key.into());
|
||||
}
|
||||
|
||||
pbkdf2::<Hmac<Sha1>>(&secret, username.as_bytes(), 0x100, &mut key[0..20]);
|
||||
|
||||
let hash = &Sha1::digest(&key[..20]);
|
||||
|
|
|
@ -448,6 +448,7 @@ async fn connect(
|
|||
e = keep_flushing(&mut ws_tx) => {
|
||||
break Err(e)
|
||||
}
|
||||
else => (),
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue