Compare commits
6 Commits
9ec9a70e5c
...
af92e316da
Author | SHA1 | Date | |
---|---|---|---|
af92e316da | |||
c9b1895e0c | |||
7992f3df0e | |||
59c325024a | |||
473212c2e6 | |||
f71b99a4c0 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1 +0,0 @@
|
||||
Cargo.lock -merge linguist-generated=false
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1527,9 +1527,7 @@ dependencies = [
|
||||
name = "fsv"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"fsv-sys",
|
||||
"num_enum",
|
||||
"thiserror",
|
||||
"utils",
|
||||
]
|
||||
|
@ -1,12 +0,0 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(unused)]
|
||||
|
||||
pub mod BINDINGS_V1_40_14 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.14.rs"));
|
||||
}
|
||||
|
||||
pub mod BINDINGS_V1_40_13 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.13.rs"));
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
mod bindings;
|
||||
use bindings::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SupportedFsvVersion {
|
||||
pub enum SUPPORTED_FSV_VERSIONS {
|
||||
V1_40_14, // 1.40.14
|
||||
V1_40_13, // 1.40.13
|
||||
}
|
||||
|
||||
impl SupportedFsvVersion {
|
||||
impl SUPPORTED_FSV_VERSIONS {
|
||||
fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::V1_40_14 => "1.40.14",
|
||||
@ -20,6 +19,14 @@ impl SupportedFsvVersion {
|
||||
}
|
||||
}
|
||||
|
||||
mod BINDINGS_V1_40_14 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.14.rs"));
|
||||
}
|
||||
|
||||
mod BINDINGS_V1_40_13 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.13.rs"));
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
@ -59,26 +66,26 @@ mod sealed { pub trait Sealed {}}
|
||||
/// Wrapper around the SESAM-VITALE library
|
||||
/// This struct is responsible for loading the library and providing an interface to call its functions.
|
||||
/// The library is loaded at creation and kept in memory until the struct is dropped.
|
||||
pub trait SSVLibraryCommon {
|
||||
pub trait SSVLibrary_Common {
|
||||
fn new(path: &str) -> Result<Self, Error> where Self: Sized;
|
||||
}
|
||||
|
||||
pub trait SSVLibraryVersion: sealed::Sealed {}
|
||||
pub trait SSVLibrary_Version: sealed::Sealed {}
|
||||
|
||||
pub struct V1_40_13 {}
|
||||
impl sealed::Sealed for V1_40_13 {}
|
||||
impl SSVLibraryVersion for V1_40_13 {}
|
||||
impl SSVLibrary_Version for V1_40_13 {}
|
||||
|
||||
pub struct V1_40_14 {}
|
||||
impl sealed::Sealed for V1_40_14 {}
|
||||
impl SSVLibraryVersion for V1_40_14 {}
|
||||
impl SSVLibrary_Version for V1_40_14 {}
|
||||
|
||||
pub struct SSVLibrary<Version: SSVLibraryVersion> {
|
||||
pub struct SSVLibrary<Version: SSVLibrary_Version> {
|
||||
_version: PhantomData<Version>,
|
||||
library: libloading::Library,
|
||||
}
|
||||
|
||||
impl<Version: SSVLibraryVersion> SSVLibraryCommon for SSVLibrary<Version> {
|
||||
impl<Version: SSVLibrary_Version> SSVLibrary_Common for SSVLibrary<Version> {
|
||||
fn new(path: &str) -> Result<Self, Error> {
|
||||
let library = unsafe { libloading::Library::new(path)?};
|
||||
Ok(Self {
|
||||
@ -130,14 +137,14 @@ impl SSVLibrary<V1_40_13> {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_library_path(version: &SupportedFsvVersion) -> String {
|
||||
pub fn get_library_path(version: &SUPPORTED_FSV_VERSIONS) -> String {
|
||||
let root_path = get_library_root_path();
|
||||
let library_name = get_library_name();
|
||||
let version = version.as_str();
|
||||
format!("{root_path}/{version}/lib/{library_name}")
|
||||
}
|
||||
|
||||
pub fn sesam_ini_path(version: &SupportedFsvVersion) -> String {
|
||||
pub fn sesam_ini_path(version: &SUPPORTED_FSV_VERSIONS) -> String {
|
||||
let root_path = get_sesam_ini_root_path();
|
||||
let version = version.as_str();
|
||||
format!("{root_path}/{version}/conf/sesam.ini")
|
||||
@ -164,22 +171,22 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_initlib2() {
|
||||
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
||||
let lib_path = &get_library_path(&SUPPORTED_FSV_VERSIONS::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");
|
||||
CString::new(sesam_ini_path(&SUPPORTED_FSV_VERSIONS::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]
|
||||
fn test_lire_config_and_carte_ps() {
|
||||
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
||||
let lib_path = &get_library_path(&SUPPORTED_FSV_VERSIONS::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");
|
||||
CString::new(sesam_ini_path(&SUPPORTED_FSV_VERSIONS::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);
|
||||
|
||||
|
@ -4,8 +4,6 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.89"
|
||||
num_enum = "0.7.3"
|
||||
thiserror = "1.0.64"
|
||||
|
||||
fsv-sys = { path = "../fsv-sys" }
|
||||
|
@ -1,24 +1,11 @@
|
||||
use thiserror::Error;
|
||||
|
||||
use fsv_sys::{
|
||||
get_library_path,
|
||||
Error as FsvError,
|
||||
SSVLibrary,
|
||||
SSVLibraryCommon,
|
||||
SupportedFsvVersion,
|
||||
V1_40_13,
|
||||
V1_40_14
|
||||
};
|
||||
|
||||
mod errors_ssv;
|
||||
use errors_ssv::SSVErrorCodes;
|
||||
use fsv_sys::{get_library_path, Error as FsvError, SSVLibrary, SSVLibrary_Common, SUPPORTED_FSV_VERSIONS, V1_40_13, V1_40_14};
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
FSVSysLibrary(#[from] FsvError),
|
||||
#[error(transparent)]
|
||||
SSVError(#[from] SSVErrorCodes),
|
||||
SysLibrary(#[from] FsvError)
|
||||
}
|
||||
|
||||
/// Enum to hold the different versions of the SSV library
|
||||
@ -33,14 +20,14 @@ pub struct SSV {
|
||||
}
|
||||
|
||||
impl SSV {
|
||||
fn new(version: SupportedFsvVersion) -> Result<Self, Error> {
|
||||
fn new(version: SUPPORTED_FSV_VERSIONS) -> Result<Self, Error> {
|
||||
let library = match version {
|
||||
SupportedFsvVersion::V1_40_13 => {
|
||||
SUPPORTED_FSV_VERSIONS::V1_40_13 => {
|
||||
let lib_path = get_library_path(&version);
|
||||
let library = SSVLibrary::<V1_40_13>::new(&lib_path)?;
|
||||
SsvLibraryVersion::V1_40_13(library)
|
||||
},
|
||||
SupportedFsvVersion::V1_40_14 => {
|
||||
SUPPORTED_FSV_VERSIONS::V1_40_14 => {
|
||||
let lib_path = get_library_path(&version);
|
||||
let library = SSVLibrary::<V1_40_14>::new(&lib_path)?;
|
||||
SsvLibraryVersion::V1_40_14(library)
|
||||
@ -55,17 +42,15 @@ impl SSV {
|
||||
/// Implement: SSV_InitLIB2
|
||||
pub fn init_library(&self, sesam_ini_path: &str) -> Result<(), Error> {
|
||||
let sesam_ini_path = std::ffi::CString::new(sesam_ini_path).expect("CString::new failed");
|
||||
let result = match &self.library {
|
||||
match &self.library {
|
||||
SsvLibraryVersion::V1_40_13(library) => {
|
||||
unsafe { library.ssv_init_lib2(sesam_ini_path.as_ptr()) }?
|
||||
let result = unsafe { library.ssv_init_lib2(sesam_ini_path.as_ptr()) }?;
|
||||
println!("SSV_InitLIB2 result: {}", result);
|
||||
},
|
||||
SsvLibraryVersion::V1_40_14(library) => {
|
||||
unsafe { library.ssv_init_lib2(sesam_ini_path.as_ptr()) }?
|
||||
let result = unsafe { library.ssv_init_lib2(sesam_ini_path.as_ptr()) }?;
|
||||
println!("SSV_InitLIB2 result: {}", result);
|
||||
},
|
||||
};
|
||||
if result != 0 {
|
||||
let error = SSVErrorCodes::from(result);
|
||||
return Err(Error::SSVError(error));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -76,21 +61,19 @@ mod tests {
|
||||
use std::env;
|
||||
|
||||
use utils::config::load_config;
|
||||
use anyhow::Result;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn init() -> Result<SSV> {
|
||||
fn init() -> SSV {
|
||||
load_config().unwrap();
|
||||
Ok(SSV::new(SupportedFsvVersion::V1_40_13)?)
|
||||
SSV::new(SUPPORTED_FSV_VERSIONS::V1_40_13).expect("SSV::new failed")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_init_library() -> Result<()> {
|
||||
let lib = init()?;
|
||||
fn test_init_library() {
|
||||
let lib = init();
|
||||
let sesam_ini_path = env::var("SESAM_INI_PATH").expect("SESAM_INI_PATH must be set");
|
||||
lib.init_library(&sesam_ini_path)?;
|
||||
Ok(())
|
||||
lib.init_library(&sesam_ini_path).expect("init_library failed");
|
||||
}
|
||||
|
||||
#[test]
|
@ -1,82 +0,0 @@
|
||||
use num_enum::FromPrimitive;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug, Eq, PartialEq, FromPrimitive)]
|
||||
#[repr(u16)]
|
||||
pub enum SSVErrorCodes {
|
||||
#[error("Le fichier `tablebin.smc` est inaccessible en lecture (inexistant ou pas de droits d'accès).")]
|
||||
FileMissingTablebinMsc = 0xF610, // tablebin.smc
|
||||
#[error("Le fichier `scripts.sms` est inaccessible en lecture (inexistant ou pas de droits d'accès).")]
|
||||
FileMissingScriptsSms = 0xF611, // scripts.sms
|
||||
#[error("Le fichier `tablebin.ssv` est inaccessible en lecture (inexistant ou pas de droits d'accès).")]
|
||||
FileMissingTablebinSsv = 0xF612, // tablebin.ssv
|
||||
#[error("Le fichier `script.ssv` est inaccessible en lecture (inexistant ou pas de droits d'accès).")]
|
||||
FileMissingScriptSsv = 0xF613, // script.ssv
|
||||
#[error("La version du fichier `tablebin.smc` est incompatible avec la bibliothèque des SSV.")]
|
||||
FileVersionIncompatibleTablebinMsc = 0xF620, // tablebin.smc
|
||||
#[error("La version du fichier `scripts.sms` est incompatible avec la bibliothèque des SSV.")]
|
||||
FileVersionIncompatibleScriptsSms = 0xF621, // scripts.sms
|
||||
#[error("La version du fichier `tablebin.ssv` est incompatible avec la bibliothèque des SSV.")]
|
||||
FileVersionIncompatibleTablebinSsv = 0xF622, // tablebin.ssv
|
||||
#[error("La version du fichier `script.ssv` est incompatible avec la bibliothèque des SSV.")]
|
||||
FileVersionIncompatibleScriptSsv = 0xF623, // script.ssv
|
||||
#[error("L'intégrité du fichier `tablebin.smc` est incorrecte.")]
|
||||
FileIntegrityIncorrectTablebinMsc = 0xF630, // tablebin.smc
|
||||
#[error("L'intégrité du fichier `scripts.sms` est incorrecte.")]
|
||||
FileIntegrityIncorrectScriptsSms = 0xF631, // scripts.sms
|
||||
#[error("L'intégrité du fichier `tablebin.ssv` est incorrecte.")]
|
||||
FileIntegrityIncorrectTablebinSsv = 0xF632, // tablebin.ssv
|
||||
#[error("L'intégrité du fichier `script.ssv` est incorrecte.")]
|
||||
FileIntegrityIncorrectScriptSsv = 0xF633, // script.ssv
|
||||
#[error("La structure interne du fichier `tablebin.smc` est invalide.")]
|
||||
FileStructureInvalidTablebinMsc = 0xF640, // tablebin.smc
|
||||
#[error("La structure interne du fichier `scripts.sms` est invalide.")]
|
||||
FileStructureInvalidScriptsSms = 0xF641, // scripts.sms
|
||||
#[error("La structure interne du fichier `tablebin.ssv` est invalide.")]
|
||||
FileStructureInvalidTablebinSsv = 0xF642, // tablebin.ssv
|
||||
#[error("La structure interne du fichier `script.ssv` est invalide.")]
|
||||
FileStructureInvalidScriptSsv = 0xF643, // script.ssv
|
||||
#[error("Le fichier `tablebin.smc` n'a pas pu être chargé en mémoire. Essayez de libérer de la mémoire.")]
|
||||
FileLoadFailedTablebinMsc = 0xF650, // tablebin.smc
|
||||
#[error("Le fichier `scripts.sms` n'a pas pu être chargé en mémoire. Essayez de libérer de la mémoire.")]
|
||||
FileLoadFailedScriptsSms = 0xF651, // scripts.sms
|
||||
#[error("Le fichier `tablebin.ssv` n'a pas pu être chargé en mémoire. Essayez de libérer de la mémoire.")]
|
||||
FileLoadFailedTablebinSsv = 0xF652, // tablebin.ssv
|
||||
#[error("Le fichier `script.ssv` n'a pas pu être chargé en mémoire. Essayez de libérer de la mémoire.")]
|
||||
FileLoadFailedScriptSsv = 0xF653, // script.ssv
|
||||
#[error("Le nom du fichier `tablebin.smc` est invalide.")]
|
||||
FileNameInvalidTablebinMsc = 0xF660, // tablebin.smc
|
||||
#[error("Le nom du fichier `scripts.sms` est invalide.")]
|
||||
FileNameInvalidScriptsSms = 0xF661, // scripts.sms
|
||||
#[error("Le nom du fichier `tablebin.ssv` est invalide.")]
|
||||
FileNameInvalidTablebinSsv = 0xF662, // tablebin.ssv
|
||||
#[error("Le nom du fichier `script.ssv` est invalide.")]
|
||||
FileNameInvalidScriptSsv = 0xF663, // script.ssv
|
||||
#[error("La fonction Initialiser Librairie est déjà appelée.")]
|
||||
FunctionInitLib2AlreadyCalled = 0xF670, // Warning
|
||||
#[error("Le fichier SESAM.INI est inaccessible en lecture (fichier ou droit d’accès manquant) ou ne contient pas le chemin des tables binaires des SSV.")]
|
||||
SesamIniMissingFileOrTablebinPath = 0xF680,
|
||||
#[error("Le chemin du répertoire de travail est absent du fichier SESAM.INI.")]
|
||||
SesamIniMissingWorkDir = 0xF6F1,
|
||||
#[error("Les fichiers d’extension adm ne sont pas accessibles en écriture.")]
|
||||
AdmFilesNotWritable = 0xF6F2, // Warning
|
||||
#[error("Aucune version de FSV du socle technique trouvé. Vérifier que la version du fichier script.sms est bonne.")]
|
||||
NoFsvVersionFound = 0xF6F4,
|
||||
#[error("Librairie SGD absente ou incomplète.")]
|
||||
LibraryMissingOrIncompleteSGD = 0xF6F5,
|
||||
#[error("Librairie SMC absente ou incomplète.")]
|
||||
LibraryMissingOrIncompleteSMC = 0xF6F6,
|
||||
#[error("Librairie SJS absente ou incomplète.")]
|
||||
LibraryMissingOrIncompleteSJS = 0xF6F7,
|
||||
#[error("Librairie SMS absente ou incomplète.")]
|
||||
LibraryMissingOrIncompleteSMS = 0xF6F8,
|
||||
#[error("Section MGC absente / clé RepertoireConfigTrace absente / fichier log4crc.xml non trouvé à l’emplacement indiqué par la clé RepertoireConfigTrace du fichier SESAM.INI.")]
|
||||
SesamIniTracingConfigMissing = 0xFF22, // Warning
|
||||
#[error("Interface Full PC/SC : problème de chargement de la librairie cryptographique ou erreur retournée par la librairie cryptographique.")]
|
||||
PCSCInterfaceCryptoLibraryError = 0xFF25,
|
||||
#[error("Valorisation incorrecte des paramètres de gestion de l'accès aux ressources dans le SESAM.INI. Vérifier les valeurs des clés tempoexclusivite, repetitionexclusivite, tempoexclusivitePCSC, repetitionexclusivitePCSC")]
|
||||
SesamIniResourceAccessParamsIncorrect = 0xFF2A,
|
||||
#[num_enum(catch_all)]
|
||||
#[error("Erreur inattendue de la librairie SSV (code d'erreur: {0}).")]
|
||||
Unexpected(u16),
|
||||
}
|
Loading…
Reference in New Issue
Block a user