From 5f5f72b6d13f31da3a54569f75d16e85f134451d Mon Sep 17 00:00:00 2001 From: Kamran Khan Date: Mon, 30 Nov 2020 02:04:52 -0800 Subject: [PATCH] Use arrayref for converting into ApduHeader --- src/ctap/apdu.rs | 6 +++--- src/lib.rs | 4 ++++ src/main.rs | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ctap/apdu.rs b/src/ctap/apdu.rs index 431b18e..fd03f2a 100644 --- a/src/ctap/apdu.rs +++ b/src/ctap/apdu.rs @@ -58,8 +58,8 @@ pub struct ApduHeader { p2: u8, } -impl From<&[u8]> for ApduHeader { - fn from(header: &[u8]) -> Self { +impl From<&[u8; 4]> for ApduHeader { + fn from(header: &[u8; 4]) -> Self { ApduHeader { cla: header[0], ins: header[1], @@ -120,7 +120,7 @@ impl TryFrom<&[u8]> for APDU { let (header, payload) = frame.split_at(APDU_HEADER_LEN); let mut apdu = APDU { - header: header.into(), + header: array_ref!(header, 0, 4).into(), lc: 0x00, data: Vec::new(), le: 0x00, diff --git a/src/lib.rs b/src/lib.rs index d6260c7..07fd02e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,3 +18,7 @@ extern crate alloc; pub mod ctap; pub mod embedded_flash; + +#[macro_use] +extern crate arrayref; + diff --git a/src/main.rs b/src/main.rs index 51c8305..ca10c3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,9 @@ extern crate alloc; extern crate core; extern crate lang_items; +#[macro_use] +extern crate arrayref; + mod ctap; pub mod embedded_flash;