Ajout de la lecture de carte CPS dans le moteur SESAM-Vitale #29
@ -52,7 +52,7 @@ struct SituationPS {
|
||||
habilitation_à_signer_un_lot: String,
|
||||
}
|
||||
|
||||
pub fn lire_carte(code_pin: &str, lecteur: &str) -> CartePS {
|
||||
pub fn lire_carte(code_pin: &str, lecteur: &str) -> Result<CartePS, String> {
|
||||
let resource_ps = CString::new(lecteur).expect("CString::new failed");
|
||||
let resource_reader = CString::new("").expect("CString::new failed");
|
||||
let card_number = CString::new(code_pin).expect("CString::new failed");
|
||||
@ -79,7 +79,7 @@ pub fn lire_carte(code_pin: &str, lecteur: &str) -> CartePS {
|
||||
decode_carte_ps(groups)
|
||||
}
|
||||
|
||||
fn decode_carte_ps(groups: Vec<Block>) -> CartePS {
|
||||
fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
|
||||
let mut carte_ps = CartePS::default();
|
||||
for group in groups {
|
||||
for (field_index, field) in group.content.iter().enumerate() {
|
||||
@ -244,11 +244,16 @@ fn decode_carte_ps(groups: Vec<Block>) -> CartePS {
|
||||
.habilitation_à_signer_un_lot =
|
||||
String::from_utf8_lossy(field.content).to_string();
|
||||
}
|
||||
_ => (),
|
||||
_ => {
|
||||
return Err(format!(
|
||||
"Unknown (group, field) pair: ({}, {})",
|
||||
group.id, field.id
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
carte_ps
|
||||
Ok(carte_ps)
|
||||
}
|
||||
|
||||
florian_briand marked this conversation as resolved
florian_briand
commented
Review
- [x] Ajouter un test sur une CPS avec plusieurs situations
- [x] Ajouter des tests "todo!" avec des formats incorrects
|
||||
#[cfg(test)]
|
||||
@ -275,7 +280,7 @@ mod test_decode_carte_ps {
|
||||
48, 2, 48, 48, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49,
|
||||
];
|
||||
let blocks = decode_ssv_memory(bytes, bytes.len());
|
||||
let carte_ps = decode_carte_ps(blocks);
|
||||
let carte_ps = decode_carte_ps(blocks).unwrap();
|
||||
|
||||
assert_eq!(carte_ps.titulaire.type_de_carte_ps, "0");
|
||||
assert_eq!(carte_ps.titulaire.type_d_identification_nationale, "8");
|
||||
@ -342,4 +347,22 @@ mod test_decode_carte_ps {
|
||||
);
|
||||
assert_eq!(carte_ps.situations[0].habilitation_à_signer_un_lot, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_missing_field() {
|
||||
todo!();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_unknown_group_field_pair() {
|
||||
todo!();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_invalid_field_format() {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ pub fn demo() {
|
||||
|
||||
let code_pin = "1234";
|
||||
let lecteur = "HID Global OMNIKEY 3x21 Smart Card Reader 0";
|
||||
let carte_ps = lire_carte(code_pin, lecteur);
|
||||
let carte_ps = lire_carte(code_pin, lecteur).unwrap();
|
||||
println!("CartePS: {:#?}", carte_ps);
|
||||
florian_briand marked this conversation as resolved
florian_briand
commented
- [x] Virer le `2`
|
||||
|
||||
ssv_lire_config();
|
||||
|
Loading…
Reference in New Issue
Block a user