feat: Ajout de la fonction SSV_LireDroitsVitale à la crate fsv-sys et refactoring des tests unitaires associés
This commit is contained in:
parent
0f53a99e56
commit
b617c7dd62
@ -2034,6 +2034,7 @@ name = "fsv-sys"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
|
"chrono",
|
||||||
"libc",
|
"libc",
|
||||||
"libloading 0.8.5",
|
"libloading 0.8.5",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
@ -16,3 +16,6 @@ thiserror.workspace = true
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
bindgen = "0.70.1"
|
bindgen = "0.70.1"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
chrono = "0.4.38"
|
||||||
|
@ -14,13 +14,13 @@
|
|||||||
| SSV_InitLIB2 |
|
| SSV_InitLIB2 |
|
||||||
| SSV_LireConfig |
|
| SSV_LireConfig |
|
||||||
| SSV_LireCartePS |
|
| SSV_LireCartePS |
|
||||||
|
| SSV_LireDroitsVitale |
|
||||||
|
|
||||||
## SGD
|
## SGD
|
||||||
|
|
||||||
| Fonctions implémentées |
|
| Fonctions implémentées |
|
||||||
|------------------------|
|
|------------------------|
|
||||||
|
|
||||||
|
|
||||||
## SRT
|
## SRT
|
||||||
|
|
||||||
| Fonctions implémentées |
|
| Fonctions implémentées |
|
||||||
|
@ -109,6 +109,15 @@ impl SSVLibrary<V1_40_14> {
|
|||||||
pZDataOut: *mut *mut libc::c_void,
|
pZDataOut: *mut *mut libc::c_void,
|
||||||
pTailleZone: *mut usize
|
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<V1_40_13> {
|
impl SSVLibrary<V1_40_13> {
|
||||||
@ -128,6 +137,15 @@ impl SSVLibrary<V1_40_13> {
|
|||||||
pZDataOut: *mut *mut libc::c_void,
|
pZDataOut: *mut *mut libc::c_void,
|
||||||
pTailleZone: *mut usize
|
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 {
|
pub fn get_library_path(version: &SupportedFsvVersion) -> String {
|
||||||
@ -162,51 +180,103 @@ mod test {
|
|||||||
|
|
||||||
use super::*;
|
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<V1_40_13> {
|
||||||
|
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
||||||
|
let ssv_library = SSVLibrary::<V1_40_13>::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<V1_40_13>) {
|
||||||
|
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<V1_40_13>) {
|
||||||
|
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<V1_40_13>) {
|
||||||
|
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]
|
#[test]
|
||||||
fn test_initlib2() {
|
fn test_initlib2() {
|
||||||
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
let _ssv_library = common::init_library();
|
||||||
let ssv_library = SSVLibrary::<V1_40_13>::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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lire_config_and_carte_ps() {
|
fn test_lire_config() {
|
||||||
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
let ssv_library = common::init_library();
|
||||||
let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed");
|
common::lire_config(&ssv_library);
|
||||||
|
}
|
||||||
|
|
||||||
let sesam_ini_str =
|
#[test]
|
||||||
CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed");
|
#[ignore="This test requires a CPS card to be inserted in the reader"]
|
||||||
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
|
fn test_lire_carte_ps() {
|
||||||
assert_eq!(result, 0);
|
let ssv_library = common::init_library();
|
||||||
|
common::lire_carte_ps(&ssv_library);
|
||||||
|
}
|
||||||
|
|
||||||
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
|
#[test]
|
||||||
let mut size: libc::size_t = 0;
|
#[ignore="This test requires a CPS card and a Vitale card to be inserted in the readers"]
|
||||||
let result = unsafe { ssv_library.ssv_lire_config(&mut buffer_ptr, &mut size) }.unwrap();
|
fn test_lire_droits_vitale() {
|
||||||
assert_eq!(result, 0);
|
let ssv_library = common::init_library();
|
||||||
unsafe { libc::free(buffer_ptr) };
|
common::lire_droits_vitale(&ssv_library);
|
||||||
|
|
||||||
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) };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user