Ajout de la lecture de carte CPS dans le moteur SESAM-Vitale #29
@ -52,7 +52,7 @@ struct SituationPS {
|
|||||||
habilitation_à_signer_un_lot: String,
|
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_ps = CString::new(lecteur).expect("CString::new failed");
|
||||||
let resource_reader = CString::new("").expect("CString::new failed");
|
let resource_reader = CString::new("").expect("CString::new failed");
|
||||||
let card_number = CString::new(code_pin).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)
|
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();
|
let mut carte_ps = CartePS::default();
|
||||||
for group in groups {
|
for group in groups {
|
||||||
for (field_index, field) in group.content.iter().enumerate() {
|
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 =
|
.habilitation_à_signer_un_lot =
|
||||||
String::from_utf8_lossy(field.content).to_string();
|
String::from_utf8_lossy(field.content).to_string();
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => {
|
||||||
|
return Err(format!(
|
||||||
|
"Unknown (group, field) pair: ({}, {})",
|
||||||
|
group.id, field.id
|
||||||
florian_briand marked this conversation as resolved
Outdated
florian_briand
commented
Outdated
Review
- [x] Implémenter une erreur en cas de match non géré
|
|||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
carte_ps
|
}
|
||||||
|
Ok(carte_ps)
|
||||||
}
|
}
|
||||||
|
|
||||||
florian_briand marked this conversation as resolved
florian_briand
commented
- [x] Ajouter un test sur une CPS avec plusieurs situations
- [x] Ajouter des tests "todo!" avec des formats incorrects
|
|||||||
#[cfg(test)]
|
#[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,
|
48, 2, 48, 48, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49,
|
||||||
florian_briand marked this conversation as resolved
Outdated
florian_briand
commented
@julien.misiak : est-ce que tu peux vérifier que les valeurs des champs de la carte vitale, ci-dessous, ont les bonnes valeurs ? @julien.misiak : est-ce que tu peux vérifier que les valeurs des champs de la carte vitale, ci-dessous, ont les bonnes valeurs ?
julien.misiak
commented
Les valeurs sont OK Les valeurs sont OK
|
|||||||
];
|
];
|
||||||
let blocks = decode_ssv_memory(bytes, bytes.len());
|
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_de_carte_ps, "0");
|
||||||
assert_eq!(carte_ps.titulaire.type_d_identification_nationale, "8");
|
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");
|
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 code_pin = "1234";
|
||||||
let lecteur = "HID Global OMNIKEY 3x21 Smart Card Reader 0";
|
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);
|
println!("CartePS: {:#?}", carte_ps);
|
||||||
florian_briand marked this conversation as resolved
florian_briand
commented
- [x] Virer le `2`
|
|||||||
|
|
||||||
ssv_lire_config();
|
ssv_lire_config();
|
||||||
|
Loading…
Reference in New Issue
Block a user