Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
emostov committed Jun 15, 2022
1 parent 1540729 commit ac0f61c
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 42 deletions.
41 changes: 27 additions & 14 deletions qos-client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ impl ClientOptions {
};

let mut chunks = args.chunks_exact(2);
assert!(chunks.remainder().is_empty(), "Unexpected number of arguments");
assert!(
chunks.remainder().is_empty(),
"Unexpected number of arguments"
);

while let Some([cmd, arg]) = chunks.next() {
options.host.parse(cmd, arg);
Expand All @@ -80,10 +83,10 @@ impl ClientOptions {
Command::GenerateSetupKey => {
options.generate_setup_key.parse(cmd, arg);
}
Command::Health |
Command::DescribeNsm |
Command::MockAttestation |
Command::Attestation => {}
Command::Health
| Command::DescribeNsm
| Command::MockAttestation
| Command::Attestation => {}
Command::BootGenesis => options.boot_genesis.parse(cmd, arg),
}
}
Expand Down Expand Up @@ -170,10 +173,9 @@ impl BootGenesisOptions {
match cmd {
"--key-dir" => self.key_dir = Some(arg.to_string()),
"--threshold" => {
self.threshold =
Some(arg.parse::<u32>().expect(
"Could not parse provided value for `--threshold`",
));
self.threshold = Some(arg.parse::<u32>().expect(
"Could not parse provided value for `--threshold`",
));
}
"--out-dir" => self.out_dir = Some(arg.to_string()),
_ => {}
Expand Down Expand Up @@ -209,7 +211,10 @@ mod handlers {
};
use qos_crypto::RsaPub;

use super::{AWS_ROOT_CERT_PEM, BorshSerialize, ClientOptions, Echo, ProtocolMsg, RsaPair, attestation_doc_from_der, cert_from_pem};
use super::{
attestation_doc_from_der, cert_from_pem, BorshSerialize, ClientOptions,
Echo, ProtocolMsg, RsaPair, AWS_ROOT_CERT_PEM,
};
use crate::{attest, request};

pub(super) fn health(options: &ClientOptions) {
Expand Down Expand Up @@ -334,7 +339,10 @@ mod handlers {
let key_dir = options.generate_setup_key.key_dir();
let key_dir_path = std::path::Path::new(&key_dir);

assert!(key_dir_path.is_dir(), "Provided `--key-dir` does not exist is not valid");
assert!(
key_dir_path.is_dir(),
"Provided `--key-dir` does not exist is not valid"
);

let setup_key = RsaPair::generate().expect("RSA key generation failed");
// Write the setup key secret
Expand Down Expand Up @@ -458,7 +466,10 @@ mod handlers {
// Get all the files in the key directory
let key_files = {
let key_dir_path = std::path::Path::new(&key_dir);
assert!(key_dir_path.is_dir(), "Provided path is not a valid directory");
assert!(
key_dir_path.is_dir(),
"Provided path is not a valid directory"
);
std::fs::read_dir(key_dir_path)
.expect("Failed to read key directory")
};
Expand All @@ -468,8 +479,10 @@ mod handlers {
let members: Vec<_> = key_files
.map(|maybe_key_path| maybe_key_path.unwrap().path())
.filter_map(|key_path| {
let file_name =
key_path.file_name().map(std::ffi::OsStr::to_string_lossy).unwrap();
let file_name = key_path
.file_name()
.map(std::ffi::OsStr::to_string_lossy)
.unwrap();
let split: Vec<_> = file_name.split('.').collect();

// TODO: do we want to dissallow having anything in this folder
Expand Down
23 changes: 16 additions & 7 deletions qos-core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub struct EnclaveOptions {

impl EnclaveOptions {
/// Create a new instance of [`Self`] with some defaults.
#[must_use] pub fn new() -> Self {
#[must_use]
pub fn new() -> Self {
Self {
cid: None,
port: None,
Expand All @@ -37,7 +38,10 @@ impl EnclaveOptions {
let mut options = EnclaveOptions::new();

let mut chunks = args.chunks_exact(2);
assert!(chunks.remainder().is_empty(), "Unexepected number of arguments");
assert!(
chunks.remainder().is_empty(),
"Unexepected number of arguments"
);

while let Some([cmd, arg]) = chunks.next() {
options.parse(cmd, arg);
Expand Down Expand Up @@ -114,7 +118,8 @@ impl EnclaveOptions {
/// # Panics
///
/// Panics if the options are not valid for exactly one of unix or vsock.
#[must_use] pub fn addr(&self) -> SocketAddress {
#[must_use]
pub fn addr(&self) -> SocketAddress {
match self.clone() {
#[cfg(feature = "vm")]
EnclaveOptions {
Expand All @@ -128,7 +133,8 @@ impl EnclaveOptions {
}

/// Get the [`NsmProvider`]
#[must_use] pub fn nsm(&self) -> Box<dyn NsmProvider> {
#[must_use]
pub fn nsm(&self) -> Box<dyn NsmProvider> {
if self.mock {
Box::new(MockNsm)
} else {
Expand All @@ -137,17 +143,20 @@ impl EnclaveOptions {
}

/// Defaults to [`SECRET_FILE`] if not explicitly specified
#[must_use] pub fn secret_file(&self) -> String {
#[must_use]
pub fn secret_file(&self) -> String {
self.secret_file.clone()
}

/// Defaults to [`PIVOT_FILE`] if not explicitly specified
#[must_use] pub fn pivot_file(&self) -> String {
#[must_use]
pub fn pivot_file(&self) -> String {
self.pivot_file.clone()
}

/// Defaults to [`EPHEMERAL_KEY_FILE`] if not explicitly specified
#[must_use] pub fn ephemeral_key_file(&self) -> String {
#[must_use]
pub fn ephemeral_key_file(&self) -> String {
self.ephemeral_key_file.clone()
}
}
Expand Down
3 changes: 2 additions & 1 deletion qos-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ pub struct Client {

impl Client {
/// Create a new client.
#[must_use] pub fn new(addr: SocketAddress) -> Self {
#[must_use]
pub fn new(addr: SocketAddress) -> Self {
Self { addr }
}

Expand Down
3 changes: 2 additions & 1 deletion qos-core/src/io/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl SocketAddress {
/// # Panics
///
/// Panics if `nix::sys::socket::UnixAddr::new` panics.
#[must_use] pub fn new_unix(path: &str) -> Self {
#[must_use]
pub fn new_unix(path: &str) -> Self {
let addr = UnixAddr::new(path).unwrap();
Self::Unix(addr)
}
Expand Down
5 changes: 1 addition & 4 deletions qos-core/src/protocol/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ mod test {
];

let manifest = Manifest {
namespace: Namespace {
nonce: 420,
name: "vape lord".to_string(),
},
namespace: Namespace { nonce: 420, name: "vape lord".to_string() },
enclave: NitroConfig {
vsock_cid: 69,
vsock_port: 42069,
Expand Down
9 changes: 7 additions & 2 deletions qos-core/src/protocol/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ pub struct GenesisOutput {

impl GenesisOutput {
/// Canonical hash of [`Self`]
#[must_use] pub fn hash(&self) -> Hash256 {
#[must_use]
pub fn hash(&self) -> Hash256 {
qos_crypto::sha_256(
&self.try_to_vec().expect("`Manifest` serializes with cbor"),
)
Expand Down Expand Up @@ -122,7 +123,11 @@ pub(super) fn boot_genesis(
let encrypted_quorum_key_share =
personal_pair.envelope_encrypt(&share)?;

member_outputs.push(GenesisMemberOutput { setup_member, encrypted_quorum_key_share, encrypted_personal_key });
member_outputs.push(GenesisMemberOutput {
setup_member,
encrypted_quorum_key_share,
encrypted_personal_key,
});
}

let genesis_output = GenesisOutput {
Expand Down
8 changes: 6 additions & 2 deletions qos-core/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ pub struct Executor {

impl Executor {
/// Create a new `Self`.
#[must_use] pub fn new(
#[must_use]
pub fn new(
attestor: Box<dyn NsmProvider>,
secret_file: String,
pivot_file: String,
Expand Down Expand Up @@ -208,7 +209,10 @@ impl server::Routable for Executor {
mod handlers {
use qos_crypto::RsaPair;

use super::{BootInstruction, Load, NsmRequest, Permissions, PermissionsExt, ProtocolMsg, ProtocolPhase, ProtocolState, boot, genesis, set_permissions};
use super::{
boot, genesis, set_permissions, BootInstruction, Load, NsmRequest,
Permissions, PermissionsExt, ProtocolMsg, ProtocolPhase, ProtocolState,
};

/// Unwrap an ok or return early with a generic error.
/// TODO: this try and pass through the returned error
Expand Down
6 changes: 4 additions & 2 deletions qos-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl From<openssl::error::ErrorStack> for CryptoError {
}

/// Create a SHA256 hash digest of `buf`.
#[must_use] pub fn sha_256(buf: &[u8]) -> [u8; 32] {
#[must_use]
pub fn sha_256(buf: &[u8]) -> [u8; 32] {
let mut hasher = openssl::sha::Sha256::new();
hasher.update(buf);
hasher.finish()
Expand All @@ -74,7 +75,8 @@ pub struct RsaPair {

impl RsaPair {
/// Get the public key of this pair.
#[must_use] pub fn public_key(&self) -> &RsaPub {
#[must_use]
pub fn public_key(&self) -> &RsaPub {
&self.public_key
}

Expand Down
3 changes: 2 additions & 1 deletion qos-crypto/src/shamir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ fn gf256_interpolate(xs: &[u8], ys: &[u8]) -> u8 {
}

/// Generate n shares requiring k shares to reconstruct.
#[must_use] pub fn shares_generate(secret: &[u8], n: usize, k: usize) -> Vec<Vec<u8>> {
#[must_use]
pub fn shares_generate(secret: &[u8], n: usize, k: usize) -> Vec<Vec<u8>> {
let mut shares = vec![vec![]; n];

// we need to store x for each point somewhere, so just prepend
Expand Down
13 changes: 7 additions & 6 deletions qos-host/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ pub struct HostOptions {

impl HostOptions {
/// Create a new instance of [`self`].
#[must_use] pub fn new() -> Self {
#[must_use]
pub fn new() -> Self {
Self::default()
}

Expand All @@ -41,7 +42,8 @@ impl HostOptions {
/// # Panics
///
/// Panics if the url cannot be parsed from options
#[must_use] pub fn url(&self) -> String {
#[must_use]
pub fn url(&self) -> String {
if let Self { ip: Some(ip), port: Some(port) } = self {
return format!(
"http://{}.{}.{}.{}:{}",
Expand All @@ -53,7 +55,8 @@ impl HostOptions {
}

/// Get the resource path.
#[must_use] pub fn path(&self, path: &str) -> String {
#[must_use]
pub fn path(&self, path: &str) -> String {
let url = self.url();
format!("{}/{}", url, path)
}
Expand Down Expand Up @@ -119,9 +122,7 @@ impl CLI {
let options = parse_args(&args);
let addr = host_addr_from_options(options.host);
let enclave_addr = options.enclave.addr();
HostServer::new_with_socket_addr(enclave_addr, addr)
.serve()
.await;
HostServer::new_with_socket_addr(enclave_addr, addr).serve().await;
}
}

Expand Down
6 changes: 4 additions & 2 deletions qos-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ pub struct HostServer {

impl HostServer {
/// Create a new [`HostServer`].
#[must_use] pub fn new(enclave_addr: SocketAddress, ip: [u8; 4], port: u16) -> Self {
#[must_use]
pub fn new(enclave_addr: SocketAddress, ip: [u8; 4], port: u16) -> Self {
Self { addr: SocketAddr::from((ip, port)), enclave_addr }
}

/// Create a new [`HostServer`].
#[must_use] pub fn new_with_socket_addr(
#[must_use]
pub fn new_with_socket_addr(
enclave_addr: SocketAddress,
addr: SocketAddr,
) -> Self {
Expand Down

0 comments on commit ac0f61c

Please sign in to comment.