scrambledb/
finalize.rs

1use crate::{
2    data_transformations::finalize_blinded_datum,
3    data_types::{BlindedPseudonymizedData, PseudonymizedData},
4    error::Error,
5    setup::StoreContext,
6    table::Table,
7};
8
9/// ## Finalization of Pseudonymous and Converted Tables
10///
11/// Finalization of pseudonyms is the same regardless of pseudonym type,
12/// i.e. whether they are long term storage pseudonyms at the Data Lake or
13/// join pseudonyms at a Data Processor.
14///
15/// Finalize a table of blinded pseudonymized data values by applying the
16/// finalization operation on each entry and shuffling the result:
17///
18/// Inputs:
19/// - `store_context`: The data store's pseudonymization context
20/// - `table`: A table of blinded pseudonymized data values
21///
22/// Output:
23/// A table of pseudonymized data values.
24pub fn finalize_blinded_table(
25    store_context: &StoreContext,
26    table: Table<BlindedPseudonymizedData>,
27) -> Result<Table<PseudonymizedData>, Error> {
28    let mut pseudonymized_data = table
29        .data()
30        .iter()
31        .map(|entry| finalize_blinded_datum(store_context, entry))
32        .collect::<Result<Vec<PseudonymizedData>, Error>>()?;
33
34    pseudonymized_data.sort();
35
36    Ok(Table::new(table.identifier().into(), pseudonymized_data))
37}