Skip to content

Commit

Permalink
Fix imports according to formatting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
akoshelev committed Aug 11, 2023
1 parent ea6a35d commit 1a39cd4
Show file tree
Hide file tree
Showing 152 changed files with 1,138 additions and 874 deletions.
3 changes: 2 additions & 1 deletion benches/oneshot/arithmetic_circuit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::Instant;

use clap::Parser;
use ipa::{ff::Fp31, secret_sharing::SharedValue, test_fixture::circuit};
use std::time::Instant;

#[derive(Debug, Parser)]
pub struct CircuitArgs {
Expand Down
9 changes: 5 additions & 4 deletions benches/oneshot/ipa.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use std::{
num::{NonZeroU32, NonZeroUsize},
time::Instant,
};

use clap::Parser;
use ipa::{
error::Error,
Expand All @@ -9,10 +14,6 @@ use ipa::{
},
};
use rand::{rngs::StdRng, thread_rng, Rng, SeedableRng};
use std::{
num::{NonZeroU32, NonZeroUsize},
time::Instant,
};
use tokio::runtime::Builder;

#[cfg(all(not(target_env = "msvc"), not(feature = "dhat-heap")))]
Expand Down
3 changes: 2 additions & 1 deletion benches/oneshot/sort.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Instant;

use futures::stream::iter as stream_iter;
use ipa::{
error::Error,
Expand All @@ -14,7 +16,6 @@ use ipa::{
test_fixture::{join3, Reconstruct, TestWorld, TestWorldConfig},
};
use rand::Rng;
use std::time::Instant;

#[tokio::main(flavor = "multi_thread", worker_threads = 3)]
async fn main() -> Result<(), Error> {
Expand Down
15 changes: 8 additions & 7 deletions src/bin/helper.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
use std::{
fs,
net::TcpListener,
os::fd::{FromRawFd, RawFd},
path::{Path, PathBuf},
process,
};

use clap::{self, Parser, Subcommand};
use hyper::http::uri::Scheme;
use ipa::{
Expand All @@ -10,13 +18,6 @@ use ipa::{
net::{ClientIdentity, HttpTransport, MpcHelperClient},
AppSetup,
};
use std::{
fs,
net::TcpListener,
os::fd::{FromRawFd, RawFd},
path::{Path, PathBuf},
process,
};
use tracing::{error, info};

#[cfg(not(target_env = "msvc"))]
Expand Down
10 changes: 6 additions & 4 deletions src/bin/ipa_bench/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use crate::{gen_events::generate_events, sample::Sample};
use clap::Parser;
use ipa::cli::Verbosity;
use rand::{rngs::StdRng, SeedableRng};
use std::{
fs::File,
io,
path::{Path, PathBuf},
process,
};

use clap::Parser;
use ipa::cli::Verbosity;
use rand::{rngs::StdRng, SeedableRng};
use tracing::{debug, error, info};

use crate::{gen_events::generate_events, sample::Sample};

const DEFAULT_EVENT_GEN_COUNT: u32 = 100_000;

#[derive(Debug, Parser)]
Expand Down
3 changes: 2 additions & 1 deletion src/bin/ipa_bench/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use std::ops::Range;

use serde::{Deserialize, Serialize};

#[cfg(feature = "enable-serde")]
#[derive(Serialize, Deserialize, Debug)]
pub struct WeightedIndex<T> {
Expand Down
20 changes: 12 additions & 8 deletions src/bin/ipa_bench/gen_events.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use crate::{
models::{Epoch, Event, EventTimestamp, GenericReport, MatchKey, Number},
sample::Sample,
};
use std::io;

use bitvec::view::BitViewSized;
use rand::{
distributions::{Bernoulli, Distribution},
CryptoRng, Rng, RngCore,
};
use std::io;
use tracing::{debug, info, trace};

use crate::{
models::{Epoch, Event, EventTimestamp, GenericReport, MatchKey, Number},
sample::Sample,
};

// 0x1E. https://datatracker.ietf.org/doc/html/rfc7464
const RECORD_SEPARATOR: u8 = 30;

Expand Down Expand Up @@ -170,14 +172,16 @@ fn add_event_timestamps(rhs: EventTimestamp, lhs: EventTimestamp) -> EventTimest

#[cfg(all(test, unit_test))]
mod tests {
use super::{gen_reports, generate_events, EventTimestamp, GenericReport};
use crate::{gen_events::add_event_timestamps, models::Epoch, sample::Sample};
use rand::{rngs::StdRng, SeedableRng};
use std::{
cmp::Ordering,
io::{Cursor, Write},
};

use rand::{rngs::StdRng, SeedableRng};

use super::{gen_reports, generate_events, EventTimestamp, GenericReport};
use crate::{gen_events::add_event_timestamps, models::Epoch, sample::Sample};

const DATA: &str = r#"
{
"devices_per_user": [
Expand Down
8 changes: 4 additions & 4 deletions src/bin/ipa_bench/models.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use rand::{CryptoRng, Rng, RngCore};
use serde::{Deserialize, Serialize};
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>;
Expand Down Expand Up @@ -318,9 +319,8 @@ impl Debug for TriggerFanoutQuery {

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

use super::EventTimestamp;
use crate::models::Epoch;

#[test]
fn event_timestamp_new() {
Expand Down
6 changes: 4 additions & 2 deletions src/bin/ipa_bench/sample.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::config::Config;
use std::time::Duration;

use rand::{
distributions::{Distribution, WeightedIndex},
CryptoRng, Rng, RngCore,
};
use std::time::Duration;

use crate::config::Config;

pub struct Sample<'a> {
config: &'a Config,
Expand Down
36 changes: 15 additions & 21 deletions src/bin/report_collector.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
use std::{
borrow::Cow,
error::Error,
fmt::Debug,
fs::{File, OpenOptions},
io,
io::{stdout, Write},
ops::Deref,
path::{Path, PathBuf},
};

use clap::{Parser, Subcommand};
use comfy_table::{Cell, Table};
use hyper::http::uri::Scheme;
use ipa::{
cli::{
noise::{apply, ApplyDpArgs},
playbook::{make_clients, playbook_ipa, validate, InputSource},
Verbosity,
CsvSerializer, IpaQueryResult, Verbosity,
},
config::NetworkConfig,
ff::{FieldType, Fp32BitPrime},
helpers::query::{IpaQueryConfig, QueryConfig, QueryType},
helpers::query::{IpaQueryConfig, QueryConfig, QuerySize, QueryType},
hpke::{KeyRegistry, PublicKeyOnly},
net::MpcHelperClient,
protocol::{BreakdownKey, MatchKey},
Expand All @@ -17,27 +30,8 @@ use ipa::{
EventGenerator, EventGeneratorConfig,
},
};

use comfy_table::{Cell, Table};
use ipa::{
cli::{
noise::{apply, ApplyDpArgs},
CsvSerializer, IpaQueryResult,
},
helpers::query::QuerySize,
};
use rand::{distributions::Alphanumeric, rngs::StdRng, thread_rng, Rng};
use rand_core::SeedableRng;
use std::{
borrow::Cow,
error::Error,
fmt::Debug,
fs::{File, OpenOptions},
io,
io::{stdout, Write},
ops::Deref,
path::{Path, PathBuf},
};

#[derive(Debug, Parser)]
#[clap(name = "rc", about = "Report Collector CLI")]
Expand Down
3 changes: 2 additions & 1 deletion src/bin/test_mpc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{error::Error, fmt::Debug, ops::Add, path::PathBuf};

use clap::{Parser, Subcommand};
use generic_array::ArrayLength;
use hyper::http::uri::Scheme;
Expand All @@ -11,7 +13,6 @@ use ipa::{
net::MpcHelperClient,
secret_sharing::{replicated::semi_honest::AdditiveShare, IntoShares},
};
use std::{error::Error, fmt::Debug, ops::Add, path::PathBuf};

#[derive(Debug, Parser)]
#[clap(
Expand Down
8 changes: 5 additions & 3 deletions src/chunkscan.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use crate::error::BoxError;
use futures::{ready, Stream};
use pin_project::pin_project;
use std::{
future::Future,
mem,
pin::Pin,
task::{Context, Poll},
};

use futures::{ready, Stream};
use pin_project::pin_project;
use tracing::error;

use crate::error::BoxError;

/// A variant of stream transform that combines semantic of `StreamExt::chunks` and `StreamExt::scan`.
/// Consumes the input stream and keeps accumulating items in the internal buffer until it reaches
/// `capacity` elements. Then the elements are moved to the `f` function that must produce a future
Expand Down
12 changes: 7 additions & 5 deletions src/cli/clientconf.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::{fs, fs::File, io::Write, iter::zip, path::PathBuf};

use clap::Args;
use config::Map;
use hpke::Serializable as _;
use toml::{Table, Value};

use crate::{
cli::paths::PathExt,
config::{ClientConfig, HpkeClientConfig, NetworkConfig, PeerConfig},
error::BoxError,
};
use clap::Args;
use config::Map;
use hpke::Serializable as _;
use std::{fs, fs::File, io::Write, iter::zip, path::PathBuf};
use toml::{Table, Value};

#[derive(Debug, Args)]
#[clap(about = "Generate client config for 3 MPC helper parties")]
Expand Down
3 changes: 2 additions & 1 deletion src/cli/ipa_output.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::helpers::query::{IpaQueryConfig, QuerySize};
use std::time::Duration;

use crate::helpers::query::{IpaQueryConfig, QuerySize};

#[derive(Debug)]
#[cfg_attr(feature = "enable-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct QueryResult {
Expand Down
14 changes: 8 additions & 6 deletions src/cli/keygen.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use crate::{error::BoxError, hpke::KeyPair};
use std::{
fs::File,
io::{self, Write},
path::{Path, PathBuf},
};

use clap::Args;
use rand::{thread_rng, Rng};
use rand_core::CryptoRng;
use rcgen::{
Certificate, CertificateParams, DistinguishedName, ExtendedKeyUsagePurpose, IsCa,
KeyUsagePurpose, SanType, PKCS_ECDSA_P256_SHA256,
};
use std::{
fs::File,
io::{self, Write},
path::{Path, PathBuf},
};
use time::{Duration, OffsetDateTime};

use crate::{error::BoxError, hpke::KeyPair};

#[derive(Debug, Args)]
#[clap(
name = "keygen",
Expand Down
6 changes: 4 additions & 2 deletions src/cli/metric_collector.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::telemetry::stats::Metrics;
use std::{io::stderr, thread};

use metrics_tracing_context::TracingContextLayer;
use metrics_util::{
debugging::{DebuggingRecorder, Snapshotter},
layers::Layer,
};
use std::{io::stderr, thread};

use crate::telemetry::stats::Metrics;

/// Collects metrics using `DebuggingRecorder` and dumps them to `stderr` when dropped.
pub struct CollectorHandle {
Expand Down
7 changes: 4 additions & 3 deletions src/cli/noise.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use clap::Args;
use rand::rngs::StdRng;
use std::{
collections::BTreeMap,
fmt::{Debug, Display, Formatter},
};

use crate::protocol::dp::InsecureDiscreteDp;
use clap::Args;
use rand::rngs::StdRng;
use rand_core::SeedableRng;

use crate::protocol::dp::InsecureDiscreteDp;

#[derive(Debug, Args)]
#[clap(about = "Apply differential privacy noise to the given input")]
pub struct ApplyDpArgs {
Expand Down
6 changes: 2 additions & 4 deletions src/cli/playbook/input.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use crate::ff::Field;

use std::{
any::type_name,
fs::File,
io,
io::{stdin, BufRead, BufReader, Read},
path::PathBuf,
};

use crate::{
ff::GaloisField,
ff::{Field, GaloisField},
ipa_test_input,
test_fixture::{input::GenericReportTestInput, ipa::TestRawDataRecord},
};
use std::path::PathBuf;

pub trait InputItem {
fn from_str(s: &str) -> Self;
Expand Down
Loading

0 comments on commit 1a39cd4

Please sign in to comment.