feat: add the structure to reprensent CPS fields returned by the lire_carte_ps function
This commit is contained in:
parent
f799f471bc
commit
d65c869949
@ -3,4 +3,5 @@ mod libssv;
|
||||
|
||||
fn main() {
|
||||
ssvlib_demo::demo();
|
||||
// XXX
|
||||
}
|
||||
|
@ -24,10 +24,88 @@ fn ssv_init_lib_2() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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)]
|
||||
struct CartePS {
|
||||
titulaire: TitulairePS,
|
||||
situations: Vec<SituationPS>,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
struct TitulairePS {
|
||||
type_de_carte_ps: String, // CN
|
||||
type_d_identification_nationale: String, // CN
|
||||
numero_d_identification_nationale: String, // CE - 8 -> 30
|
||||
cle_du_numero_d_identification_nationale: String, // CN
|
||||
code_civilite: String, // CN
|
||||
nom_du_ps: String, // CE - 27
|
||||
prenom_du_ps: String, // CE - 27
|
||||
categorie_carte: char, // CA
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SituationPS {
|
||||
numero_logique_de_la_situation_de_facturation_du_ps: u8,
|
||||
mode_d_exercice: String,
|
||||
statut_d_exercice: String,
|
||||
secteur_d_activite: String,
|
||||
type_d_identification_structure: String,
|
||||
numero_d_identification_structure: String,
|
||||
cle_du_numero_d_identification_structure: String,
|
||||
raison_sociale_structure: String,
|
||||
numero_d_identification_de_facturation_du_ps: String,
|
||||
cle_du_numero_d_identification_de_facturation_du_ps: String,
|
||||
numero_d_identification_du_ps_remplaçant: String,
|
||||
cle_du_numero_d_identification_du_ps_remplaçant: String,
|
||||
code_conventionnel: String,
|
||||
code_specialite: String,
|
||||
code_zone_tarifaire: String,
|
||||
code_zone_ik: String,
|
||||
code_agrement_1: String,
|
||||
code_agrement_2: String,
|
||||
code_agrement_3: String,
|
||||
habilitation_à_signer_une_facture: String,
|
||||
habilitation_à_signer_un_lot: String,
|
||||
}
|
||||
|
||||
impl Default for SituationPS {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
numero_logique_de_la_situation_de_facturation_du_ps: 0,
|
||||
mode_d_exercice: String::new(),
|
||||
statut_d_exercice: String::new(),
|
||||
secteur_d_activite: String::new(),
|
||||
type_d_identification_structure: String::new(),
|
||||
numero_d_identification_structure: String::new(),
|
||||
cle_du_numero_d_identification_structure: String::new(),
|
||||
raison_sociale_structure: String::new(),
|
||||
numero_d_identification_de_facturation_du_ps: String::new(),
|
||||
cle_du_numero_d_identification_de_facturation_du_ps: String::new(),
|
||||
numero_d_identification_du_ps_remplaçant: String::new(),
|
||||
cle_du_numero_d_identification_du_ps_remplaçant: String::new(),
|
||||
code_conventionnel: String::new(),
|
||||
code_specialite: String::new(),
|
||||
code_zone_tarifaire: String::new(),
|
||||
code_zone_ik: String::new(),
|
||||
code_agrement_1: String::new(),
|
||||
code_agrement_2: String::new(),
|
||||
code_agrement_3: String::new(),
|
||||
habilitation_à_signer_une_facture: String::new(),
|
||||
habilitation_à_signer_un_lot: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ssv_lire_carte_ps() {
|
||||
let resource_ps = CString::new("PS").expect("CString::new failed");
|
||||
let resource_reader = CString::new("TRANSPA1").expect("CString::new failed");
|
||||
let card_number = CString::new("1234567890").expect("CString::new failed");
|
||||
let resource_ps =
|
||||
CString::new("HID Global OMNIKEY 3x21 Smart Card Reader 0").expect("CString::new failed");
|
||||
let resource_reader = CString::new("").expect("CString::new failed");
|
||||
let card_number = CString::new("1234").expect("CString::new failed");
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
@ -44,11 +122,6 @@ fn ssv_lire_carte_ps() {
|
||||
|
||||
if !buffer.is_null() {
|
||||
hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
@ -57,14 +130,24 @@ fn ssv_lire_carte_ps() {
|
||||
|
||||
pub fn decode_zone_memoire(bytes: &[u8]) {
|
||||
// Maintenant, vous pouvez accéder aux octets individuels dans `donnees`
|
||||
for &octet in bytes {
|
||||
println!("Octet: {}", octet);
|
||||
}
|
||||
|
||||
let mut current_pos_general = 0;
|
||||
let mut current_groupe = 0;
|
||||
let mut num_champ = 0;
|
||||
|
||||
let mut carte_ps = CartePS {
|
||||
titulaire: TitulairePS {
|
||||
type_de_carte_ps: String::new(),
|
||||
type_d_identification_nationale: String::new(),
|
||||
numero_d_identification_nationale: String::new(),
|
||||
cle_du_numero_d_identification_nationale: String::new(),
|
||||
code_civilite: String::new(),
|
||||
nom_du_ps: String::new(),
|
||||
prenom_du_ps: String::new(),
|
||||
categorie_carte: ' ',
|
||||
},
|
||||
situations: Vec::new(),
|
||||
};
|
||||
|
||||
while current_pos_general < bytes.len() - 1 {
|
||||
num_champ = 0;
|
||||
current_groupe =
|
||||
@ -109,25 +192,160 @@ pub fn decode_zone_memoire(bytes: &[u8]) {
|
||||
|
||||
match current_groupe {
|
||||
1 => match num_champ {
|
||||
1 => println!("Groupe1.Champ1: {}", String::from_utf8_lossy(&bytes_champ)),
|
||||
2 => println!("Groupe1.Champ2: {}", String::from_utf8_lossy(&bytes_champ)),
|
||||
3 => println!("Groupe1.Champ3: {}", String::from_utf8_lossy(&bytes_champ)),
|
||||
4 => println!("Groupe1.Champ4: {}", String::from_utf8_lossy(&bytes_champ)),
|
||||
5 => println!("Groupe1.Champ5: {}", String::from_utf8_lossy(&bytes_champ)),
|
||||
6 => println!("Groupe1.Champ6: {}", String::from_utf8_lossy(&bytes_champ)),
|
||||
7 => println!("Groupe1.Champ7: {}", String::from_utf8_lossy(&bytes_champ)),
|
||||
8 => println!("Groupe1.Champ8: {}", String::from_utf8_lossy(&bytes_champ)),
|
||||
1 => {
|
||||
carte_ps.titulaire.type_de_carte_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
2 => {
|
||||
carte_ps.titulaire.type_d_identification_nationale =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
3 => {
|
||||
carte_ps.titulaire.numero_d_identification_nationale =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
4 => {
|
||||
carte_ps.titulaire.cle_du_numero_d_identification_nationale =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
5 => {
|
||||
carte_ps.titulaire.code_civilite =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
6 => {
|
||||
carte_ps.titulaire.nom_du_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
7 => {
|
||||
carte_ps.titulaire.prenom_du_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
8 => {
|
||||
carte_ps.titulaire.categorie_carte = bytes_champ[0] as char;
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
2 => match num_champ {
|
||||
1 => {
|
||||
// Ajoutez votre logique pour Groupe2 ici
|
||||
carte_ps.situations.push(SituationPS::default());
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.numero_logique_de_la_situation_de_facturation_du_ps =
|
||||
bytes_champ[0];
|
||||
}
|
||||
2 => {
|
||||
// Ajoutez votre logique pour Groupe2 ici
|
||||
carte_ps.situations.last_mut().unwrap().mode_d_exercice =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
3 => {
|
||||
// Ajoutez votre logique pour Groupe2 ici
|
||||
carte_ps.situations.last_mut().unwrap().statut_d_exercice =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
4 => {
|
||||
carte_ps.situations.last_mut().unwrap().secteur_d_activite =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
5 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.type_d_identification_structure =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
6 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.numero_d_identification_structure =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
7 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.cle_du_numero_d_identification_structure =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
8 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.raison_sociale_structure =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
9 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.numero_d_identification_de_facturation_du_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
10 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.cle_du_numero_d_identification_de_facturation_du_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
11 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.numero_d_identification_du_ps_remplaçant =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
12 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.cle_du_numero_d_identification_du_ps_remplaçant =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
13 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_conventionnel =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
14 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_specialite =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
15 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_zone_tarifaire =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
16 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_zone_ik =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
17 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_agrement_1 =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
18 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_agrement_2 =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
19 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_agrement_3 =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
20 => {
|
||||
carte_ps.situations.last_mut().unwrap().habilitation_à_signer_une_facture =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
21 => {
|
||||
carte_ps.situations.last_mut().unwrap().habilitation_à_signer_un_lot =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
@ -139,6 +357,8 @@ pub fn decode_zone_memoire(bytes: &[u8]) {
|
||||
current_pos_groupe += longueur_champs + nbre_octets_longueur;
|
||||
}
|
||||
}
|
||||
|
||||
println!("CartePS: {:#?}", carte_ps);
|
||||
}
|
||||
|
||||
fn ssv_lire_config() {
|
||||
@ -173,7 +393,7 @@ pub fn demo() {
|
||||
|
||||
ssv_init_lib_2();
|
||||
ssv_lire_carte_ps();
|
||||
ssv_lire_config();
|
||||
// ssv_lire_config();
|
||||
|
||||
println!("-----------------------------------------");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user