Rename StatusByte -> StatusBytes
This commit is contained in:
parent
a52f3a648e
commit
c5d03bd677
5 changed files with 42 additions and 42 deletions
|
@ -13,7 +13,7 @@ use sequoia_openpgp::Cert;
|
|||
use openpgp_card;
|
||||
use openpgp_card::algorithm::AlgoSimple;
|
||||
use openpgp_card::card_do::{KeyGenerationTime, Sex};
|
||||
use openpgp_card::{CardApp, Error, KeyType, StatusByte};
|
||||
use openpgp_card::{CardApp, Error, KeyType, StatusBytes};
|
||||
use openpgp_card_sequoia::{
|
||||
make_cert, public_key_material_to_key, public_to_fingerprint,
|
||||
};
|
||||
|
@ -23,7 +23,7 @@ use crate::util;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum TestResult {
|
||||
Status(StatusByte),
|
||||
Status(StatusBytes),
|
||||
StatusOk,
|
||||
Text(String),
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ pub enum TestError {
|
|||
OPGP(#[from] Error),
|
||||
|
||||
#[error(transparent)]
|
||||
OCard(#[from] StatusByte),
|
||||
OCard(#[from] StatusBytes),
|
||||
|
||||
#[error(transparent)]
|
||||
Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error
|
||||
|
@ -486,7 +486,7 @@ pub fn test_verify(
|
|||
let res = ca.set_name("Notverified<<Hello");
|
||||
|
||||
if let Err(Error::CardStatus(s)) = res {
|
||||
assert_eq!(s, StatusByte::SecurityStatusNotSatisfied);
|
||||
assert_eq!(s, StatusBytes::SecurityStatusNotSatisfied);
|
||||
} else {
|
||||
panic!("Status should be 'SecurityStatusNotSatisfied'");
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use anyhow::Result;
|
|||
use std::convert::TryFrom;
|
||||
|
||||
use crate::apdu::{command::Command, response::RawResponse};
|
||||
use crate::{CardClientBox, Error, StatusByte};
|
||||
use crate::{CardClientBox, Error, StatusBytes};
|
||||
|
||||
// "Maximum amount of bytes in a short APDU command or response" (from pcsc)
|
||||
const MAX_BUFFER_SIZE: usize = 264;
|
||||
|
@ -53,7 +53,7 @@ pub(crate) fn send_command(
|
|||
|
||||
// Only continue if status is 0x61xx or 0x9000.
|
||||
if next.status().0 != 0x61 && next.status() != (0x90, 0x0) {
|
||||
return Err(Error::CardStatus(StatusByte::from(next.status())));
|
||||
return Err(Error::CardStatus(StatusBytes::from(next.status())));
|
||||
}
|
||||
|
||||
log::debug!(" appending {} bytes to response", next.raw_data().len());
|
||||
|
@ -177,7 +177,7 @@ fn send_command_low_level(
|
|||
|| (sw1 == 0x68 && sw2 == 0x83))
|
||||
{
|
||||
// Unexpected status for a non-final chunked response
|
||||
return Err(StatusByte::from((sw1, sw2)).into());
|
||||
return Err(StatusBytes::from((sw1, sw2)).into());
|
||||
}
|
||||
|
||||
// ISO: "If SW1-SW2 is set to '6884', then command
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// SPDX-FileCopyrightText: 2021 Heiko Schaefer <heiko@schaefer.name>
|
||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||
|
||||
use crate::{Error, StatusByte};
|
||||
use crate::{Error, StatusBytes};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
/// Response from the card to a command.
|
||||
|
@ -41,21 +41,21 @@ impl TryFrom<RawResponse> for Response {
|
|||
if value.is_ok() {
|
||||
Ok(Response { data: value.data })
|
||||
} else {
|
||||
Err(Error::CardStatus(StatusByte::from(value.status())))
|
||||
Err(Error::CardStatus(StatusBytes::from(value.status())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RawResponse {
|
||||
pub fn check_ok(&self) -> Result<(), StatusByte> {
|
||||
pub fn check_ok(&self) -> Result<(), StatusBytes> {
|
||||
if !self.is_ok() {
|
||||
Err(StatusByte::from((self.sw1, self.sw2)))
|
||||
Err(StatusBytes::from((self.sw1, self.sw2)))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn data(&self) -> Result<&[u8], StatusByte> {
|
||||
pub fn data(&self) -> Result<&[u8], StatusBytes> {
|
||||
self.check_ok()?;
|
||||
Ok(&self.data)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ pub enum Error {
|
|||
Smartcard(SmartcardError),
|
||||
|
||||
#[error("OpenPGP card error status: {0}")]
|
||||
CardStatus(StatusByte),
|
||||
CardStatus(StatusBytes),
|
||||
|
||||
#[error("Command too long ({0} bytes)")]
|
||||
CommandTooLong(usize),
|
||||
|
@ -30,8 +30,8 @@ pub enum Error {
|
|||
InternalError(anyhow::Error),
|
||||
}
|
||||
|
||||
impl From<StatusByte> for Error {
|
||||
fn from(oce: StatusByte) -> Self {
|
||||
impl From<StatusBytes> for Error {
|
||||
fn from(oce: StatusBytes) -> Self {
|
||||
Error::CardStatus(oce)
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +42,10 @@ impl From<anyhow::Error> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
/// OpenPGP card "Status Byte" errors
|
||||
/// OpenPGP card "Status Bytes" errors
|
||||
#[derive(thiserror::Error, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum StatusByte {
|
||||
pub enum StatusBytes {
|
||||
#[error("Selected file or DO in termination state")]
|
||||
TerminationState,
|
||||
|
||||
|
@ -116,34 +116,34 @@ pub enum StatusByte {
|
|||
UnknownStatus(u8, u8),
|
||||
}
|
||||
|
||||
impl From<(u8, u8)> for StatusByte {
|
||||
impl From<(u8, u8)> for StatusBytes {
|
||||
fn from(status: (u8, u8)) -> Self {
|
||||
match (status.0, status.1) {
|
||||
(0x62, 0x85) => StatusByte::TerminationState,
|
||||
(0x62, 0x85) => StatusBytes::TerminationState,
|
||||
(0x63, 0xC0..=0xCF) => {
|
||||
StatusByte::PasswordNotChecked(status.1 & 0xf)
|
||||
StatusBytes::PasswordNotChecked(status.1 & 0xf)
|
||||
}
|
||||
(0x64, 0x02..=0x80) => StatusByte::TriggeringByCard(status.1),
|
||||
(0x65, 0x01) => StatusByte::MemoryFailure,
|
||||
(0x66, 0x00) => StatusByte::SecurityRelatedIssues,
|
||||
(0x67, 0x00) => StatusByte::WrongLength,
|
||||
(0x68, 0x81) => StatusByte::LogicalChannelNotSupported,
|
||||
(0x68, 0x82) => StatusByte::SecureMessagingNotSupported,
|
||||
(0x68, 0x83) => StatusByte::LastCommandOfChainExpected,
|
||||
(0x68, 0x84) => StatusByte::CommandChainingUnsupported,
|
||||
(0x69, 0x82) => StatusByte::SecurityStatusNotSatisfied,
|
||||
(0x69, 0x83) => StatusByte::AuthenticationMethodBlocked,
|
||||
(0x69, 0x85) => StatusByte::ConditionOfUseNotSatisfied,
|
||||
(0x69, 0x87) => StatusByte::ExpectedSecureMessagingDOsMissing,
|
||||
(0x69, 0x88) => StatusByte::SMDataObjectsIncorrect,
|
||||
(0x6A, 0x80) => StatusByte::IncorrectParametersCommandDataField,
|
||||
(0x6A, 0x82) => StatusByte::FileOrApplicationNotFound,
|
||||
(0x6A, 0x88) => StatusByte::ReferencedDataNotFound,
|
||||
(0x6B, 0x00) => StatusByte::WrongParametersP1P2,
|
||||
(0x6D, 0x00) => StatusByte::INSNotSupported,
|
||||
(0x6E, 0x00) => StatusByte::CLANotSupported,
|
||||
(0x6F, 0x00) => StatusByte::NoPreciseDiagnosis,
|
||||
_ => StatusByte::UnknownStatus(status.0, status.1),
|
||||
(0x64, 0x02..=0x80) => StatusBytes::TriggeringByCard(status.1),
|
||||
(0x65, 0x01) => StatusBytes::MemoryFailure,
|
||||
(0x66, 0x00) => StatusBytes::SecurityRelatedIssues,
|
||||
(0x67, 0x00) => StatusBytes::WrongLength,
|
||||
(0x68, 0x81) => StatusBytes::LogicalChannelNotSupported,
|
||||
(0x68, 0x82) => StatusBytes::SecureMessagingNotSupported,
|
||||
(0x68, 0x83) => StatusBytes::LastCommandOfChainExpected,
|
||||
(0x68, 0x84) => StatusBytes::CommandChainingUnsupported,
|
||||
(0x69, 0x82) => StatusBytes::SecurityStatusNotSatisfied,
|
||||
(0x69, 0x83) => StatusBytes::AuthenticationMethodBlocked,
|
||||
(0x69, 0x85) => StatusBytes::ConditionOfUseNotSatisfied,
|
||||
(0x69, 0x87) => StatusBytes::ExpectedSecureMessagingDOsMissing,
|
||||
(0x69, 0x88) => StatusBytes::SMDataObjectsIncorrect,
|
||||
(0x6A, 0x80) => StatusBytes::IncorrectParametersCommandDataField,
|
||||
(0x6A, 0x82) => StatusBytes::FileOrApplicationNotFound,
|
||||
(0x6A, 0x88) => StatusBytes::ReferencedDataNotFound,
|
||||
(0x6B, 0x00) => StatusBytes::WrongParametersP1P2,
|
||||
(0x6D, 0x00) => StatusBytes::INSNotSupported,
|
||||
(0x6E, 0x00) => StatusBytes::CLANotSupported,
|
||||
(0x6F, 0x00) => StatusBytes::NoPreciseDiagnosis,
|
||||
_ => StatusBytes::UnknownStatus(status.0, status.1),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ mod tlv;
|
|||
|
||||
pub use crate::apdu::response::Response;
|
||||
pub use crate::card_app::CardApp;
|
||||
pub use crate::errors::{Error, SmartcardError, StatusByte};
|
||||
pub use crate::errors::{Error, SmartcardError, StatusBytes};
|
||||
|
||||
/// The CardClient trait defines communication with an OpenPGP card via a
|
||||
/// backend implementation (e.g. the pcsc backend in the crate
|
||||
|
|
Loading…
Reference in a new issue