use super::*;
const SERIALIZED_APDU: &[u8] = &[0xFF, 0x00, 0, 0, 3, 0x42, 0x42, 0x42];
const APDU_RESPONSE: &[u8] = &[0xDE, 0xAD, 0xBE, 0xEF, 0x90, 0x00];
#[test]
#[cfg(feature = "std")]
fn apdu_command_vec() {
let data = std::vec![SERIALIZED_APDU[5]; 3];
let command = APDUCommand {
cla: 0xFF,
ins: 0x00,
p1: 0,
p2: 0,
data,
};
assert_eq!(SERIALIZED_APDU, &command.serialize()[..])
}
#[test]
fn apdu_command_slice() {
let data = &SERIALIZED_APDU[5..];
let _ = APDUCommand {
cla: 0xFF,
ins: 0x00,
p1: 0,
p2: 0,
data,
};
}
#[test]
fn apdu_answer_success() {
let answer = APDUAnswer::from_answer(APDU_RESPONSE).expect("valid answer length >= 2");
let code = answer.error_code().expect("valid error code");
assert_eq!(code, APDUErrorCode::NoError);
assert_eq!(answer.apdu_data(), &APDU_RESPONSE[..4]);
}
#[test]
fn apdu_answer_vec() {
let answer = APDUAnswer::from_answer(APDU_RESPONSE.to_vec()).expect("valid answer length >= 2");
let code = answer.error_code().expect("valid error code");
assert_eq!(code, APDUErrorCode::NoError);
assert_eq!(answer.apdu_data(), &APDU_RESPONSE[..4]);
}
#[test]
fn apdu_answer_error() {
let answer = APDUAnswer::from_answer(&[0x64, 0x00][..]).expect("valid answer length >= 2");
let code = answer.error_code().expect("valid error code");
assert_eq!(code, APDUErrorCode::ExecutionError);
assert_eq!(answer.apdu_data(), &[]);
}
#[test]
fn apdu_answer_unknown() {
let answer = APDUAnswer::from_answer(&APDU_RESPONSE[..4]).expect("valid answer length >= 2");
let code = answer.error_code().expect_err("invalid error code");
assert_eq!(code, 0xBEEF);
assert_eq!(answer.apdu_data(), &[0xDE, 0xAD]);
}
#[test]
fn apdu_answer_too_short() {
let answer = APDUAnswer::from_answer(&[][..]).expect_err("empty answer");
assert_eq!(answer, APDUAnswerError::TooShort);
}