Skip to content

Commit

Permalink
Removed unused structures to help with coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cberkhoff committed Apr 3, 2024
1 parent 4a72886 commit 8b5a62c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 124 deletions.
104 changes: 1 addition & 103 deletions ipa-core/src/bin/ipa_bench/models.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use std::{
fmt::{Debug, Formatter},
io::{Error as IoError, ErrorKind as IoErrorKind},
ops::Range,
};

use rand::{CryptoRng, Rng, RngCore};
use serde::{Deserialize, Serialize};

// Type aliases to indicate whether the parameter should be encrypted, secret shared, etc.
// Underlying types are temporalily assigned for PoC.
pub type CipherText = Vec<u8>;
type PlainText = String;
pub type MatchKey = u64;
pub type Number = u32;
Expand All @@ -20,104 +17,6 @@ pub type Epoch = u8;
/// An offset in seconds into a given epoch. Using an 32-bit value > 20-bit > 604,800 seconds.
pub type Offset = u32;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecretShare {
ss: [CipherText; 3],
}

impl SecretShare {
fn combine(&self) -> Vec<u8> {
let mut result = Vec::new();

assert!(self.ss[0].len() == self.ss[1].len());
assert!(self.ss[0].len() == self.ss[2].len());

for i in 0..self.ss[0].len() {
result.push(self.ss[0][i] ^ self.ss[1][i] ^ self.ss[2][i]);
}

result
}

// TODO: Add Shamir's SS

fn xor<R: RngCore + CryptoRng>(data: &[u8], rng: &mut R) -> Self {
let mut ss = [Vec::new(), Vec::new(), Vec::new()];

for x in data {
let ss1 = rng.gen::<u8>();
let ss2 = rng.gen::<u8>();
let ss3 = ss1 ^ ss2 ^ x;

ss[0].push(ss1);
ss[1].push(ss2);
ss[2].push(ss3);
}

SecretShare { ss }
}
}

pub trait SecretSharable {
/// Splits the number into secret shares
fn xor_split<R: RngCore + CryptoRng>(&self, rng: &mut R) -> SecretShare;

/// Combines the given secret shares back to [Self]
/// # Errors
/// if the combined data overflows [Self]
fn combine(data: &SecretShare) -> Result<Self, IoError>
where
Self: Sized;
}

impl SecretSharable for u32 {
fn xor_split<R: RngCore + CryptoRng>(&self, rng: &mut R) -> SecretShare {
SecretShare::xor(&self.to_be_bytes(), rng)
}

fn combine(data: &SecretShare) -> Result<Self, IoError> {
let ss = data.combine();

let mut high = ss[0..ss.len() - 4].to_vec();
high.retain(|x| *x != 0);

if ss.len() > 4 && !high.is_empty() {
return Err(IoError::from(IoErrorKind::InvalidData));
}

let mut bytes = [0u8; 4];
for (i, v) in ss[ss.len() - 4..].iter().enumerate() {
bytes[i] = *v;
}

Ok(u32::from_be_bytes(bytes))
}
}

impl SecretSharable for u64 {
fn xor_split<R: RngCore + CryptoRng>(&self, rng: &mut R) -> SecretShare {
SecretShare::xor(&self.to_be_bytes(), rng)
}

fn combine(data: &SecretShare) -> Result<Self, IoError> {
let ss = data.combine();

let mut high = ss[0..ss.len() - 8].to_vec();
high.retain(|x| *x != 0);

if ss.len() > 8 && !high.is_empty() {
return Err(IoError::from(IoErrorKind::InvalidData));
}

let mut bytes = [0u8; 8];
for (i, v) in ss[ss.len() - 8..].iter().enumerate() {
bytes[i] = *v;
}

Ok(u64::from_be_bytes(bytes))
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]

Check warning on line 20 in ipa-core/src/bin/ipa_bench/models.rs

View check run for this annotation

Codecov / codecov/patch

ipa-core/src/bin/ipa_bench/models.rs#L20

Added line #L20 was not covered by tests
/// A timestamp of a source/trigger report represented by epoch and offset.
///
Expand Down Expand Up @@ -313,8 +212,7 @@ impl Debug for TriggerFanoutQuery {

#[cfg(all(test, unit_test))]
mod tests {
use super::EventTimestamp;
use crate::models::Epoch;
use super::{EventTimestamp, Epoch};

#[test]
fn event_timestamp_new() {
Expand Down
17 changes: 0 additions & 17 deletions ipa-core/src/helpers/transport/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub mod oprf_shuffle;

use std::{
fmt::{Debug, Display, Formatter},
num::NonZeroU32,
Expand Down Expand Up @@ -312,18 +310,3 @@ impl std::fmt::Display for ContributionBits {
write!(f, "{}", self.0)
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SparseAggregateQueryConfig {
pub contribution_bits: ContributionBits,
pub num_contributions: u32,
}

impl Default for SparseAggregateQueryConfig {
fn default() -> Self {
Self {
contribution_bits: ContributionBits::default(),
num_contributions: 8,
}
}
}
4 changes: 0 additions & 4 deletions ipa-core/src/helpers/transport/query/oprf_shuffle.rs

This file was deleted.

0 comments on commit 8b5a62c

Please sign in to comment.