Fixed clippy suggestions, added cross_usb compatible list of devices

This commit is contained in:
G2-Games 2024-03-10 00:12:17 -06:00
parent e4268056d2
commit a443453fad
4 changed files with 23 additions and 12 deletions

View file

@ -69,6 +69,15 @@ pub static DEVICE_IDS: Lazy<Box<[DeviceId]>> = Lazy::new(|| {
} }
}); });
pub static DEVICE_IDS_CROSSUSB: Lazy<Box<[cross_usb::DeviceFilter]>> = Lazy::new(|| {
DEVICE_IDS.iter().map(|d|{
cross_usb::device_filter! {
vendor_id: d.vendor_id,
product_id: d.product_id,
}
}).collect()
});
/// The current status of the Minidisc device /// The current status of the Minidisc device
pub enum Status { pub enum Status {
Ready, Ready,

View file

@ -22,12 +22,11 @@ pub fn new_thread_encryptor(
rand::thread_rng().fill_bytes(&mut random_key); rand::thread_rng().fill_bytes(&mut random_key);
// Encrypt it with the kek // Encrypt it with the kek
let mut encrypted_random_key = random_key.clone(); let mut encrypted_random_key = random_key;
match DesEcbEnc::new(&input.kek.into()) if let Err(x) = DesEcbEnc::new(&input.kek.into())
.decrypt_padded_mut::<NoPadding>(&mut encrypted_random_key) .decrypt_padded_mut::<NoPadding>(&mut encrypted_random_key)
{ {
Err(x) => panic!("Cannot create main key {:?}", x), panic!("Cannot create main key {:?}", x)
Ok(_) => {}
}; };
let default_chunk_size = match input.chunk_size { let default_chunk_size = match input.chunk_size {

View file

@ -1531,6 +1531,7 @@ impl NetMDInterface {
Ok(()) Ok(())
} }
#[allow(clippy::too_many_arguments)]
pub async fn send_track<F>( pub async fn send_track<F>(
&mut self, &mut self,
wireformat: u8, wireformat: u8,
@ -1587,7 +1588,7 @@ impl NetMDInterface {
_written_bytes += binpack.len(); _written_bytes += binpack.len();
packet_count += 1; packet_count += 1;
(progress_callback)(total_bytes, _written_bytes); (progress_callback)(total_bytes, _written_bytes);
if total_bytes == _written_bytes.try_into().unwrap() { if total_bytes == _written_bytes {
packets.close(); packets.close();
break; break;
} }
@ -1652,7 +1653,7 @@ pub fn retailmac(key: &[u8], value: &[u8], iv: &[u8; 8]) -> Vec<u8> {
let iv2 = &beginning[beginning.len() - 8..]; let iv2 = &beginning[beginning.len() - 8..];
let mut wonky_key = [0u8; 24]; let mut wonky_key = [0u8; 24];
wonky_key[0..16].clone_from_slice(&key); wonky_key[0..16].clone_from_slice(key);
wonky_key[16..].clone_from_slice(&key[0..8]); wonky_key[16..].clone_from_slice(&key[0..8]);
TDesCbcEnc::new(&wonky_key.into(), iv2.into()) TDesCbcEnc::new(&wonky_key.into(), iv2.into())
.encrypt_padded_mut::<NoPadding>(&mut end, 8) .encrypt_padded_mut::<NoPadding>(&mut end, 8)
@ -1717,6 +1718,8 @@ pub struct MDTrack {
pub data: Vec<u8>, pub data: Vec<u8>,
pub chunk_size: usize, pub chunk_size: usize,
pub full_width_title: Option<String>, pub full_width_title: Option<String>,
#[allow(clippy::type_complexity)]
pub encrypt_packets_iterator: pub encrypt_packets_iterator:
Box<dyn Fn(DataEncryptorInput) -> UnboundedReceiver<(Vec<u8>, Vec<u8>, Vec<u8>)>>, Box<dyn Fn(DataEncryptorInput) -> UnboundedReceiver<(Vec<u8>, Vec<u8>, Vec<u8>)>>,
} }
@ -1775,7 +1778,7 @@ impl MDTrack {
pub fn get_encrypting_iterator(&mut self) -> UnboundedReceiver<(Vec<u8>, Vec<u8>, Vec<u8>)> { pub fn get_encrypting_iterator(&mut self) -> UnboundedReceiver<(Vec<u8>, Vec<u8>, Vec<u8>)> {
(self.encrypt_packets_iterator)(DataEncryptorInput { (self.encrypt_packets_iterator)(DataEncryptorInput {
kek: self.get_kek().clone(), kek: self.get_kek(),
frame_size: self.frame_size(), frame_size: self.frame_size(),
chunk_size: self.chunk_size(), chunk_size: self.chunk_size(),
data: std::mem::take(&mut self.data), data: std::mem::take(&mut self.data),
@ -1814,7 +1817,7 @@ impl<'a> MDSession<'a> {
} }
pub async fn close(&mut self) -> Result<(), Box<dyn Error>> { pub async fn close(&mut self) -> Result<(), Box<dyn Error>> {
if let None = self.hex_session_key { if self.hex_session_key.is_none() {
self.md.session_key_forget().await?; self.md.session_key_forget().await?;
} }
self.hex_session_key = None; self.hex_session_key = None;
@ -1831,14 +1834,14 @@ impl<'a> MDSession<'a> {
where where
F: Fn(usize, usize), F: Fn(usize, usize),
{ {
if let None = self.hex_session_key { if self.hex_session_key.is_none() {
return Err("Cannot download a track using a non-init()'ed session!".into()); return Err("Cannot download a track using a non-init()'ed session!".into());
} }
self.md self.md
.setup_download( .setup_download(
&track.content_id(), &track.content_id(),
&track.get_kek(), &track.get_kek(),
&self.hex_session_key.as_ref().unwrap(), self.hex_session_key.as_ref().unwrap(),
) )
.await?; .await?;
let data_format = track.data_format(); let data_format = track.data_format();
@ -1866,7 +1869,7 @@ impl<'a> MDSession<'a> {
.await?; .await?;
} }
self.md self.md
.commit_track(track_index, &self.hex_session_key.as_ref().unwrap()) .commit_track(track_index, self.hex_session_key.as_ref().unwrap())
.await?; .await?;
Ok((track_index, uuid, ccid)) Ok((track_index, uuid, ccid))

View file

@ -173,7 +173,7 @@ pub fn agressive_sanitize_title(title: &str) -> String {
.into() .into()
} }
pub fn time_to_duration(time: &Vec<u64>) -> std::time::Duration { pub fn time_to_duration(time: &[u64]) -> std::time::Duration {
assert_eq!(time.len(), 4); assert_eq!(time.len(), 4);
std::time::Duration::from_micros( std::time::Duration::from_micros(
(time[0] * 3600000000) + (time[1] * 60000000) + (time[2] * 1000000) + (time[3] * 11600), (time[0] * 3600000000) + (time[1] * 60000000) + (time[2] * 1000000) + (time[3] * 11600),