From c3ef90638d55a312bc0ce12440651a35576b27f4 Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Sat, 21 Aug 2021 01:19:14 +0200 Subject: [PATCH] Add documentation, remove unused TryFrom implementation. --- openpgp-card/src/apdu/response.rs | 38 +++++++++++++------------------ 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/openpgp-card/src/apdu/response.rs b/openpgp-card/src/apdu/response.rs index 5f32718..f85fb78 100644 --- a/openpgp-card/src/apdu/response.rs +++ b/openpgp-card/src/apdu/response.rs @@ -4,7 +4,22 @@ use crate::errors::{OcErrorStatus, OpenpgpCardError}; use std::convert::TryFrom; -/// APDU Response +/// Response from the card to a command. +/// +/// This object contains pure payload, without the status bytes. +/// Creating a `Response` object is only possible when the response from +/// the card showed an "ok" status code (if the status bytes were no ok, +/// you will receive an Error, never a Response). +#[derive(Debug)] +pub struct Response { + data: Vec, +} + +/// "Raw" APDU Response, including the status bytes. +/// +/// This type is used for processing inside the openpgp-card crate +/// (raw responses with a non-ok status sometimes need to be processed e.g. +/// when a response is sent from the card in "chained" format). #[allow(unused)] #[derive(Clone, Debug)] pub(crate) struct RawResponse { @@ -13,11 +28,6 @@ pub(crate) struct RawResponse { sw2: u8, } -#[derive(Debug)] -pub struct Response { - data: Vec, -} - impl TryFrom for Response { type Error = OpenpgpCardError; @@ -70,22 +80,6 @@ impl RawResponse { } } -impl<'a> TryFrom<&[u8]> for RawResponse { - type Error = OcErrorStatus; - - fn try_from(buf: &[u8]) -> Result { - let n = buf.len(); - if n < 2 { - return Err(OcErrorStatus::ResponseLength(buf.len())); - } - Ok(RawResponse { - data: buf[..n - 2].into(), - sw1: buf[n - 2], - sw2: buf[n - 1], - }) - } -} - impl TryFrom> for RawResponse { type Error = OcErrorStatus;