1
0
Fork 0
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:
Roderick van Domburg 2021-12-29 23:15:08 +01:00
parent e51f475a00
commit 9b6e02fa0d
No known key found for this signature in database
GPG key ID: A9EF5222A26F0451
4 changed files with 15 additions and 3 deletions

View file

@ -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]);

View file

@ -448,6 +448,7 @@ async fn connect(
e = keep_flushing(&mut ws_tx) => {
break Err(e)
}
else => (),
}
};