aboutsummaryrefslogtreecommitdiff
path: root/src/device.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-02-20 23:13:38 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-02-21 00:16:00 +0100
commit853e613769087a4bf67023e42f7fc4f3b92339fb (patch)
treeacfa941c5be18587d0299710b3e77e42666d3212 /src/device.rs
parent3e31f2f9f6d7d087b136299468a4a2babdf6ccfb (diff)
downloadntw-853e613769087a4bf67023e42f7fc4f3b92339fb.tar.gz
ntw-853e613769087a4bf67023e42f7fc4f3b92339fb.tar.bz2
Split struct Crc into trait Crc and struct Stm32Crc
There are different ways to implement the CRC check: For testing, we might want to calulate the CRC in the software. On STM32 MCUs, we want to use the CRC peripheral. This patch splits the struct Crc into the Crc trait and the Stm32Crc struct implementing Crc using the CRC peripheral. The Nitrokey struct can now accept any Crc implementation.
Diffstat (limited to 'src/device.rs')
-rw-r--r--src/device.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/device.rs b/src/device.rs
index 9f3d1a7..830fa93 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -94,15 +94,15 @@ impl Response {
}
}
-pub struct Nitrokey {
- crc: Crc,
+pub struct Nitrokey<C: Crc> {
+ crc: C,
request: Option<Request>,
request_crc: u32,
buf: [u8; REPORT_LEN],
}
-impl Nitrokey {
- pub fn new(crc: Crc) -> Self {
+impl<C: Crc> Nitrokey<C> {
+ pub fn new(crc: C) -> Self {
Nitrokey {
crc,
request: None,
@@ -112,7 +112,7 @@ impl Nitrokey {
}
}
-impl HidDevice for Nitrokey {
+impl<C: Crc> HidDevice for Nitrokey<C> {
fn subclass(&self) -> Subclass {
Subclass::BootInterface
}