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
pub enum Status {
Ready,

View file

@ -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 {

View file

@ -1531,6 +1531,7 @@ impl NetMDInterface {
Ok(())
}
#[allow(clippy::too_many_arguments)]
pub async fn send_track<F>(
&mut self,
wireformat: u8,
@ -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;
}
@ -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)
@ -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>)>>,
}
@ -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),
@ -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;
@ -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();
@ -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))

View file

@ -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),