Avoid panics in class

This commit is contained in:
Sosthène Guédon
2023-06-19 08:45:53 +02:00
committed by sosthene-nitrokey
parent edfb8584d5
commit 930982e25c
2 changed files with 12 additions and 6 deletions
+11 -5
View File
@@ -99,9 +99,9 @@ where
Some(self.string_index),
)?;
writer.write(FUNCTIONAL_INTERFACE, &FUNCTIONAL_INTERFACE_DESCRIPTOR)?;
writer.endpoint(&self.pipe.write).unwrap();
writer.endpoint(&self.read).unwrap();
// writer.endpoint(&self.interrupt).unwrap();
writer.endpoint(&self.pipe.write).ok();
writer.endpoint(&self.read).ok();
// writer.endpoint(&self.interrupt).ok();
Ok(())
}
@@ -179,7 +179,10 @@ where
ClassRequest::GetDataRates => {
transfer.accept_with_static(&DATA_RATE_BPS).ok();
}
_ => panic!("unexpected direction for {:?}", &request),
_ => {
error!("unexpected direction for {:?}", &request);
self.pipe.reset_state();
}
}
}
@@ -219,7 +222,10 @@ where
// transfer.reject().ok();
// todo!();
}
_ => panic!("unexpected direction for {:?}", &request),
_ => {
error!("unexpected direction for {:?}", &request);
self.pipe.reset_state();
}
}
}
+1 -1
View File
@@ -98,7 +98,7 @@ where
/// Reset the state of the CCID driver
///
/// This is done on unexpected input instead of panicking
fn reset_state(&mut self) {
pub fn reset_state(&mut self) {
self.seq = 0;
self.state = State::Idle;
self.sent = 0;