From 2b45f5aa7e3ea6143305e0a6e3c09450214d727c Mon Sep 17 00:00:00 2001 From: lienjukaisim <154924955+lienjukaisim@users.noreply.github.com> Date: Wed, 14 Aug 2024 15:33:56 +0200 Subject: [PATCH] --- crates/sesam-vitale/lib/ssvw64.lib | Bin 2104 -> 2328 bytes crates/sesam-vitale/src/cartevitale.rs | 411 ++++++++++++------------ crates/sesam-vitale/src/main.rs | 2 +- crates/sesam-vitale/src/ssv_memory.rs | 2 + scripts/compile_win_headers - Copie.bat | 26 ++ scripts/compile_win_headers.bat | 4 +- scripts/ssvw64.def | 6 + 7 files changed, 246 insertions(+), 205 deletions(-) create mode 100644 scripts/compile_win_headers - Copie.bat create mode 100644 scripts/ssvw64.def diff --git a/crates/sesam-vitale/lib/ssvw64.lib b/crates/sesam-vitale/lib/ssvw64.lib index 13cbd5a9e64e27005c0cc1330e6d2e10e663592a..9900c54b6cf4fa02837acd1f5298be6c3a3d59e0 100644 GIT binary patch delta 579 zcmdlXFhgj9G`q2xv6+Rb@#F+1F&iUu3k3*B;9_84;AUW8+Qz`Za)*I|O^AVkJqwC2 z0cjxSu!G_iKzhYw1s0!)JF@hHgTvx|GK*4Oit;l{io-HX5_3`+;^Q-O3*xa!O;%(S zL3V?)kp;pH>_A6sV`5;q!@|HI#Kypo1r)dh#C9AE3@d;b=s*S*237_(26hHU1|}GL zaxbI42v*DFSxhH?V6>ae%gD!r?7+zn*>sRxp~hS~XV2tLrgbdp44<1OTQf&80jVrj zsmU9d&m*Z5n>>d_0IYUBOB+nB`s4&w4v2bhWVND37AEk}O=)9h0NRmuXYxiC`N^x8 zq$ew~6~RnUMwlQq`5v1-k}2Yowb_NiHafDKpomX~imzn1KoS2B6&K}Do}9!kj3g)K qU}^+)kOC;a|Nm!TNNEGPN&y(I%)rpZ7KRMP#bxDYCVDA3ISc^gY?zJ! delta 407 zcmbOsv_oKmG`pd>v8jcL`Q!^sVkSmLMhXy+z{SA8z{$YC3vxSQr=ym71);avn*Y*km470kB$m);5@0^~o1lIUwr2k=2SCS(w0sAf=6&0cc0soym%< z@{^^Qr6*5hD}tGzj4(lJvLCxXk}2YoXR`}~ZQRIif+Eh$0TGwvus{*dhl;myC<6el CM`1w# diff --git a/crates/sesam-vitale/src/cartevitale.rs b/crates/sesam-vitale/src/cartevitale.rs index 8bcd914..3c0ba22 100644 --- a/crates/sesam-vitale/src/cartevitale.rs +++ b/crates/sesam-vitale/src/cartevitale.rs @@ -4,7 +4,6 @@ use std::ptr; use crate::libssv::SSV_LireDroitsVitale; - use crate::ssv_memory::{decode_ssv_memory, Block}; #[derive(Debug, Default)] @@ -15,139 +14,133 @@ pub struct CarteVitale { donneesBeneficiaire: Vec, } - - // 1. CB = Caractères Binaires » // 2. CE = Caractères « Etendus » (ISO 8859-1) // 3. CA = Caractères Alphanumériques (ASCII?) // 4. CN = Caractères Numériques #[derive(Debug, Default)] struct DonneesAssure { - type_de_carte_vitale: char, // CA - numero_de_serie: String, // CN - 1 -> 20 - date_de_fin_de_validite: String, // CN - Format AAAAMMJJ0000 - donnees_administration_ruf1: char, // CN - donnees_administration_ruf2: String, // CA - 24 - donnees_ruf_administration: String, // CE - 10 - type_d_identification_du_porteur: char, // CA - numero_national_d_immatriculation: String, // CA - 13 - cle_du_nir: String, // CA - 2 - code_regime: String, // CN - 2 - caisse_gestionnaire: String, // CN - 3 - centre_gestionnaire: String, // CN - 4 - code_gestion: String, // CA - 2 - donnees_ruf_famille: String, // CE - 55 + type_de_carte_vitale: char, // CA + numero_de_serie: String, // CN - 1 -> 20 + date_de_fin_de_validite: String, // CN - Format AAAAMMJJ0000 + donnees_administration_ruf1: char, // CN + donnees_administration_ruf2: String, // CA - 24 + donnees_ruf_administration: String, // CE - 10 + type_d_identification_du_porteur: char, // CA + numero_national_d_immatriculation: String, // CA - 13 + cle_du_nir: String, // CA - 2 + code_regime: String, // CN - 2 + caisse_gestionnaire: String, // CN - 3 + centre_gestionnaire: String, // CN - 4 + code_gestion: String, // CA - 2 + donnees_ruf_famille: String, // CE - 55 } - #[derive(Debug, Default)] struct ServiceAMOFamille { - code_service_amo_famille: String, // CN - 2 - date_de_debut_service_amo_famille: String, // CN - Format AAAAMMJJ0000 - date_de_fin_service_amo_famille: String, // CN - Format AAAAMMJJ0000 + code_service_amo_famille: String, // CN - 2 + date_de_debut_service_amo_famille: String, // CN - Format AAAAMMJJ0000 + date_de_fin_service_amo_famille: String, // CN - Format AAAAMMJJ0000 } - #[derive(Debug, Default)] struct DonneesAccidentTravail { - organisme_gestionnaire_risque_at: String, // CN - 9 - code_at: char, // CA - 2 - identifiant_at: String, // CN - 9 - organisme_gestionnaire_at1: String, // CN - 9 - code_at1: char, // CA - 2 - identifiant_at1: String, // CN - 9 - organisme_gestionnaire_at2: String, // CN - 9 - code_at2: char, // CA - 2 - identifiant_at2: String, // CN - 9 + organisme_gestionnaire_risque_at: String, // CN - 9 + code_at: char, // CA - 2 + identifiant_at: String, // CN - 9 + organisme_gestionnaire_at1: String, // CN - 9 + code_at1: char, // CA - 2 + identifiant_at1: String, // CN - 9 + organisme_gestionnaire_at2: String, // CN - 9 + code_at2: char, // CA - 2 + identifiant_at2: String, // CN - 9 } - #[derive(Debug, Default)] struct DonneesBeneficiaire { - nom_usuel: String, // CE - 27 - nom_de_famille: String, // CE - 27 - prenom: String, // CE - 27 - adresse_ligne_1: String, // CE - 32 - adresse_ligne_2: String, // CE - 32 - adresse_ligne_3: String, // CE - 32 - adresse_ligne_4: String, // CE - 32 - adresse_ligne_5: String, // CE - 32 - nir_certifie: String, // CA - 13 - cle_du_nir_certifie: String, // CN - 2 - date_de_certification_du_nir: String, // CN - Format AAAAMMJJ0000 - date_de_naissance: String, // CN - Format AAAAMMJJ0000 - rang_de_naissance: String, // CN - 1 - qualite: String, // CN - 2 - code_service_amo_beneficiaire: char, // CA - 2 - date_de_debut_service_amo: String, // CN - Format AAAAMMJJ0000 - date_de_fin_service_amo: String, // CN - Format AAAAMMJJ0000 - donnees_ruf_amo: String, // CE - 30 + nom_usuel: String, // CE - 27 + nom_de_famille: String, // CE - 27 + prenom: String, // CE - 27 + adresse_ligne_1: String, // CE - 32 + adresse_ligne_2: String, // CE - 32 + adresse_ligne_3: String, // CE - 32 + adresse_ligne_4: String, // CE - 32 + adresse_ligne_5: String, // CE - 32 + nir_certifie: String, // CA - 13 + cle_du_nir_certifie: String, // CN - 2 + date_de_certification_du_nir: String, // CN - Format AAAAMMJJ0000 + date_de_naissance: String, // CN - Format AAAAMMJJ0000 + rang_de_naissance: String, // CN - 1 + qualite: String, // CN - 2 + code_service_amo_beneficiaire: char, // CA - 2 + date_de_debut_service_amo: String, // CN - Format AAAAMMJJ0000 + date_de_fin_service_amo: String, // CN - Format AAAAMMJJ0000 + donnees_ruf_amo: String, // CE - 30 periodeDroitsAMO: Vec, periodeCodeCouverture: Vec, - donneesMutuelle: DonneesMutuelle, - donneesComplementaire: DonneesComplementaire, + donneesMutuelle: DonneesMutuelle, + donneesComplementaire: DonneesComplementaire, donneesRUFBeneficiaireComplementaire: DonneesRUFBeneficiaireComplementaire, } - #[derive(Debug, Default)] struct PeriodeDroitsAMO { - date_de_debut_droits_amo: String, // CN - Format AAAAMMJJ0000 - date_de_fin_droits_amo: String, // CN - Format AAAAMMJJ0000 + date_de_debut_droits_amo: String, // CN - Format AAAAMMJJ0000 + date_de_fin_droits_amo: String, // CN - Format AAAAMMJJ0000 } - #[derive(Debug, Default)] struct PeriodeCodeCouverture { - date_de_debut_code_couverture: String, // CN - Format AAAAMMJJ0000 - date_de_fin_code_couverture: String, // CN - Format AAAAMMJJ0000 - code_ald: String, // CN - 1 - code_situation: String, // CN - 4 + date_de_debut_code_couverture: String, // CN - Format AAAAMMJJ0000 + date_de_fin_code_couverture: String, // CN - Format AAAAMMJJ0000 + code_ald: String, // CN - 1 + code_situation: String, // CN - 4 } - #[derive(Debug, Default)] struct DonneesMutuelle { - identification_mutuelle: String, // CN - 8 - garanties_effectives: String, // CA - 8 - indicateur_de_traitement_mutuelle: String, // CN - 2 - type_de_services_associes: char, // CA - 1 - services_associes_au_contrat: String, // CA - 17 - code_aiguillage_sts: char, // CA - 1 + identification_mutuelle: String, // CN - 8 + garanties_effectives: String, // CA - 8 + indicateur_de_traitement_mutuelle: String, // CN - 2 + type_de_services_associes: char, // CA - 1 + services_associes_au_contrat: String, // CA - 17 + code_aiguillage_sts: char, // CA - 1 periodeDroitsMutuelle: Vec, } - #[derive(Debug, Default)] struct PeriodeDroitsMutuelle { - date_de_debut_droits_mutuelle: String, // CN - Format AAAAMMJJ0000 - date_de_fin_droits_mutuelle: String, // CN - Format AAAAMMJJ0000 + date_de_debut_droits_mutuelle: String, // CN - Format AAAAMMJJ0000 + date_de_fin_droits_mutuelle: String, // CN - Format AAAAMMJJ0000 } - #[derive(Debug, Default)] struct DonneesComplementaire { - numero_complementaire_b2: String, // CA - 10 - numero_complementaire_edi: String, // CA - 19 - numero_adherent_amc: String, // CA - 8 - indicateur_de_traitement_amc: String, // CN - 2 - date_de_debut_validite_amc: String, // CN - Format AAAAMMJJ0000 - date_de_fin_validite_amc: String, // CN - Format AAAAMMJJ0000 - code_routage_flux_amc: String, // CA - 2 - identifiant_hote: String, // CA - 3 - nom_de_domaine_amc: String, // CE - 20 - code_aiguillage_sts: char, // CA - 1 - type_de_services_associes: char, // CA - 1 - services_associes_au_contrat: String, // CE - 17 + numero_complementaire_b2: String, // CA - 10 + numero_complementaire_edi: String, // CA - 19 + numero_adherent_amc: String, // CA - 8 + indicateur_de_traitement_amc: String, // CN - 2 + date_de_debut_validite_amc: String, // CN - Format AAAAMMJJ0000 + date_de_fin_validite_amc: String, // CN - Format AAAAMMJJ0000 + code_routage_flux_amc: String, // CA - 2 + identifiant_hote: String, // CA - 3 + nom_de_domaine_amc: String, // CE - 20 + code_aiguillage_sts: char, // CA - 1 + type_de_services_associes: char, // CA - 1 + services_associes_au_contrat: String, // CE - 17 } #[derive(Debug, Default)] struct DonneesRUFBeneficiaireComplementaire { - donnees_ruf_beneficiaire_complementaire: String, // CE - 115 + donnees_ruf_beneficiaire_complementaire: String, // CE - 115 } - -pub fn LireDroitsVitale(lecteurPS: &str, lecteurVitale: &str, codePorteurPS: &str, dateConsultation: &str) -> Result { +pub fn LireDroitsVitale( + lecteurPS: &str, + lecteurVitale: &str, + codePorteurPS: &str, + dateConsultation: &str, +) -> Result { let resource_ps = CString::new(lecteurPS).expect("CString::new failed"); let resource_vitale = CString::new(lecteurVitale).expect("CString::new failed"); let card_number = CString::new(codePorteurPS).expect("CString::new failed"); @@ -165,137 +158,151 @@ pub fn LireDroitsVitale(lecteurPS: &str, lecteurVitale: &str, codePorteurPS: &st &mut buffer, &mut size, ); - println!("SSV_LireCartePS result: {}", result); + println!("SSV_LireDroitsVitale result: {}", result); if !buffer.is_null() { hex_values = std::slice::from_raw_parts(buffer as *const u8, size); - libc::free(buffer); } } + let groups = decode_ssv_memory(hex_values, hex_values.len()); + + unsafe { + libc::free(buffer); + } + decode_carte_vitale(groups) } fn decode_carte_vitale(groups: Vec) -> Result { let mut cartevitale = CarteVitale::default(); - - // let lastBlock :u16; - // let lastField :u16; for group in groups { for field in group.content { - - match (group.id, field.id) { - (101, 1) => { - let byte = field.content[0]; - cartevitale.donneesAssure.type_de_carte_vitale = byte as char; + if field.content.len() > 0 { + match (group.id, field.id) { + (101, 1) => { + let byte = field.content[0]; + cartevitale.donneesAssure.type_de_carte_vitale = byte as char; + } + (101, 2) => { + cartevitale.donneesAssure.numero_de_serie = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 3) => { + cartevitale.donneesAssure.date_de_fin_de_validite = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 4) => { + println!("101.4 field.size: {:#?}", field.size); + let byte = field.content[0]; + cartevitale.donneesAssure.donnees_administration_ruf1 = byte as char; + } + (101, 5) => { + cartevitale.donneesAssure.donnees_administration_ruf2 = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 6) => { + cartevitale.donneesAssure.donnees_ruf_administration = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 7) => { + let byte = field.content[0]; + cartevitale.donneesAssure.type_d_identification_du_porteur = byte as char; + } + (101, 8) => { + cartevitale.donneesAssure.numero_national_d_immatriculation = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 9) => { + cartevitale.donneesAssure.cle_du_nir = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 10) => { + cartevitale.donneesAssure.code_regime = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 11) => { + cartevitale.donneesAssure.caisse_gestionnaire = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 12) => { + cartevitale.donneesAssure.centre_gestionnaire = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 13) => { + cartevitale.donneesAssure.code_gestion = + String::from_utf8_lossy(field.content).to_string(); + } + (101, 14) => { + cartevitale.donneesAssure.donnees_ruf_famille = + String::from_utf8_lossy(field.content).to_string(); + } + (102, 1) => { + cartevitale.serviceAMOFamille.code_service_amo_famille = + String::from_utf8_lossy(field.content).to_string(); + } + (102, 2) => { + cartevitale + .serviceAMOFamille + .date_de_debut_service_amo_famille = + String::from_utf8_lossy(field.content).to_string(); + } + (102, 3) => { + cartevitale + .serviceAMOFamille + .date_de_fin_service_amo_famille = + String::from_utf8_lossy(field.content).to_string(); + } + (103, 1) => { + cartevitale + .donneesAccidentTravail + .organisme_gestionnaire_risque_at = + String::from_utf8_lossy(field.content).to_string(); + } + (103, 2) => { + let byte = field.content[0]; + cartevitale.donneesAccidentTravail.code_at = byte as char; + } + (103, 3) => { + cartevitale.donneesAccidentTravail.identifiant_at = + String::from_utf8_lossy(field.content).to_string(); + } + (103, 4) => { + cartevitale + .donneesAccidentTravail + .organisme_gestionnaire_at1 = + String::from_utf8_lossy(field.content).to_string(); + } + (103, 5) => { + let byte = field.content[0]; + cartevitale.donneesAccidentTravail.code_at1 = byte as char; + } + (103, 6) => { + cartevitale.donneesAccidentTravail.identifiant_at1 = + String::from_utf8_lossy(field.content).to_string(); + } + (103, 7) => { + cartevitale + .donneesAccidentTravail + .organisme_gestionnaire_at2 = + String::from_utf8_lossy(field.content).to_string(); + } + (103, 8) => { + let byte = field.content[0]; + cartevitale.donneesAccidentTravail.code_at2 = byte as char; + } + (103, 9) => { + cartevitale.donneesAccidentTravail.identifiant_at2 = + String::from_utf8_lossy(field.content).to_string(); + } + _ => {} //{ + // return Err(format!( + // "Unknown (group, field) pair: ({}, {})", + // group.id, field.id + // )) + // } } - (101, 2) => { - cartevitale.donneesAssure.numero_de_serie = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 3) => { - cartevitale.donneesAssure.date_de_fin_de_validite = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 4) => { - let byte = field.content[0]; - cartevitale.donneesAssure.donnees_administration_ruf1 = byte as char; - } - (101, 5) => { - cartevitale.donneesAssure.donnees_administration_ruf2 = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 6) => { - cartevitale.donneesAssure.donnees_ruf_administration = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 7) => { - let byte = field.content[0]; - cartevitale.donneesAssure.type_d_identification_du_porteur = byte as char; - } - (101, 8) => { - cartevitale.donneesAssure.numero_national_d_immatriculation = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 9) => { - cartevitale.donneesAssure.cle_du_nir = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 10) => { - cartevitale.donneesAssure.code_regime = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 11) => { - cartevitale.donneesAssure.caisse_gestionnaire = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 12) => { - cartevitale.donneesAssure.centre_gestionnaire = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 13) => { - cartevitale.donneesAssure.code_gestion = - String::from_utf8_lossy(field.content).to_string(); - } - (101, 14) => { - cartevitale.donneesAssure.donnees_ruf_famille = - String::from_utf8_lossy(field.content).to_string(); - } - (102, 1) => { - cartevitale.serviceAMOFamille.code_service_amo_famille = - String::from_utf8_lossy(field.content).to_string(); - } - (102, 2) => { - cartevitale.serviceAMOFamille.date_de_debut_service_amo_famille = - String::from_utf8_lossy(field.content).to_string(); - } - (102, 3) => { - cartevitale.serviceAMOFamille.date_de_fin_service_amo_famille = - String::from_utf8_lossy(field.content).to_string(); - } - (103, 1) => { - cartevitale.donneesAccidentTravail.organisme_gestionnaire_risque_at = - String::from_utf8_lossy(field.content).to_string(); - } - (103, 2) => { - let byte = field.content[0]; - cartevitale.donneesAccidentTravail.code_at = byte as char; - } - (103, 3) => { - cartevitale.donneesAccidentTravail.identifiant_at = - String::from_utf8_lossy(field.content).to_string(); - } - (103, 4) => { - cartevitale.donneesAccidentTravail.organisme_gestionnaire_at1 = - String::from_utf8_lossy(field.content).to_string(); - } - (103, 5) => { - let byte = field.content[0]; - cartevitale.donneesAccidentTravail.code_at1 = byte as char; - } - (103, 6) => { - cartevitale.donneesAccidentTravail.identifiant_at1 = - String::from_utf8_lossy(field.content).to_string(); - } - (103, 7) => { - cartevitale.donneesAccidentTravail.organisme_gestionnaire_at2 = - String::from_utf8_lossy(field.content).to_string(); - } - (103, 8) => { - let byte = field.content[0]; - cartevitale.donneesAccidentTravail.code_at2 = byte as char; - } - (103, 9) => { - cartevitale.donneesAccidentTravail.identifiant_at2 = - String::from_utf8_lossy(field.content).to_string(); - } - _ =>{} //{ - // return Err(format!( - // "Unknown (group, field) pair: ({}, {})", - // group.id, field.id - // )) - // } } } } diff --git a/crates/sesam-vitale/src/main.rs b/crates/sesam-vitale/src/main.rs index b2319da..efcbff0 100644 --- a/crates/sesam-vitale/src/main.rs +++ b/crates/sesam-vitale/src/main.rs @@ -1,5 +1,5 @@ mod cps; -mod carteVitale; +mod cartevitale; mod libssv; mod ssv_memory; mod ssvlib_demo; diff --git a/crates/sesam-vitale/src/ssv_memory.rs b/crates/sesam-vitale/src/ssv_memory.rs index fba08af..cf77d8b 100644 --- a/crates/sesam-vitale/src/ssv_memory.rs +++ b/crates/sesam-vitale/src/ssv_memory.rs @@ -71,6 +71,8 @@ impl<'a> From<&'a [u8]> for Block<'a> { let mut field_id = 1; while field_offset < block_size { let mut field: Field<'a> = raw_content[field_offset..].into(); + + field.id = field_id; field_offset += field.size; field_id += 1; diff --git a/scripts/compile_win_headers - Copie.bat b/scripts/compile_win_headers - Copie.bat new file mode 100644 index 0000000..4dd44ef --- /dev/null +++ b/scripts/compile_win_headers - Copie.bat @@ -0,0 +1,26 @@ +@echo off +rem Set variables +set LIB_DIR=crates/sesam-vitale/lib +set DEF_DIR=crates/sesam-vitale/src/win/fsv + +if "%1"=="/clean" ( + goto clean +) + +rem Set the environment for the x64 platform +call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 + +rem Create a ssvw64.lib file from the ssvw64.def file +lib /def:ssvw64.def /out:%LIB_DIR%\ssvw64.lib /machine:x64 + +rem Build complete +pause +exit /b 0 + +:clean +del %LIB_DIR%\*.lib +del %LIB_DIR%\*.exp + +rem Clean complete +pause +exit /b 0 diff --git a/scripts/compile_win_headers.bat b/scripts/compile_win_headers.bat index 2bde361..47bd7cf 100644 --- a/scripts/compile_win_headers.bat +++ b/scripts/compile_win_headers.bat @@ -1,7 +1,7 @@ @echo off rem Set variables -set LIB_DIR=crates/sesam-vitale/lib -set DEF_DIR=crates/sesam-vitale/src/win/fsv +set LIB_DIR=F:\PAPILLON\Krys4lideCopie\crates\sesam-vitale\lib +set DEF_DIR=F:\PAPILLON\Krys4lideCopie\crates\sesam-vitale\src\win\fsv if "%1"=="/clean" ( goto clean diff --git a/scripts/ssvw64.def b/scripts/ssvw64.def new file mode 100644 index 0000000..e5358f7 --- /dev/null +++ b/scripts/ssvw64.def @@ -0,0 +1,6 @@ +LIBRARY "ssvw64" +EXPORTS + SSV_InitLIB2 + SSV_LireCartePS + SSV_LireConfig + SSV_LireDroitsVitale \ No newline at end of file