feat: define structure
This commit is contained in:
parent
d68fcabb96
commit
338c6737e9
182
Cargo.lock
generated
182
Cargo.lock
generated
@ -74,6 +74,55 @@ dependencies = [
|
|||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "0.6.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-parse"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
|
||||||
|
dependencies = [
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-query"
|
||||||
|
version = "1.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.86"
|
version = "1.0.86"
|
||||||
@ -464,6 +513,18 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitvec"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
|
||||||
|
dependencies = [
|
||||||
|
"funty",
|
||||||
|
"radium",
|
||||||
|
"tap",
|
||||||
|
"wyz",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "block"
|
name = "block"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
@ -780,6 +841,12 @@ dependencies = [
|
|||||||
"objc",
|
"objc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "combine"
|
name = "combine"
|
||||||
version = "4.6.7"
|
version = "4.6.7"
|
||||||
@ -1018,6 +1085,31 @@ dependencies = [
|
|||||||
"syn 2.0.72",
|
"syn 2.0.72",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deku"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "709ade444d53896e60f6265660eb50480dd08b77bfc822e5dcc233b88b0b2fba"
|
||||||
|
dependencies = [
|
||||||
|
"bitvec",
|
||||||
|
"deku_derive",
|
||||||
|
"no_std_io",
|
||||||
|
"rustversion",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deku_derive"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d7534973f93f9de83203e41c8ddd32d230599fa73fa889f3deb1580ccd186913"
|
||||||
|
dependencies = [
|
||||||
|
"darling 0.20.10",
|
||||||
|
"proc-macro-crate 3.1.0",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.72",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deranged"
|
name = "deranged"
|
||||||
version = "0.3.11"
|
version = "0.3.11"
|
||||||
@ -1304,6 +1396,29 @@ dependencies = [
|
|||||||
"syn 2.0.72",
|
"syn 2.0.72",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_filter"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_logger"
|
||||||
|
version = "0.11.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"env_filter",
|
||||||
|
"humantime",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@ -1484,6 +1599,12 @@ version = "0.3.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "funty"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futf"
|
name = "futf"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@ -2049,6 +2170,12 @@ dependencies = [
|
|||||||
"libm",
|
"libm",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humantime"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "1.4.1"
|
version = "1.4.1"
|
||||||
@ -2224,6 +2351,12 @@ version = "2.9.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
|
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "0.4.8"
|
version = "0.4.8"
|
||||||
@ -2772,6 +2905,15 @@ dependencies = [
|
|||||||
"memoffset 0.9.1",
|
"memoffset 0.9.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "no_std_io"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7fa5f306a6f2c01b4fd172f29bb46195b1764061bf926c75e96ff55df3178208"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nodrop"
|
name = "nodrop"
|
||||||
version = "0.1.14"
|
version = "0.1.14"
|
||||||
@ -3476,6 +3618,12 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "radium"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.7.3"
|
version = "0.7.3"
|
||||||
@ -3942,6 +4090,16 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "services-sesam-vitale-sys"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bitvec",
|
||||||
|
"deku",
|
||||||
|
"libc",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servo_arc"
|
name = "servo_arc"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -3957,8 +4115,11 @@ name = "sesam-vitale"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"deku",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
|
"env_logger",
|
||||||
"libc",
|
"libc",
|
||||||
|
"services-sesam-vitale-sys",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"utils",
|
"utils",
|
||||||
]
|
]
|
||||||
@ -4311,6 +4472,12 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tap"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "target-lexicon"
|
name = "target-lexicon"
|
||||||
version = "0.12.15"
|
version = "0.12.15"
|
||||||
@ -5078,6 +5245,12 @@ version = "0.7.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utils"
|
name = "utils"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -5854,6 +6027,15 @@ dependencies = [
|
|||||||
"winapi-build",
|
"winapi-build",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wyz"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
|
||||||
|
dependencies = [
|
||||||
|
"tap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "x11"
|
name = "x11"
|
||||||
version = "2.21.0"
|
version = "2.21.0"
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
name = "services-sesam-vitale-sys"
|
name = "services-sesam-vitale-sys"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
#links= "ssvlux64"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitvec = "1.0.1"
|
bitvec = "1.0.1"
|
||||||
deku = "0.17.0"
|
deku = "0.17.0"
|
||||||
libc = "0.2.155"
|
libc = "0.2.155"
|
||||||
|
thiserror = "1.0.63"
|
||||||
|
66
crates/services-sesam-vitale-sys/src/api.rs
Normal file
66
crates/services-sesam-vitale-sys/src/api.rs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
use thiserror::Error;
|
||||||
|
use std::{ffi::CString, fmt, path::Path, ptr};
|
||||||
|
|
||||||
|
use crate::{bindings::{SSV_InitLIB2, SSV_TermLIB}, types::{common::read_from_buffer, configuration::Configuration}};
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
pub struct SesamVitaleError {
|
||||||
|
code: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for SesamVitaleError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "Got error code {} from SSV_LireConfig", self.code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_library(sesam_ini_path: &Path) -> Result<(), SesamVitaleError> {
|
||||||
|
// TODO: better error handling
|
||||||
|
let path_str = sesam_ini_path.to_str().unwrap();
|
||||||
|
let path_ptr = CString::new(path_str).expect("failed to create cstring");
|
||||||
|
|
||||||
|
let exit_code: u16 = unsafe { SSV_InitLIB2(path_ptr.as_ptr()) };
|
||||||
|
if exit_code != 0 {
|
||||||
|
let error = SesamVitaleError { code: exit_code };
|
||||||
|
return Err(error);
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
pub fn close_library() -> Result<(), SesamVitaleError> {
|
||||||
|
let exit_code: u16 = unsafe { SSV_TermLIB() };
|
||||||
|
if exit_code != 0 {
|
||||||
|
let error = SesamVitaleError { code: exit_code };
|
||||||
|
return Err(error);
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_config() -> Result<Configuration, SesamVitaleError> {
|
||||||
|
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
|
||||||
|
let mut size: libc::size_t = 0;
|
||||||
|
|
||||||
|
let buffer_ptr_ptr: *mut *mut libc::c_void = &mut buffer_ptr;
|
||||||
|
let size_ptr: *mut libc::size_t = &mut size;
|
||||||
|
|
||||||
|
// Need to add proper error handling -> return a result with error code pointing to an error
|
||||||
|
// enum
|
||||||
|
let exit_code: u16 = unsafe { SSV_LireConfig(buffer_ptr_ptr, size_ptr) };
|
||||||
|
|
||||||
|
if exit_code != 0 {
|
||||||
|
let error = SesamVitaleError { code: exit_code };
|
||||||
|
return Err(error);
|
||||||
|
};
|
||||||
|
|
||||||
|
let buffer: &[u8] = unsafe { std::slice::from_raw_parts(buffer_ptr as *const u8, size) };
|
||||||
|
|
||||||
|
// TODO: Improve error handling
|
||||||
|
let configuration: Configuration = read_from_buffer(buffer).unwrap();
|
||||||
|
|
||||||
|
// TODO: Call library function for memory delocating
|
||||||
|
unsafe { libc::free(buffer_ptr) };
|
||||||
|
|
||||||
|
Ok(configuration)
|
||||||
|
}
|
||||||
|
|
@ -1,70 +1,6 @@
|
|||||||
|
pub mod api;
|
||||||
mod bindings;
|
mod bindings;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
use bindings::{SSV_InitLIB2, SSV_LireConfig, SSV_TermLIB};
|
|
||||||
use std::{ffi::CString, fmt, path::Path, ptr};
|
|
||||||
use types::serialization_types::{read_from_buffer, Configuration};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct SesamVitaleError {
|
|
||||||
code: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for SesamVitaleError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "Got error code {} from SSV_LireConfig", self.code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_library(sesam_ini_path: &Path) -> Result<(), SesamVitaleError> {
|
|
||||||
// TODO: better error handling
|
|
||||||
let path_str = sesam_ini_path.to_str().unwrap();
|
|
||||||
let path_ptr = CString::new(path_str).expect("failed to create cstring");
|
|
||||||
|
|
||||||
let exit_code: u16 = unsafe { SSV_InitLIB2(path_ptr.as_ptr()) };
|
|
||||||
if exit_code != 0 {
|
|
||||||
let error = SesamVitaleError { code: exit_code };
|
|
||||||
return Err(error);
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
pub fn close_library() -> Result<(), SesamVitaleError> {
|
|
||||||
let exit_code: u16 = unsafe { SSV_TermLIB() };
|
|
||||||
if exit_code != 0 {
|
|
||||||
let error = SesamVitaleError { code: exit_code };
|
|
||||||
return Err(error);
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_config() -> Result<Configuration, SesamVitaleError> {
|
|
||||||
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
|
|
||||||
let mut size: libc::size_t = 0;
|
|
||||||
|
|
||||||
let buffer_ptr_ptr: *mut *mut libc::c_void = &mut buffer_ptr;
|
|
||||||
let size_ptr: *mut libc::size_t = &mut size;
|
|
||||||
|
|
||||||
// Need to add proper error handling -> return a result with error code pointing to an error
|
|
||||||
// enum
|
|
||||||
let exit_code: u16 = unsafe { SSV_LireConfig(buffer_ptr_ptr, size_ptr) };
|
|
||||||
|
|
||||||
if exit_code != 0 {
|
|
||||||
let error = SesamVitaleError { code: exit_code };
|
|
||||||
return Err(error);
|
|
||||||
};
|
|
||||||
|
|
||||||
let buffer: &[u8] = unsafe { std::slice::from_raw_parts(buffer_ptr as *const u8, size) };
|
|
||||||
|
|
||||||
// TODO: Improve error handling
|
|
||||||
let configuration: Configuration = read_from_buffer(buffer).unwrap();
|
|
||||||
|
|
||||||
// TODO: Call library function for memory delocating
|
|
||||||
unsafe { libc::free(buffer_ptr) };
|
|
||||||
|
|
||||||
Ok(configuration)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {}
|
mod tests {}
|
||||||
|
@ -1,264 +1,144 @@
|
|||||||
pub struct Identification<T> {
|
use crate::types::configuration::{
|
||||||
value: T,
|
ConfigurationHeader, PCSCReader, ReaderConfiguration, SESAMVitaleComponent,
|
||||||
// Key to check the validity of the value
|
};
|
||||||
// TODO: implement checking algorithm
|
|
||||||
key: u8,
|
use std::{error::Error, str::FromStr};
|
||||||
|
|
||||||
|
use bitvec::index::BitIdx;
|
||||||
|
use deku::{
|
||||||
|
bitvec::{BitStore, Msb0},
|
||||||
|
ctx::ByteSize,
|
||||||
|
deku_derive,
|
||||||
|
reader::{Reader, ReaderRet},
|
||||||
|
DekuContainerRead, DekuError, DekuReader,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub(crate) struct NumericString(#[deku(map = "convert_from_data_field")] String);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub(crate) struct AlphaNumericString(#[deku(map = "convert_from_data_field")] String);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub(crate) struct BinaryData(#[deku(map = "extract_from_data_field")] Vec<u8>);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
#[deku(endian = "big")]
|
||||||
|
pub(crate) struct GroupId(u16);
|
||||||
|
|
||||||
|
trait MapToDekuParseError<T> {
|
||||||
|
fn map_to_deku_parse_error(self) -> Result<T, DekuError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Byte = u8;
|
impl<T, E: Error> MapToDekuParseError<T> for Result<T, E> {
|
||||||
|
fn map_to_deku_parse_error(self) -> Result<T, DekuError> {
|
||||||
pub(crate) enum IdentificationNationale {
|
self.map_err(|e| DekuError::Parse(e.to_string().into()))
|
||||||
NumeroAdeli(String),
|
}
|
||||||
NumeroEmployeeDansStructure(IdentificationStructure, String),
|
|
||||||
NumeroDRASS(String),
|
|
||||||
NumeroRPPS(String),
|
|
||||||
/// N° Etudiant Médecin type ADELI sur 9 caractères (information transmise par l’ANS)
|
|
||||||
NumeroEtudiantMedecin(String),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum TypeCarteProfessionnelSante {
|
fn read_size<R: std::io::Read>(reader: &mut Reader<R>) -> Result<ByteSize, DekuError> {
|
||||||
/// Carte de Professionnel de Santé (CPS)
|
let first_byte: u8 = u8::from_reader_with_ctx(reader, ())?;
|
||||||
CarteDeProfessionnelSante,
|
|
||||||
/// Carte de Professionnel de Santé en Formation (CPF)
|
let is_length_expanded = first_byte.get_bit::<Msb0>(BitIdx::new(0).map_to_deku_parse_error()?);
|
||||||
CarteDeProfessionnelSanteEnFormation,
|
|
||||||
/// Carte de Personnel d'Établissement de Santé (CDE/CPE)
|
match is_length_expanded {
|
||||||
CarteDePersonnelEtablissementSante,
|
true => {
|
||||||
/// Carte de Personnel Autorisé (CDA/CPA)
|
let size_of_data_size: ByteSize = ByteSize((first_byte & 0b0111_1111) as usize);
|
||||||
CarteDePersonnelAutorise,
|
|
||||||
/// Carte de Personne Morale
|
if size_of_data_size.0 > 4 {
|
||||||
CarteDePersonneMorale,
|
return Err(DekuError::Parse("Size of the length encoding is > 4, this is not normal. Probable parsing error".to_string().into()));
|
||||||
|
};
|
||||||
|
|
||||||
|
// maximum size of the buffer is 4, we use the offset to read values less than 4 bytes
|
||||||
|
let buffer: &mut [u8; 4] = &mut [0; 4];
|
||||||
|
let write_offset = 4 - size_of_data_size.0;
|
||||||
|
|
||||||
|
match reader.read_bytes(size_of_data_size.0, &mut buffer[write_offset..])? {
|
||||||
|
ReaderRet::Bits(_bit_vec) => Err(DekuError::Parse("Got bits when trying to read bytes -> reader is unaligned, this is not normal.".to_string().into())),
|
||||||
|
ReaderRet::Bytes => Ok(ByteSize(u32::from_be_bytes(*buffer) as usize)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false => Ok(ByteSize(first_byte as usize)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum CategorieCarteProfessionnelSante {
|
// Using this as the map function asks deku to parse a datafield
|
||||||
Reelle,
|
// We then use the datafield and convert it to the corresponding value
|
||||||
Test,
|
pub(super) fn convert_from_data_field<T>(data_field: DataField) -> Result<T, DekuError>
|
||||||
Demonstration,
|
where
|
||||||
|
T: FromStr,
|
||||||
|
T::Err: Error,
|
||||||
|
{
|
||||||
|
let text = String::from_utf8(data_field.data).map_to_deku_parse_error()?;
|
||||||
|
T::from_str(&text).map_to_deku_parse_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum CodeCivilite {
|
pub(crate) fn extract_from_data_field(data_field: DataField) -> Result<Vec<u8>, DekuError> {
|
||||||
Adjudant,
|
Ok(data_field.data)
|
||||||
Amiral,
|
|
||||||
Aspirant,
|
|
||||||
Aumônier,
|
|
||||||
Capitaine,
|
|
||||||
Cardinal,
|
|
||||||
Chanoine,
|
|
||||||
Colonel,
|
|
||||||
Commandant,
|
|
||||||
Commissaire,
|
|
||||||
Conseiller,
|
|
||||||
Directeur,
|
|
||||||
Docteur,
|
|
||||||
Douanier,
|
|
||||||
Epouxse, // Epoux(se)
|
|
||||||
Evêque,
|
|
||||||
Général,
|
|
||||||
Gouverneur,
|
|
||||||
Ingénieur,
|
|
||||||
Inspecteur,
|
|
||||||
Lieutenant,
|
|
||||||
Madame,
|
|
||||||
Mademoiselle,
|
|
||||||
Maître,
|
|
||||||
Maréchal,
|
|
||||||
Médecin,
|
|
||||||
Mesdames,
|
|
||||||
Mesdemoiselles,
|
|
||||||
Messieurs,
|
|
||||||
Monseigneur,
|
|
||||||
Monsieur,
|
|
||||||
NotreDame,
|
|
||||||
Pasteur,
|
|
||||||
Préfet,
|
|
||||||
Président,
|
|
||||||
Professeur,
|
|
||||||
Recteur,
|
|
||||||
Sergent,
|
|
||||||
SousPréfet,
|
|
||||||
Technicien,
|
|
||||||
Veuve,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum IdentificationStructure {
|
#[deku_derive(DekuRead)]
|
||||||
NumeroAdeliCabinet(String),
|
#[derive(Debug, PartialEq)]
|
||||||
NumeroFINESS(String),
|
pub(crate) struct DataField {
|
||||||
NumeroSIREN(String),
|
#[deku(reader = "read_size(deku::reader)")]
|
||||||
NumeroSIRET(String),
|
pub(crate) data_size: ByteSize,
|
||||||
NumeroRPPSCabinet(String),
|
|
||||||
|
#[deku(bytes_read = "data_size.0")]
|
||||||
|
pub(crate) data: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum ModeExercice {
|
#[deku_derive(DekuRead)]
|
||||||
LiberalExploitantCommercant, // Libéral, exploitant, commerçant
|
#[derive(Debug, PartialEq)]
|
||||||
Salarie,
|
pub(crate) struct BlockHeader {
|
||||||
Remplacant,
|
pub(crate) group_id: GroupId,
|
||||||
Benevole,
|
|
||||||
|
#[deku(reader = "read_size(deku::reader)")]
|
||||||
|
pub(crate) data_size: ByteSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum StatutExercice {
|
#[deku_derive(DekuRead)]
|
||||||
// TAB-Statuts géré par l’ANS il faut trouver la donnee
|
#[derive(Debug, PartialEq)]
|
||||||
PLACEHOLDER(u8),
|
pub(crate) struct DataBlock {
|
||||||
|
pub(crate) header: BlockHeader,
|
||||||
|
|
||||||
|
#[deku(ctx = "header.group_id")]
|
||||||
|
pub(crate) inner: DataGroup,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum SecteurActivite {
|
#[deku_derive(DekuRead)]
|
||||||
EtablissementPublicDeSanté,
|
#[derive(Debug, PartialEq)]
|
||||||
HopitauxMilitaires,
|
#[deku(ctx = "group_id: GroupId", id = "group_id.0")]
|
||||||
EtablissementPrivePSPH, // Participant au Service Public Hospitalier
|
pub enum DataGroup {
|
||||||
EtablissementPriveNonPSPH,
|
#[deku(id = 60)]
|
||||||
DispensaireDeSoins,
|
ConfigurationHeader(ConfigurationHeader),
|
||||||
AutresStructuresDeSoinsRelevantDuServiceDeSanteDesArmees,
|
#[deku(id = 61)]
|
||||||
CabinetIndividuel,
|
ReaderConfiguration(ReaderConfiguration),
|
||||||
CabinetDeGroupe,
|
#[deku(id = 64)]
|
||||||
ExerciceEnSociete,
|
SESAMVitaleComponent(SESAMVitaleComponent),
|
||||||
SecteurPrivePHTempsPlein,
|
#[deku(id = 67)]
|
||||||
TransportSanitaire,
|
PCSCReader(PCSCReader),
|
||||||
EntrepriseDInterim,
|
}
|
||||||
EtablissementDeSoinsEtPrevention,
|
pub(crate) fn read_from_buffer<T>(buffer: &[u8]) -> Result<T, T::Error>
|
||||||
PreventionEtSoinsEnEntreprise,
|
where
|
||||||
SanteScolaireEtUniversitaire,
|
T: TryFrom<Vec<DataBlock>>,
|
||||||
RecrutementEtGestionRH,
|
{
|
||||||
PMIPlanificationFamiliale,
|
let mut data_blocks: Vec<DataBlock> = Vec::new();
|
||||||
EtablissementPourHandicapes,
|
let mut offset = 0;
|
||||||
ComMarketingConsultingMedia,
|
|
||||||
EtablissementPersonnesAgees,
|
let mut remaining_buffer = buffer;
|
||||||
EtablissementAideaLaFamille,
|
|
||||||
EtablissementDEnseignement,
|
while !remaining_buffer.is_empty() {
|
||||||
EtablissementsDeProtectionDeLEnfance,
|
// TODO: properly handle errors
|
||||||
EtablissementsDHebergementEtDeReadaptation,
|
let (rest, data_block) = DataBlock::from_bytes((remaining_buffer, offset)).unwrap();
|
||||||
Recherche,
|
|
||||||
AssurancePrivee,
|
data_blocks.push(data_block);
|
||||||
OrganismeDeSecuriteSociale,
|
|
||||||
MinistèreEtServicesDeconcentres,
|
(remaining_buffer, offset) = rest;
|
||||||
CollectivitesTerritoriales,
|
|
||||||
AssociationsEtOrganitationsHumanitaire,
|
|
||||||
LaboratoireDeBiologieMedicale,
|
|
||||||
AutreEtablissementSanitaire,
|
|
||||||
ProductionCommercialisationGrosBienMedicaux,
|
|
||||||
CommerceDétailDeBiensMédicaux,
|
|
||||||
PharmacieDOfficine,
|
|
||||||
CentreDeDialyse,
|
|
||||||
ParaPharmacie,
|
|
||||||
AutreSecteurDActivité,
|
|
||||||
SecteurNonDefini,
|
|
||||||
CentreAntiCancer,
|
|
||||||
CentreDeTransfusionSanguine,
|
|
||||||
RépartitionDistribributionFabricationExploitationImportationMedicamentsEtDispositifsMédicaux,
|
|
||||||
IncendiesEtSecours,
|
|
||||||
EntreprisesIndustriellesEtTertiairesHorsIndustriesPharmaceutiques,
|
|
||||||
EntiteDUnTOM,
|
|
||||||
FabricationExploitationImportationMedicamentsEtDispositifsMedicaux,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) type IdentificationFacturation = u32;
|
T::try_from(data_blocks)
|
||||||
pub(crate) enum CodeConventionnel {
|
|
||||||
NonConventionne,
|
|
||||||
Conventionne,
|
|
||||||
ConventionneAvecDepassement,
|
|
||||||
ConventionneAvecHonorairesLibres,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Code spécialité ou Code spécialité de l'exécutant
|
|
||||||
pub(crate) enum CodeSpecialite {
|
|
||||||
MedecineGenerale,
|
|
||||||
AnesthesieReanimation,
|
|
||||||
Cardiologie,
|
|
||||||
ChirurgieGenerale,
|
|
||||||
DermatologieEtVenerologie,
|
|
||||||
Radiologie,
|
|
||||||
GynecologieObstetrique,
|
|
||||||
GastroEnterologieEtHepatologie,
|
|
||||||
MedecineInterne,
|
|
||||||
NeuroChirurgie,
|
|
||||||
OtoRhinoLaryngologie,
|
|
||||||
Pediatrie,
|
|
||||||
Pneumologie,
|
|
||||||
Rhumatologie,
|
|
||||||
Ophtalmologie,
|
|
||||||
ChirurgieUrologique,
|
|
||||||
NeuroPsychiatrie,
|
|
||||||
Stomatologie,
|
|
||||||
ChirurgienDentiste,
|
|
||||||
ReanimationMedicale,
|
|
||||||
SageFemme,
|
|
||||||
SpecialisteEnMedecineGeneraleAvecDiplome,
|
|
||||||
SpecialisteEnMedecineGeneraleReconnuParLOrdre,
|
|
||||||
Infirmier,
|
|
||||||
Psychologue,
|
|
||||||
MasseurKinesitherapeute,
|
|
||||||
PedicurePodologue,
|
|
||||||
Orthophoniste,
|
|
||||||
Orthoptiste,
|
|
||||||
LaboratoireDAnalysesMedicales,
|
|
||||||
ReeducationReadaptationFonctionnelle,
|
|
||||||
Neurologie,
|
|
||||||
Psychiatrie,
|
|
||||||
Geriatrie,
|
|
||||||
Nephrologie,
|
|
||||||
ChirurgieDentaireSpecialiteODF,
|
|
||||||
AnatomoCytoPathologie,
|
|
||||||
MedecinBiologiste,
|
|
||||||
LaboratoirePolyvalent,
|
|
||||||
LaboratoireDAnatomoCytoPathologique,
|
|
||||||
ChirurgieOrthopediqueEtTraumatologie,
|
|
||||||
EndocrinologieEtMetabolisme,
|
|
||||||
ChirurgieInfantile,
|
|
||||||
ChirurgieMaxilloFaciale,
|
|
||||||
ChirurgieMaxilloFacialeEtStomatologie,
|
|
||||||
ChirurgiePlastiqueReconstructriceEtEsthetique,
|
|
||||||
ChirurgieThoraciqueEtCardioVasculaire,
|
|
||||||
ChirurgieVasculaire,
|
|
||||||
ChirurgieVisceraleEtDigestive,
|
|
||||||
PharmacieDOfficine,
|
|
||||||
PharmacieMutualiste,
|
|
||||||
ChirurgienDentisteSpecialiteCO,
|
|
||||||
ChirurgienDentisteSpecialiteMBD,
|
|
||||||
PrestataireDeTypeSociete,
|
|
||||||
PrestataireArtisan,
|
|
||||||
PrestataireDeTypeAssociation,
|
|
||||||
Orthesiste,
|
|
||||||
Opticien,
|
|
||||||
Audioprothesiste,
|
|
||||||
ÉpithesisteOculariste,
|
|
||||||
PodoOrthesiste,
|
|
||||||
Orthoprothesiste,
|
|
||||||
ChirurgieOrale,
|
|
||||||
GynecologieMedicale,
|
|
||||||
Hematologie,
|
|
||||||
MedecineNucleaire,
|
|
||||||
OncologieMedicale,
|
|
||||||
OncologieRadiotherapique,
|
|
||||||
PsychiatrieDeLEnfantEtDeLAdolescent,
|
|
||||||
Radiotherapie,
|
|
||||||
Obstetrique,
|
|
||||||
GenetiqueMedicale,
|
|
||||||
ObstetriqueEtGynecologieMedicale,
|
|
||||||
SantePubliqueEtMedecineSociale,
|
|
||||||
MedecineDesMaladiesInfectieusesEtTropicales,
|
|
||||||
MedecineLegaleEtExpertisesMedicales,
|
|
||||||
MedecineDUrgence,
|
|
||||||
MedecineVasculaire,
|
|
||||||
Allergologie,
|
|
||||||
InfirmierExercantEnPratiquesAvancees, // IPA
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Page 54 dictionnaires des donnees
|
|
||||||
/// donnees inutilises pour les pharmacies
|
|
||||||
pub(crate) enum CodeZoneTarifaire {}
|
|
||||||
|
|
||||||
pub(crate) enum CodeZoneIK {
|
|
||||||
PasIndemniteKilometrique,
|
|
||||||
IndemnitesKilometriquesPlaine,
|
|
||||||
IndemnitesKilometriquesMontagne,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) enum CodeAgrement {
|
|
||||||
PasDAgrementRadio,
|
|
||||||
/// Agrément D ou agrément DDASS
|
|
||||||
AgrementDDASS,
|
|
||||||
/// Agrément A, B, C, E et F
|
|
||||||
AgrementABCEF,
|
|
||||||
/// Agrément G, H et J
|
|
||||||
AgrementGHJ,
|
|
||||||
AgrementK,
|
|
||||||
AgrementL,
|
|
||||||
AgrementM,
|
|
||||||
}
|
}
|
||||||
|
137
crates/services-sesam-vitale-sys/src/types/configuration.rs
Normal file
137
crates/services-sesam-vitale-sys/src/types/configuration.rs
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
use crate::types::common::DataBlock;
|
||||||
|
use std::{error::Error, fmt, vec::Vec};
|
||||||
|
|
||||||
|
use crate::types::common::convert_from_data_field;
|
||||||
|
use deku::{deku_derive, DekuReader};
|
||||||
|
|
||||||
|
use super::common::{AlphaNumericString, DataGroup};
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct SSVVersionNumber(#[deku(map = "convert_from_data_field")] u16);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct GALSSVersionNumber(#[deku(map = "convert_from_data_field")] u16);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct PSSVersionNumber(#[deku(map = "convert_from_data_field")] u16);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct ConfigurationHeader {
|
||||||
|
pub ssv_version: SSVVersionNumber,
|
||||||
|
pub galss_version: GALSSVersionNumber,
|
||||||
|
pub pss_version: PSSVersionNumber,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct PCSCReaderName(AlphaNumericString);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct CardType(#[deku(map = "convert_from_data_field")] u8);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct PCSCReader {
|
||||||
|
pub name: PCSCReaderName,
|
||||||
|
pub card_type: CardType,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct SESAMVitaleComponentID(#[deku(map = "convert_from_data_field")] u16);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct SESAMVitaleComponentDescription(AlphaNumericString);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct SESAMVitaleComponentVersion(AlphaNumericString);
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct SESAMVitaleComponent {
|
||||||
|
pub id: SESAMVitaleComponentID,
|
||||||
|
pub description: SESAMVitaleComponentDescription,
|
||||||
|
pub version: SESAMVitaleComponentVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deku_derive(DekuRead)]
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct ReaderConfiguration {}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum ConfigurationError {
|
||||||
|
MultipleConfigurationHeaders,
|
||||||
|
MissingConfigurationHeader,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ConfigurationError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
ConfigurationError::MultipleConfigurationHeaders => {
|
||||||
|
write!(f, "Multiple ConfigurationHeader blocks found")
|
||||||
|
}
|
||||||
|
ConfigurationError::MissingConfigurationHeader => {
|
||||||
|
write!(f, "Missing ConfigurationHeader block")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for ConfigurationError {}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Configuration {
|
||||||
|
pub configuration_header: ConfigurationHeader,
|
||||||
|
pub reader_configurations: Vec<ReaderConfiguration>,
|
||||||
|
pub sesam_vitale_components: Vec<SESAMVitaleComponent>,
|
||||||
|
pub pcsc_readers: Vec<PCSCReader>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<Vec<DataBlock>> for Configuration {
|
||||||
|
type Error = ConfigurationError;
|
||||||
|
|
||||||
|
fn try_from(data_blocks: Vec<DataBlock>) -> Result<Self, Self::Error> {
|
||||||
|
let mut configuration_header: Option<ConfigurationHeader> = None;
|
||||||
|
let mut reader_configurations: Vec<ReaderConfiguration> = Vec::new();
|
||||||
|
let mut sesam_vitale_components: Vec<SESAMVitaleComponent> = Vec::new();
|
||||||
|
let mut pcsc_readers: Vec<PCSCReader> = Vec::new();
|
||||||
|
|
||||||
|
for block in data_blocks {
|
||||||
|
match block.inner {
|
||||||
|
DataGroup::ConfigurationHeader(header) => {
|
||||||
|
if configuration_header.is_some() {
|
||||||
|
return Err(ConfigurationError::MultipleConfigurationHeaders);
|
||||||
|
}
|
||||||
|
configuration_header = Some(header);
|
||||||
|
}
|
||||||
|
DataGroup::ReaderConfiguration(configuration) => {
|
||||||
|
reader_configurations.push(configuration)
|
||||||
|
}
|
||||||
|
DataGroup::SESAMVitaleComponent(component) => {
|
||||||
|
sesam_vitale_components.push(component);
|
||||||
|
}
|
||||||
|
DataGroup::PCSCReader(reader) => {
|
||||||
|
pcsc_readers.push(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let configuration_header = match configuration_header {
|
||||||
|
Some(header) => header,
|
||||||
|
None => return Err(ConfigurationError::MissingConfigurationHeader),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
configuration_header,
|
||||||
|
reader_configurations,
|
||||||
|
sesam_vitale_components,
|
||||||
|
pcsc_readers,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1,3 @@
|
|||||||
pub mod serialization_types;
|
pub mod common;
|
||||||
|
pub mod configuration;
|
||||||
|
pub mod droits_vitale;
|
||||||
|
@ -1,248 +0,0 @@
|
|||||||
use bitvec::index::BitIdx;
|
|
||||||
use std::{error::Error, fmt, str::FromStr, vec::Vec};
|
|
||||||
|
|
||||||
use deku::{
|
|
||||||
bitvec::{BitStore, Msb0}, ctx::ByteSize, deku_derive, reader::{Reader, ReaderRet}, DekuContainerRead, DekuError, DekuReader
|
|
||||||
};
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
||||||
#[deku(endian = "big")]
|
|
||||||
pub(crate) struct GroupId(u16);
|
|
||||||
|
|
||||||
trait MapToDekuParseError<T> {
|
|
||||||
fn map_to_deku_parse_error(self) -> Result<T, DekuError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E: Error> MapToDekuParseError<T> for Result<T, E> {
|
|
||||||
fn map_to_deku_parse_error(self) -> Result<T, DekuError> {
|
|
||||||
self.map_err(|e| DekuError::Parse(e.to_string().into()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub(crate) struct DataField {
|
|
||||||
#[deku(reader = "read_size(deku::reader)")]
|
|
||||||
pub(crate) data_size: ByteSize,
|
|
||||||
|
|
||||||
#[deku(bytes_read = "data_size.0")]
|
|
||||||
pub(crate) data: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub(crate) struct BlockHeader {
|
|
||||||
pub(crate) group_id: GroupId,
|
|
||||||
|
|
||||||
#[deku(reader = "read_size(deku::reader)")]
|
|
||||||
pub(crate) data_size: ByteSize,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub(crate) struct DataBlock {
|
|
||||||
pub(crate) header: BlockHeader,
|
|
||||||
|
|
||||||
#[deku(ctx = "header.group_id")]
|
|
||||||
pub(crate) inner: DataGroup,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_size<R: std::io::Read>(reader: &mut Reader<R>) -> Result<ByteSize, DekuError> {
|
|
||||||
let first_byte: u8 = u8::from_reader_with_ctx(reader, ())?;
|
|
||||||
|
|
||||||
let is_length_expanded = first_byte.get_bit::<Msb0>(BitIdx::new(0).map_to_deku_parse_error()?);
|
|
||||||
|
|
||||||
match is_length_expanded {
|
|
||||||
true => {
|
|
||||||
let size_of_data_size: ByteSize = ByteSize((first_byte & 0b0111_1111) as usize);
|
|
||||||
|
|
||||||
if size_of_data_size.0 > 4 {
|
|
||||||
return Err(DekuError::Parse("Size of the length encoding is > 4, this is not normal. Probable parsing error".to_string().into()));
|
|
||||||
};
|
|
||||||
|
|
||||||
// maximum size of the buffer is 4, we use the offset to read values less than 4 bytes
|
|
||||||
let buffer: &mut [u8; 4] = &mut [0; 4];
|
|
||||||
let write_offset = 4 - size_of_data_size.0;
|
|
||||||
|
|
||||||
match reader.read_bytes(size_of_data_size.0, &mut buffer[write_offset..])? {
|
|
||||||
ReaderRet::Bits(_bit_vec) => Err(DekuError::Parse("Got bits when trying to read bytes -> reader is unaligned, this is not normal.".to_string().into())),
|
|
||||||
ReaderRet::Bytes => Ok(ByteSize(u32::from_be_bytes(*buffer) as usize)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false => Ok(ByteSize(first_byte as usize)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Using this as the map function asks deku to parse a datafield
|
|
||||||
// We then use the datafield and convert it to the corresponding value
|
|
||||||
fn convert_from_data_field<T>(data_field: DataField) -> Result<T, DekuError>
|
|
||||||
where
|
|
||||||
T: FromStr,
|
|
||||||
T::Err: Error,
|
|
||||||
{
|
|
||||||
let text = String::from_utf8(data_field.data).map_to_deku_parse_error()?;
|
|
||||||
T::from_str(&text).map_to_deku_parse_error()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct SSVVersionNumber(#[deku(map = "convert_from_data_field")] u16);
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct GALSSVersionNumber(#[deku(map = "convert_from_data_field")] u16);
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct PSSVersionNumber(#[deku(map = "convert_from_data_field")] u16);
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct ConfigurationHeader {
|
|
||||||
pub ssv_version: SSVVersionNumber,
|
|
||||||
pub galss_version: GALSSVersionNumber,
|
|
||||||
pub pss_version: PSSVersionNumber,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct PCSCReaderName(#[deku(map = "convert_from_data_field")] String);
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct CardType(#[deku(map = "convert_from_data_field")] u8);
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct PCSCReader {
|
|
||||||
pub name: PCSCReaderName,
|
|
||||||
pub card_type: CardType,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct SESAMVitaleComponentID(#[deku(map = "convert_from_data_field")] u16);
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct SESAMVitaleComponentDescription(#[deku(map = "convert_from_data_field")] String);
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct SESAMVitaleComponentVersion(#[deku(map = "convert_from_data_field")] String);
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct SESAMVitaleComponent {
|
|
||||||
pub id: SESAMVitaleComponentID,
|
|
||||||
pub description: SESAMVitaleComponentDescription,
|
|
||||||
pub version: SESAMVitaleComponentVersion,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct ReaderConfiguration {}
|
|
||||||
|
|
||||||
#[deku_derive(DekuRead)]
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
#[deku(ctx = "group_id: GroupId", id = "group_id.0")]
|
|
||||||
pub enum DataGroup {
|
|
||||||
#[deku(id = 60)]
|
|
||||||
ConfigurationHeader(ConfigurationHeader),
|
|
||||||
#[deku(id = 61)]
|
|
||||||
ReaderConfiguration(ReaderConfiguration),
|
|
||||||
#[deku(id = 64)]
|
|
||||||
SESAMVitaleComponent(SESAMVitaleComponent),
|
|
||||||
#[deku(id = 67)]
|
|
||||||
PCSCReader(PCSCReader),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum ConfigurationError {
|
|
||||||
MultipleConfigurationHeaders,
|
|
||||||
MissingConfigurationHeader,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for ConfigurationError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
ConfigurationError::MultipleConfigurationHeaders => {
|
|
||||||
write!(f, "Multiple ConfigurationHeader blocks found")
|
|
||||||
}
|
|
||||||
ConfigurationError::MissingConfigurationHeader => {
|
|
||||||
write!(f, "Missing ConfigurationHeader block")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for ConfigurationError {}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Configuration {
|
|
||||||
pub configuration_header: ConfigurationHeader,
|
|
||||||
pub reader_configurations: Vec<ReaderConfiguration>,
|
|
||||||
pub sesam_vitale_components: Vec<SESAMVitaleComponent>,
|
|
||||||
pub pcsc_readers: Vec<PCSCReader>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<Vec<DataBlock>> for Configuration {
|
|
||||||
type Error = ConfigurationError;
|
|
||||||
|
|
||||||
fn try_from(data_blocks: Vec<DataBlock>) -> Result<Self, Self::Error> {
|
|
||||||
let mut configuration_header: Option<ConfigurationHeader> = None;
|
|
||||||
let mut reader_configurations: Vec<ReaderConfiguration> = Vec::new();
|
|
||||||
let mut sesam_vitale_components: Vec<SESAMVitaleComponent> = Vec::new();
|
|
||||||
let mut pcsc_readers: Vec<PCSCReader> = Vec::new();
|
|
||||||
|
|
||||||
for block in data_blocks {
|
|
||||||
match block.inner {
|
|
||||||
DataGroup::ConfigurationHeader(header) => {
|
|
||||||
if configuration_header.is_some() {
|
|
||||||
return Err(ConfigurationError::MultipleConfigurationHeaders);
|
|
||||||
}
|
|
||||||
configuration_header = Some(header);
|
|
||||||
}
|
|
||||||
DataGroup::ReaderConfiguration(configuration) => {
|
|
||||||
reader_configurations.push(configuration)
|
|
||||||
}
|
|
||||||
DataGroup::SESAMVitaleComponent(component) => {
|
|
||||||
sesam_vitale_components.push(component);
|
|
||||||
}
|
|
||||||
DataGroup::PCSCReader(reader) => {
|
|
||||||
pcsc_readers.push(reader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let configuration_header = match configuration_header {
|
|
||||||
Some(header) => header,
|
|
||||||
None => return Err(ConfigurationError::MissingConfigurationHeader),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
configuration_header,
|
|
||||||
reader_configurations,
|
|
||||||
sesam_vitale_components,
|
|
||||||
pcsc_readers,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn read_from_buffer<T: TryFrom<Vec<DataBlock>>>(buffer: &[u8]) -> Result<T, T::Error>{
|
|
||||||
let mut data_blocks: Vec<DataBlock> = Vec::new();
|
|
||||||
let mut offset = 0;
|
|
||||||
|
|
||||||
let mut remaining_buffer = buffer;
|
|
||||||
|
|
||||||
while !remaining_buffer.is_empty() {
|
|
||||||
// TODO: properly handle errors
|
|
||||||
let (rest, data_block) = DataBlock::from_bytes((remaining_buffer, offset)).unwrap();
|
|
||||||
|
|
||||||
data_blocks.push(data_block);
|
|
||||||
|
|
||||||
(remaining_buffer, offset) = rest;
|
|
||||||
};
|
|
||||||
|
|
||||||
T::try_from(data_blocks)
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
pub(crate) use crate::types::common::IdentificationNationale;
|
|
||||||
|
|
||||||
use super::common::{
|
|
||||||
Byte, CategorieCarteProfessionnelSante, CodeAgrement, CodeCivilite, CodeConventionnel,
|
|
||||||
CodeSpecialite, CodeZoneIK, CodeZoneTarifaire, Identification, IdentificationFacturation,
|
|
||||||
IdentificationStructure, ModeExercice, SecteurActivite, StatutExercice,
|
|
||||||
TypeCarteProfessionnelSante,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(crate) struct CarteProfessionnelSante {
|
|
||||||
type_carte: TypeCarteProfessionnelSante,
|
|
||||||
categorie_carte: CategorieCarteProfessionnelSante,
|
|
||||||
professionnel_sante: ProfessionnelDeSante,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ProfessionnelDeSante {
|
|
||||||
prenom: String,
|
|
||||||
nom: String,
|
|
||||||
code_civilite: CodeCivilite,
|
|
||||||
identification_nationale: Identification<IdentificationNationale>,
|
|
||||||
situations_execice: Vec<SituationDExercice>,
|
|
||||||
}
|
|
||||||
struct StructureMedicale {
|
|
||||||
/// Nom Entreprise
|
|
||||||
raison_sociale: String,
|
|
||||||
identification: Identification<IdentificationStructure>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SituationDExercice {
|
|
||||||
/// Numéro identifiant la situation du PS parmi ses autres situations inscrites sur sa CPS
|
|
||||||
identifiant_situation: Byte,
|
|
||||||
mode_exercice: Option<ModeExercice>,
|
|
||||||
statut_exercice: Option<StatutExercice>,
|
|
||||||
secteur_activite: Option<SecteurActivite>,
|
|
||||||
structure_d_exercice: Option<StructureMedicale>,
|
|
||||||
identification_facturation: Identification<IdentificationFacturation>,
|
|
||||||
identification_remplacant: Option<Identification<IdentificationNationale>>,
|
|
||||||
code_conventionnel: CodeConventionnel,
|
|
||||||
code_specialite: CodeSpecialite,
|
|
||||||
code_zone_tarifaire: CodeZoneTarifaire,
|
|
||||||
code_zone_ik: CodeZoneIK,
|
|
||||||
code_agrement: CodeAgrement,
|
|
||||||
habilite_signature_facture: bool,
|
|
||||||
habilite_signature_lot: bool,
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user