Skip to content

Commit

Permalink
Fixed clippy suggestions, added cross_usb compatible list of devices
Browse files Browse the repository at this point in the history
  • Loading branch information
G2-Games committed Mar 10, 2024
1 parent e426805 commit a443453
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/netmd/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
pub enum Status {
Ready,
Expand Down
7 changes: 3 additions & 4 deletions src/netmd/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ pub fn new_thread_encryptor(
rand::thread_rng().fill_bytes(&mut random_key);

// Encrypt it with the kek
let mut encrypted_random_key = random_key.clone();
match DesEcbEnc::new(&input.kek.into())
let mut encrypted_random_key = random_key;
if let Err(x) = DesEcbEnc::new(&input.kek.into())
.decrypt_padded_mut::<NoPadding>(&mut encrypted_random_key)
{
Err(x) => panic!("Cannot create main key {:?}", x),
Ok(_) => {}
panic!("Cannot create main key {:?}", x)
};

let default_chunk_size = match input.chunk_size {
Expand Down
17 changes: 10 additions & 7 deletions src/netmd/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,7 @@ impl NetMDInterface {
Ok(())
}

#[allow(clippy::too_many_arguments)]
pub async fn send_track<F>(
&mut self,
wireformat: u8,
Expand Down Expand Up @@ -1587,7 +1588,7 @@ impl NetMDInterface {
_written_bytes += binpack.len();
packet_count += 1;
(progress_callback)(total_bytes, _written_bytes);
if total_bytes == _written_bytes.try_into().unwrap() {
if total_bytes == _written_bytes {
packets.close();
break;
}
Expand Down Expand Up @@ -1652,7 +1653,7 @@ pub fn retailmac(key: &[u8], value: &[u8], iv: &[u8; 8]) -> Vec<u8> {
let iv2 = &beginning[beginning.len() - 8..];

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]);
TDesCbcEnc::new(&wonky_key.into(), iv2.into())
.encrypt_padded_mut::<NoPadding>(&mut end, 8)
Expand Down Expand Up @@ -1717,6 +1718,8 @@ pub struct MDTrack {
pub data: Vec<u8>,
pub chunk_size: usize,
pub full_width_title: Option<String>,

#[allow(clippy::type_complexity)]
pub encrypt_packets_iterator:
Box<dyn Fn(DataEncryptorInput) -> UnboundedReceiver<(Vec<u8>, Vec<u8>, Vec<u8>)>>,
}
Expand Down Expand Up @@ -1775,7 +1778,7 @@ impl MDTrack {

pub fn get_encrypting_iterator(&mut self) -> UnboundedReceiver<(Vec<u8>, Vec<u8>, Vec<u8>)> {
(self.encrypt_packets_iterator)(DataEncryptorInput {
kek: self.get_kek().clone(),
kek: self.get_kek(),
frame_size: self.frame_size(),
chunk_size: self.chunk_size(),
data: std::mem::take(&mut self.data),
Expand Down Expand Up @@ -1814,7 +1817,7 @@ impl<'a> MDSession<'a> {
}

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.hex_session_key = None;
Expand All @@ -1831,14 +1834,14 @@ impl<'a> MDSession<'a> {
where
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());
}
self.md
.setup_download(
&track.content_id(),
&track.get_kek(),
&self.hex_session_key.as_ref().unwrap(),
self.hex_session_key.as_ref().unwrap(),
)
.await?;
let data_format = track.data_format();
Expand Down Expand Up @@ -1866,7 +1869,7 @@ impl<'a> MDSession<'a> {
.await?;
}
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?;

Ok((track_index, uuid, ccid))
Expand Down
2 changes: 1 addition & 1 deletion src/netmd/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub fn agressive_sanitize_title(title: &str) -> String {
.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);
std::time::Duration::from_micros(
(time[0] * 3600000000) + (time[1] * 60000000) + (time[2] * 1000000) + (time[3] * 11600),
Expand Down

0 comments on commit a443453

Please sign in to comment.