Skip to main content

paas_server/
pep_crypto.rs

1use libpep::factors::{EncryptionSecret, PseudonymizationSecret};
2use libpep::keys::distribution::BlindingFactor;
3use libpep::transcryptor::DistributedTranscryptor;
4use serde::Deserialize;
5use std::fs;
6
7#[derive(Deserialize, Debug)]
8pub struct PEPSystemConfig {
9    pseudonymization_secret: String,
10    rekeying_secret: String,
11    blinding_factor: String,
12}
13
14pub fn create_pep_crypto_system(system_config_file: &str) -> DistributedTranscryptor {
15    let file_content =
16        fs::read_to_string(system_config_file).expect("Failed to read PEP system config file");
17    let pep_system_config: PEPSystemConfig =
18        serde_yml::from_str(&file_content).expect("Failed to PEP system config file");
19
20    let blinding_factor = BlindingFactor::from_hex(pep_system_config.blinding_factor.as_str())
21        .expect("Failed to decode blinding factor");
22
23    DistributedTranscryptor::new(
24        PseudonymizationSecret::from(pep_system_config.pseudonymization_secret.into_bytes()),
25        EncryptionSecret::from(pep_system_config.rekeying_secret.into_bytes()),
26        blinding_factor,
27    )
28}