Add documentation, remove unused TryFrom implementation.
This commit is contained in:
parent
7a7db8a131
commit
c3ef90638d
1 changed files with 16 additions and 22 deletions
|
@ -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<u8>,
|
||||
}
|
||||
|
||||
/// "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<u8>,
|
||||
}
|
||||
|
||||
impl TryFrom<RawResponse> 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<Self, OcErrorStatus> {
|
||||
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<Vec<u8>> for RawResponse {
|
||||
type Error = OcErrorStatus;
|
||||
|
||||
|
|
Loading…
Reference in a new issue