From db5eedd45ae6c551aa99f2b18251b100e05de6b0 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Thu, 10 Oct 2024 15:04:45 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Ajout=20de=20la=20fonction=20SSV=5FLire?= =?UTF-8?q?DroitsVitale=20=C3=A0=20la=20crate=20fsv-sys=20et=20refactoring?= =?UTF-8?q?=20des=20tests=20unitaires=20associ=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 1 + crates/fsv-sys/Cargo.toml | 3 + crates/fsv-sys/PROGRESS.md | 2 +- crates/fsv-sys/src/lib.rs | 148 +++++++++++++++++++++++++++---------- 4 files changed, 114 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41f1f68..6ed28d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2034,6 +2034,7 @@ name = "fsv-sys" version = "0.1.0" dependencies = [ "bindgen", + "chrono", "libc", "libloading 0.8.5", "thiserror", diff --git a/crates/fsv-sys/Cargo.toml b/crates/fsv-sys/Cargo.toml index 354cc42..448410f 100644 --- a/crates/fsv-sys/Cargo.toml +++ b/crates/fsv-sys/Cargo.toml @@ -16,3 +16,6 @@ thiserror.workspace = true [build-dependencies] bindgen = "0.70.1" + +[dev-dependencies] +chrono = "0.4.38" diff --git a/crates/fsv-sys/PROGRESS.md b/crates/fsv-sys/PROGRESS.md index 0a683b1..ca3b5e3 100644 --- a/crates/fsv-sys/PROGRESS.md +++ b/crates/fsv-sys/PROGRESS.md @@ -14,13 +14,13 @@ | SSV_InitLIB2 | | SSV_LireConfig | | SSV_LireCartePS | +| SSV_LireDroitsVitale | ## SGD | Fonctions implémentées | |------------------------| - ## SRT | Fonctions implémentées | diff --git a/crates/fsv-sys/src/lib.rs b/crates/fsv-sys/src/lib.rs index 86f07a4..e3b1357 100644 --- a/crates/fsv-sys/src/lib.rs +++ b/crates/fsv-sys/src/lib.rs @@ -109,6 +109,15 @@ impl SSVLibrary { pZDataOut: *mut *mut libc::c_void, pTailleZone: *mut usize }); + + ssv_function!(BINDINGS_V1_40_14::SSV_LireDroitsVitale, ssv_lire_droits_vitale, { + NomRessourcePS: *const i8, + NomRessourceLecteur: *const i8, + CodePorteurPS: *const i8, + DateConsultation: *const i8, + pZDataOut: *mut *mut libc::c_void, + pTailleZone: *mut usize + }); } impl SSVLibrary { @@ -128,6 +137,15 @@ impl SSVLibrary { pZDataOut: *mut *mut libc::c_void, pTailleZone: *mut usize }); + + ssv_function!(BINDINGS_V1_40_13::SSV_LireDroitsVitale, ssv_lire_droits_vitale, { + NomRessourcePS: *const i8, + NomRessourceLecteur: *const i8, + CodePorteurPS: *const i8, + DateConsultation: *const i8, + pZDataOut: *mut *mut libc::c_void, + pTailleZone: *mut usize + }); } pub fn get_library_path(version: &SupportedFsvVersion) -> String { @@ -162,51 +180,103 @@ mod test { use super::*; + mod common { + use super::*; + + const CPS_READER_NAME: &str = "Gemalto PC Twin Reader (645D94C3) 00 00"; + const CPS_PIN: &str = "1234"; + const VITALE_READER_NAME: &str = "XXXXXX"; + + pub fn init_library() -> SSVLibrary { + let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13); + let ssv_library = SSVLibrary::::new(lib_path).expect("SSVLibrary::new failed"); + + let sesam_ini_str = + CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed"); + let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap(); + assert_eq!(result, 0); + + ssv_library + } + + pub fn lire_config(ssv_library: &SSVLibrary) { + let mut buffer_ptr: *mut libc::c_void = ptr::null_mut(); + let mut size: libc::size_t = 0; + let result = unsafe { ssv_library.ssv_lire_config(&mut buffer_ptr, &mut size) }.unwrap(); + assert_eq!(result, 0); + unsafe { libc::free(buffer_ptr) }; + } + + pub fn lire_carte_ps(ssv_library: &SSVLibrary) { + let nom_ressource_ps = + CString::new(CPS_READER_NAME).expect("CString::new failed"); + let nom_ressource_lecteur = + CString::new("useless parameter").expect("CString::new failed"); + let code_porteur_ps = CString::new(CPS_PIN).expect("CString::new failed"); + let mut buffer_ptr: *mut libc::c_void = ptr::null_mut(); + let mut size: libc::size_t = 0; + let result = unsafe { + ssv_library.ssv_lire_carte_ps( + nom_ressource_ps.as_ptr(), + nom_ressource_lecteur.as_ptr(), + code_porteur_ps.as_ptr(), + &mut buffer_ptr, + &mut size, + ) + }.unwrap(); + assert_eq!(result, 0); + unsafe { libc::free(buffer_ptr) }; + } + + pub fn lire_droits_vitale(ssv_library: &SSVLibrary) { + let nom_ressource_ps = + CString::new(CPS_READER_NAME).expect("CString::new failed"); + let nom_ressource_lecteur = + CString::new(VITALE_READER_NAME).expect("CString::new failed"); + let code_porteur_ps = CString::new(CPS_PIN).expect("CString::new failed"); + // Today's date, in the format YYYYMMDD + let today = chrono::Local::now().format("%Y%m%d").to_string(); + let date_consultation = CString::new(today).expect("CString::new failed"); + let mut buffer_ptr: *mut libc::c_void = ptr::null_mut(); + let mut size: libc::size_t = 0; + + let result = unsafe { + ssv_library.ssv_lire_droits_vitale( + nom_ressource_ps.as_ptr(), + nom_ressource_lecteur.as_ptr(), + code_porteur_ps.as_ptr(), + date_consultation.as_ptr(), + &mut buffer_ptr, + &mut size, + ) + }.unwrap(); + assert_eq!(result, 0); + unsafe { libc::free(buffer_ptr) }; + } + } + #[test] fn test_initlib2() { - let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13); - let ssv_library = SSVLibrary::::new(lib_path).expect("SSVLibrary::new failed"); - - let sesam_ini_str = - CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed"); - let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap(); - assert_eq!(result, 0); + let _ssv_library = common::init_library(); } #[test] - fn test_lire_config_and_carte_ps() { - let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13); - let ssv_library = SSVLibrary::::new(lib_path).expect("SSVLibrary::new failed"); + fn test_lire_config() { + let ssv_library = common::init_library(); + common::lire_config(&ssv_library); + } - let sesam_ini_str = - CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed"); - let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap(); - assert_eq!(result, 0); + #[test] + #[ignore="This test requires a CPS card to be inserted in the reader"] + fn test_lire_carte_ps() { + let ssv_library = common::init_library(); + common::lire_carte_ps(&ssv_library); + } - let mut buffer_ptr: *mut libc::c_void = ptr::null_mut(); - let mut size: libc::size_t = 0; - let result = unsafe { ssv_library.ssv_lire_config(&mut buffer_ptr, &mut size) }.unwrap(); - assert_eq!(result, 0); - unsafe { libc::free(buffer_ptr) }; - - let nom_ressource_ps = - CString::new("Gemalto PC Twin Reader (645D94C3) 00 00").expect("CString::new failed"); - let nom_ressource_lecteur = - CString::new("Gemalto PC Twin Reader (645D94C3) 00 00").expect("CString::new failed"); - let code_porteur_ps = CString::new("1234").expect("CString::new failed"); - let mut buffer_ptr: *mut libc::c_void = ptr::null_mut(); - let mut size: libc::size_t = 0; - let result = unsafe { - ssv_library.ssv_lire_carte_ps( - nom_ressource_ps.as_ptr(), - nom_ressource_lecteur.as_ptr(), - code_porteur_ps.as_ptr(), - &mut buffer_ptr, - &mut size, - ) - } - .unwrap(); - assert_eq!(result, 0); - unsafe { libc::free(buffer_ptr) }; + #[test] + #[ignore="This test requires a CPS card and a Vitale card to be inserted in the readers"] + fn test_lire_droits_vitale() { + let ssv_library = common::init_library(); + common::lire_droits_vitale(&ssv_library); } }