Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

style(rustfmt): format imports #95

Merged
merged 8 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# https://rust-lang.github.io/rustfmt/

imports_layout = "HorizontalVertical"
imports_granularity = "Module"
group_imports = "StdExternalCrate"
15 changes: 9 additions & 6 deletions rtc_data_enclave/src/data_upload.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use std::prelude::v1::*;

use rand::prelude::*;
use rtc_tenclave::crypto::RtcCrypto;
use rtc_tenclave::crypto::SodaBoxCrypto as Crypto;
use rtc_tenclave::crypto::{RtcCrypto, SodaBoxCrypto as Crypto};
use rtc_tenclave::util;
use rtc_types::DataUploadError as DataError;
use rtc_types::UploadMetadata as Metadata;
use rtc_types::{CryptoError, DataUploadResponse};
use rtc_types::{
CryptoError,
DataUploadError as DataError,
DataUploadResponse,
UploadMetadata as Metadata,
};
use secrecy::{ExposeSecret, Zeroize};
use sgx_tseal::SgxSealedData;
use sgx_types::*;
use std::prelude::v1::*;
use uuid::Uuid;

pub struct SealedResult {
Expand Down
4 changes: 2 additions & 2 deletions rtc_data_enclave/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ mod data_upload;
mod ocalls;

use core::slice;
use rtc_types::*;
use sgx_types::*;
use std::prelude::v1::*;

#[allow(unused_imports)] // for ECALL linking
use rtc_tenclave::enclave::enclave_create_report;
use rtc_types::*;
use sgx_types::*;

/// Validates and save a payload encrypted for the enclave
///
Expand Down
3 changes: 2 additions & 1 deletion rtc_data_enclave/src/ocalls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use sgx_types::*;
use std::boxed::Box;

use sgx_types::*;
use uuid::Uuid;

extern "C" {
Expand Down
17 changes: 7 additions & 10 deletions rtc_data_service/http_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

mod tls;

use std::sync::Arc;

use actix::{Arbiter, Supervisor};
use actix_cors::Cors;
use actix_web::http::header;
use actix_web::web::{self, Data};
use actix_web::{App, HttpServer};
use rtc_data_service::app_config::AppConfig;
use rtc_data_service::auth_enclave_actor::AuthEnclaveActor;
use rtc_data_service::data_enclave_actor::DataEnclaveActor;
Expand All @@ -14,16 +21,6 @@ use rtc_data_service::exec_enclave_actor::ExecEnclaveActor;
use rtc_data_service::exec_token::*;
use rtc_data_service::handlers::*;

use std::sync::Arc;

use actix::{Arbiter, Supervisor};
use actix_cors::Cors;
use actix_web::{
http::header,
web::{self, Data},
App, HttpServer,
};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
let config = AppConfig::new().expect("Server config expected");
Expand Down
12 changes: 7 additions & 5 deletions rtc_data_service/http_server/src/tls.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::io::BufReader;
use std::{fs, io, iter};

use rtc_data_service::app_config::TlsConfig;
use rustls::{
AllowAnyAuthenticatedClient, NoClientAuth, PrivateKey, RootCertStore,
AllowAnyAuthenticatedClient,
NoClientAuth,
PrivateKey,
RootCertStore,
ServerConfig as TlsServerConfig,
};
use rustls_pemfile::{self, read_one, Item};
use thiserror::Error;

use std::io::BufReader;
use std::iter;
use std::{fs, io};

pub fn get_tls_server_config(config: TlsConfig) -> Result<TlsServerConfig, TlsConfigError> {
let client_auth = match config.client_cert_path {
Some(path) => {
Expand Down
3 changes: 2 additions & 1 deletion rtc_data_service/src/app_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::env;

use config::{Config, ConfigError, Environment, File};
use rtc_uenclave::EnclaveConfig;
use serde::Deserialize;
use std::env;

// Configuration specific to the server
#[derive(Deserialize, Clone, Default)]
Expand Down
3 changes: 2 additions & 1 deletion rtc_data_service/src/auth_enclave_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
//! TODO: The `*_enclave_actor` modules currently mirror each other,
//! and should be kept in sync until we factor out the shared code.

use std::sync::Arc;

use actix::prelude::*;
use rtc_uenclave::{AttestationError, EnclaveConfig, RtcAuthEnclave};
use std::sync::Arc;

#[derive(Default)]
pub(crate) struct RequestAttestation;
Expand Down
3 changes: 2 additions & 1 deletion rtc_data_service/src/data_enclave_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
//! TODO: The `*_enclave_actor` modules currently mirror each other,
//! and should be kept in sync until we factor out the shared code.

use std::sync::Arc;

use actix::prelude::*;
use rtc_uenclave::{AttestationError, EnclaveConfig, RtcDataEnclave};
use std::sync::Arc;

#[derive(Default)]
pub(crate) struct RequestAttestation;
Expand Down
3 changes: 2 additions & 1 deletion rtc_data_service/src/data_upload/message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::data_enclave_actor::DataEnclaveActor;
use actix::{Handler, Message};
use rtc_types::{DataUploadError, DataUploadResponse, EcallError, UploadMetadata};

use crate::data_enclave_actor::DataEnclaveActor;

pub struct DataUploadMessage {
pub metadata: UploadMetadata,
pub payload: Box<[u8]>,
Expand Down
16 changes: 9 additions & 7 deletions rtc_data_service/src/data_upload/service.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::convert::TryInto;

use actix::{Addr, MailboxError};
use actix_web::{error::ErrorInternalServerError, post, web};
use actix_web::error::ErrorInternalServerError;
use actix_web::{post, web};
use models::*;
use rtc_types::{DataUploadError, DataUploadResponse, EcallError};

use super::DataUploadMessage;
use crate::data_enclave_actor::DataEnclaveActor;
use crate::merge_error::*;

use super::DataUploadMessage;
use std::convert::TryInto;

/// Save uploaded data file using a [`DataUploadMessage`] for [`DataEnclaveActor`].
///
/// * Request: POST [`RequestBody`]
Expand All @@ -34,13 +35,14 @@ pub async fn upload_file(
}

pub mod models {
use crate::validation::ValidationError;
use crate::Base64Standard;
use std::convert::TryFrom;

use rtc_types::{DataUploadResponse, UploadMetadata};
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;

use crate::data_upload::DataUploadMessage;
use crate::validation::ValidationError;
use crate::Base64Standard;

#[derive(Serialize, Deserialize, Debug)]
pub struct RequestBody {
Expand Down
3 changes: 2 additions & 1 deletion rtc_data_service/src/exec/message.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::convert::Infallible;

use crate::exec_enclave_actor::ExecEnclaveActor;
use actix::{Handler, Message};

use crate::exec_enclave_actor::ExecEnclaveActor;

// TODO: Replace with types from rtc_types
pub(crate) type RequestExecutionResponse = ();
pub(crate) type RequestExecutionError = Infallible;
Expand Down
17 changes: 9 additions & 8 deletions rtc_data_service/src/exec/service.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::convert::TryInto;

use actix::{Addr, MailboxError};
use actix_web::{error::ErrorInternalServerError, post, web};
use actix_web::error::ErrorInternalServerError;
use actix_web::{post, web};
use models::*;

use crate::{
exec::{RequestExecutionError, RequestExecutionMessage, RequestExecutionResponse},
exec_enclave_actor::ExecEnclaveActor,
merge_error::*,
};
use crate::exec::{RequestExecutionError, RequestExecutionMessage, RequestExecutionResponse};
use crate::exec_enclave_actor::ExecEnclaveActor;
use crate::merge_error::*;

/// Request execution using an execution token
#[post("/exec/request")]
Expand All @@ -27,11 +26,13 @@ pub async fn request_execution(
}

pub mod models {
use std::convert::TryFrom;

use serde::{Deserialize, Serialize};

use crate::exec::{RequestExecutionMessage, RequestExecutionResponse};
use crate::validation::ValidationError;
use crate::Base64Standard;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;

#[derive(Serialize, Deserialize, Debug)]
pub struct Metadata {
Expand Down
3 changes: 2 additions & 1 deletion rtc_data_service/src/exec_enclave_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
//! TODO: The `*_enclave_actor` modules currently mirror each other,
//! and should be kept in sync until we factor out the shared code.

use std::sync::Arc;

use actix::prelude::*;
use rtc_uenclave::{AttestationError, EnclaveConfig, RtcExecEnclave};
use std::sync::Arc;

#[derive(Default)]
pub(crate) struct RequestAttestation;
Expand Down
3 changes: 2 additions & 1 deletion rtc_data_service/src/exec_token/message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::data_enclave_actor::DataEnclaveActor;
use actix::{Handler, Message};
use rtc_types::{ExecReqMetadata, ExecTokenError, ExecTokenResponse};

use crate::data_enclave_actor::DataEnclaveActor;

// TODO : Change struct values to resemble request Body (add data access key, uuid, hash, keypair, nonce..)
pub struct ExecTokenMessage {
pub metadata: ExecReqMetadata,
Expand Down
13 changes: 7 additions & 6 deletions rtc_data_service/src/exec_token/service.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::convert::TryInto;

use actix::{Addr, MailboxError};
use actix_web::{error::ErrorInternalServerError, post, web, HttpRequest};
use actix_web::error::ErrorInternalServerError;
use actix_web::{post, web, HttpRequest};
use models::*;
use rtc_types::{ExecTokenError, ExecTokenResponse};

use super::ExecTokenMessage;
use crate::data_enclave_actor::DataEnclaveActor;
use crate::merge_error::*;

use super::ExecTokenMessage;

#[post("auth/tokens")]
pub async fn req_exec_token(
_req: HttpRequest,
Expand All @@ -27,13 +27,14 @@ pub async fn req_exec_token(
}

pub mod models {
use crate::validation::ValidationError;
use crate::Base64Standard;
use std::convert::TryFrom;

use rtc_types::{ExecReqMetadata, ExecTokenResponse};
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;

use crate::exec_token::ExecTokenMessage;
use crate::validation::ValidationError;
use crate::Base64Standard;

#[derive(Serialize, Deserialize, Debug)]
pub struct RequestBody {
Expand Down
7 changes: 3 additions & 4 deletions rtc_data_service/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use actix::Addr;
use actix_web::{error::ErrorInternalServerError, get, web, HttpRequest, HttpResponse};
use actix_web::error::ErrorInternalServerError;
use actix_web::{get, web, HttpRequest, HttpResponse};
use models::Status;

use crate::auth_enclave_actor;
use crate::auth_enclave_actor::AuthEnclaveActor;
use crate::data_enclave_actor;
use crate::data_enclave_actor::DataEnclaveActor;
use crate::exec_enclave_actor;
use crate::exec_enclave_actor::ExecEnclaveActor;
use crate::merge_error::*;
use crate::{auth_enclave_actor, data_enclave_actor, exec_enclave_actor};

pub async fn server_status(_req: HttpRequest) -> HttpResponse {
HttpResponse::Ok().json(Status {
Expand Down
3 changes: 1 addition & 2 deletions rtc_data_service/src/merge_error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::{Debug, Display};

// TODO: Pull this into the rtc_types library?

Expand Down
4 changes: 1 addition & 3 deletions rtc_data_service/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ use std::sync::Arc;

use actix::Actor;
use actix_web::App;

use rtc_uenclave::{EnclaveConfig, RtcAuthEnclave, RtcDataEnclave};

use rtc_data_service::auth_enclave_actor::AuthEnclaveActor;
use rtc_data_service::data_enclave_actor::DataEnclaveActor;
use rtc_data_service::data_upload::upload_file;
use rtc_data_service::exec::request_execution;
use rtc_data_service::exec_enclave_actor::ExecEnclaveActor;
use rtc_data_service::exec_token::req_exec_token;
use rtc_data_service::handlers;
use rtc_uenclave::{EnclaveConfig, RtcAuthEnclave, RtcDataEnclave};

/// Initialise an auth enclave for testing.
pub(crate) fn init_auth_enclave() -> RtcAuthEnclave<EnclaveConfig> {
Expand Down
11 changes: 3 additions & 8 deletions rtc_data_service/tests/web_api/data_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
use std::convert::TryInto;
use std::path::Path;

use sgx_types::sgx_target_info_t;

use actix_web::test;
use uuid::Uuid;

use rtc_data_service::data_upload::models;

use crate::helpers;
use sgx_types::sgx_target_info_t;
use uuid::Uuid;

// See rtc_tenclave/src/crypto.rs
use crate::CRYPTO_BOX_BOXZEROBYTES;
use crate::CRYPTO_BOX_ZEROBYTES;
use crate::{helpers, CRYPTO_BOX_BOXZEROBYTES, CRYPTO_BOX_ZEROBYTES};

/// Upload some data, decrypt and check the result.
#[actix_rt::test]
Expand Down
1 change: 0 additions & 1 deletion rtc_data_service/tests/web_api/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use actix_web::web::Bytes;
use actix_web::{http, test};

use rtc_data_service::exec;

use crate::helpers;
Expand Down
1 change: 0 additions & 1 deletion rtc_data_service/tests/web_api/exec_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use actix_web::web::Bytes;
use actix_web::{http, test};

use rtc_data_service::exec_token;

use crate::helpers;
Expand Down
12 changes: 6 additions & 6 deletions rtc_tenclave/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::convert::TryInto;
use std::prelude::v1::*;

use rand::prelude::*;
use rtc_types::EncryptedMessage;
use rtc_types::{CryptoError as Error, SizedEncryptedMessage};
use rtc_types::{CryptoError as Error, EncryptedMessage, SizedEncryptedMessage};
use secrecy::{ExposeSecret, Secret};
use sgx_types::*;
use std::{convert::TryInto, prelude::v1::*};
use zeroize::Zeroize;

#[cfg(not(test))]
use sgx_tse::{rsgx_get_key, rsgx_self_report};
use sgx_types::*;
use zeroize::Zeroize;

// FIXME: sodalite should expose these padding constants.
// Values referenced from https://tweetnacl.cr.yp.to/20140427/tweetnacl.h
Expand Down
Loading