scll_core/command/
select.rs1use crate::command::{build, BuildError, Capdu};
4
5#[allow(clippy::module_name_repetitions)] pub fn select_by_aid(aid: &[u8]) -> Result<Capdu, BuildError> {
17 build(0x00, 0xA4, 0x04, 0x00, aid, true)
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23 use proptest::prelude::*;
24 use scll_test_util::HexSlice;
25
26 #[test]
27 fn empty_aid_selects_default_application() {
28 let apdu = select_by_aid(&[]).unwrap();
30 assert_eq!(HexSlice(&apdu), HexSlice([0x00, 0xA4, 0x04, 0x00, 0x00]));
31 }
32
33 #[test]
34 fn by_aid_wraps_header_lc_and_le() {
35 let aid = [0xA0, 0x00, 0x00, 0x01, 0x51];
37 let apdu = select_by_aid(&aid).unwrap();
38 assert_eq!(
39 HexSlice(&apdu),
40 HexSlice([0x00, 0xA4, 0x04, 0x00, 0x05, 0xA0, 0x00, 0x00, 0x01, 0x51, 0x00])
41 );
42 }
43
44 #[test]
45 fn oversized_input_returns_overflow_not_panic() {
46 let big = [0xABu8; 256];
48 assert_eq!(select_by_aid(&big), Err(BuildError::Overflow));
49 }
50
51 proptest! {
52 #[test]
54 fn round_trips_any_short_aid(aid in proptest::collection::vec(any::<u8>(), 1..=255)) {
55 let apdu = select_by_aid(&aid).unwrap();
56 prop_assert_eq!(&apdu[0..4], &[0x00, 0xA4, 0x04, 0x00]);
57 prop_assert_eq!(usize::from(apdu[4]), aid.len());
58 prop_assert_eq!(&apdu[5..5 + aid.len()], aid.as_slice());
59 prop_assert_eq!(*apdu.last().unwrap(), 0x00);
60 }
61
62 #[test]
64 fn never_panics(aid in proptest::collection::vec(any::<u8>(), 0..400)) {
65 let _ = select_by_aid(&aid);
66 }
67 }
68}