You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesatee.apache.org by ur...@apache.org on 2019/11/20 19:58:41 UTC
[incubator-mesatee] branch acs updated: Apply rustfmt and fix
clippy warnings
This is an automated email from the ASF dual-hosted git repository.
uraj pushed a commit to branch acs
in repository https://gitbox.apache.org/repos/asf/incubator-mesatee.git
View the commit online:
https://github.com/apache/incubator-mesatee/commit/580ba5478a98ce3b2ff6980691dd56b6331fa609
The following commit(s) were added to refs/heads/acs by this push:
new 580ba54 Apply rustfmt and fix clippy warnings
580ba54 is described below
commit 580ba5478a98ce3b2ff6980691dd56b6331fa609
Author: Pei Wang <wa...@baidu.com>
AuthorDate: Wed Nov 20 11:57:29 2019 -0800
Apply rustfmt and fix clippy warnings
---
mesatee_services/acs/client/src/acs_client.rs | 39 +--
mesatee_services/acs/proto/src/lib.rs | 1 -
mesatee_services/acs/proto/src/proto.rs | 4 +-
mesatee_services/acs/sgx_trusted_lib/src/acs.rs | 26 +-
mesatee_services/acs/sgx_trusted_lib/src/sgx.rs | 4 +-
.../sgx_trusted_lib/src/tests/acs_test.rs | 273 +++++++++++----------
.../sgx_trusted_lib/src/tests/common_setup.rs | 3 +-
.../sgx_trusted_lib/src/tests/mod.rs | 2 +-
8 files changed, 169 insertions(+), 183 deletions(-)
diff --git a/mesatee_services/acs/client/src/acs_client.rs b/mesatee_services/acs/client/src/acs_client.rs
index 9a1ceff..287550a 100644
--- a/mesatee_services/acs/client/src/acs_client.rs
+++ b/mesatee_services/acs/client/src/acs_client.rs
@@ -51,11 +51,7 @@ impl ACSClient {
}
}
- pub fn enforce_data_access(
- &mut self,
- task: String,
- data: String
- ) -> Result<bool> {
+ pub fn enforce_data_access(&mut self, task: String, data: String) -> Result<bool> {
let req = ACSRequest::Enforce(EnforceRequest::AccessData(task, data));
let resp = self.channel.invoke(req)?;
match resp {
@@ -64,11 +60,7 @@ impl ACSClient {
}
}
- pub fn enforce_data_deletion(
- &mut self,
- usr: String,
- data: String,
- ) -> Result<bool> {
+ pub fn enforce_data_deletion(&mut self, usr: String, data: String) -> Result<bool> {
let req = ACSRequest::Enforce(EnforceRequest::DeleteData(usr, data));
let resp = self.channel.invoke(req)?;
match resp {
@@ -76,12 +68,8 @@ impl ACSClient {
_ => Err(Error::from(ErrorKind::RPCResponseError)),
}
}
-
- pub fn enforce_script_access(
- &mut self,
- task: String,
- script: String,
- ) -> Result<bool> {
+
+ pub fn enforce_script_access(&mut self, task: String, script: String) -> Result<bool> {
let req = ACSRequest::Enforce(EnforceRequest::AccessScript(task, script));
let resp = self.channel.invoke(req)?;
match resp {
@@ -89,12 +77,8 @@ impl ACSClient {
_ => Err(Error::from(ErrorKind::RPCResponseError)),
}
}
-
- pub fn enforce_script_deletion(
- &mut self,
- usr: String,
- script: String
- ) -> Result<bool> {
+
+ pub fn enforce_script_deletion(&mut self, usr: String, script: String) -> Result<bool> {
let req = ACSRequest::Enforce(EnforceRequest::DeleteScript(usr, script));
let resp = self.channel.invoke(req)?;
match resp {
@@ -120,17 +104,16 @@ impl ACSClient {
) -> Result<()> {
let mut facts = Vec::with_capacity(1 + participants.len());
for par in participants {
- facts.push(AccessControlTerms::TaskParticipant(task.clone(), par.clone()));
+ facts.push(AccessControlTerms::TaskParticipant(
+ task.clone(),
+ par.clone(),
+ ));
}
facts.push(AccessControlTerms::TaskCreator(task, creator));
self._announce_terms(facts)
}
- pub fn announce_data_creation(
- &mut self,
- data: String,
- creator: String,
- ) -> Result<()> {
+ pub fn announce_data_creation(&mut self, data: String, creator: String) -> Result<()> {
self._announce_terms(std::vec!(AccessControlTerms::DataOwner(data, creator)))
}
diff --git a/mesatee_services/acs/proto/src/lib.rs b/mesatee_services/acs/proto/src/lib.rs
index ff8f727..c8de55e 100644
--- a/mesatee_services/acs/proto/src/lib.rs
+++ b/mesatee_services/acs/proto/src/lib.rs
@@ -13,7 +13,6 @@
// limitations under the License.
#![cfg_attr(feature = "mesalock_sgx", no_std)]
#[cfg(feature = "mesalock_sgx")]
-
extern crate sgx_tstd as std;
mod proto;
diff --git a/mesatee_services/acs/proto/src/proto.rs b/mesatee_services/acs/proto/src/proto.rs
index 78c63f1..7deac9c 100644
--- a/mesatee_services/acs/proto/src/proto.rs
+++ b/mesatee_services/acs/proto/src/proto.rs
@@ -40,7 +40,7 @@ pub enum EnforceRequest {
// access_data = task, data
AccessData(String, String),
-
+
// delete_data = usr, data
DeleteData(String, String),
@@ -60,7 +60,7 @@ pub struct AnnounceRequest {
pub enum AccessControlTerms {
// task_creator = task, usr
TaskCreator(String, String),
-
+
// task_participant = task, usr
TaskParticipant(String, String),
diff --git a/mesatee_services/acs/sgx_trusted_lib/src/acs.rs b/mesatee_services/acs/sgx_trusted_lib/src/acs.rs
index 4e2c735..4cf9d71 100644
--- a/mesatee_services/acs/sgx_trusted_lib/src/acs.rs
+++ b/mesatee_services/acs/sgx_trusted_lib/src/acs.rs
@@ -17,10 +17,10 @@
use std::prelude::v1::*;
use mesatee_core::rpc::EnclaveService;
-use mesatee_core::{Result, ErrorKind};
+use mesatee_core::{ErrorKind, Result};
+use std::collections::HashSet;
use std::ffi::CString;
use std::os::raw::c_char;
-use std::collections::HashSet;
use acs_proto::*;
@@ -70,10 +70,13 @@ where
}
}
-impl<T> PyMarshallable for [T] where T: PyMarshallable {
+impl<T> PyMarshallable for [T]
+where
+ T: PyMarshallable,
+{
fn marshal(&self, buffer: &mut String) {
buffer.push('[');
- for t in self.as_ref() {
+ for t in self {
t.marshal(buffer);
buffer.push(',');
}
@@ -146,12 +149,11 @@ impl HandleRequest for EnforceRequest {
("delete_script", buffer)
}
};
-
+
let c_request_type = CString::new(request_type.to_string()).unwrap();
let c_request_content = CString::new(request_content).unwrap();
- let py_ret = unsafe {
- acs_enforce_request(c_request_type.as_ptr(), c_request_content.as_ptr())
- };
+ let py_ret =
+ unsafe { acs_enforce_request(c_request_type.as_ptr(), c_request_content.as_ptr()) };
match py_ret {
0 => Ok(ACSResponse::Enforce(false)),
@@ -196,10 +198,8 @@ impl HandleRequest for AnnounceRequest {
let c_term_type = CString::new(term_type.to_string()).unwrap();
let c_term_fact = CString::new(term_fact).unwrap();
- let py_ret = unsafe {
- acs_announce_fact(c_term_type.as_ptr(), c_term_fact.as_ptr())
- };
-
+ let py_ret = unsafe { acs_announce_fact(c_term_type.as_ptr(), c_term_fact.as_ptr()) };
+
if py_ret != 0 {
return Err(ErrorKind::MesaPyError.into());
}
@@ -225,7 +225,7 @@ impl EnclaveService<ACSRequest, ACSResponse> for ACSEnclave {
ACSRequest::Enforce(req) => req.handle_request()?,
ACSRequest::Announce(req) => req.handle_request()?,
};
-
+
Ok(response)
}
}
diff --git a/mesatee_services/acs/sgx_trusted_lib/src/sgx.rs b/mesatee_services/acs/sgx_trusted_lib/src/sgx.rs
index 85266e6..4ab1123 100644
--- a/mesatee_services/acs/sgx_trusted_lib/src/sgx.rs
+++ b/mesatee_services/acs/sgx_trusted_lib/src/sgx.rs
@@ -21,7 +21,7 @@ use std::os::raw::c_char;
use mesatee_core::config;
use mesatee_core::prelude::*;
-use mesatee_core::{Result, Error, ErrorKind};
+use mesatee_core::{Error, ErrorKind, Result};
use env_logger;
use std::backtrace::{self, PrintFormat};
@@ -72,7 +72,7 @@ fn handle_serve_connection(args: &ServeConnectionInput) -> Result<ServeConnectio
Ok(ServeConnectionOutput::default())
}
-const MODEL_TEXT: &'static str = include_str!("../../model.conf");
+const MODEL_TEXT: &str = include_str!("../../model.conf");
#[handle_ecall]
fn handle_init_enclave(_args: &InitEnclaveInput) -> Result<InitEnclaveOutput> {
diff --git a/tests/functional_test/sgx_trusted_lib/src/tests/acs_test.rs b/tests/functional_test/sgx_trusted_lib/src/tests/acs_test.rs
index 51d2d5c..4c72f97 100644
--- a/tests/functional_test/sgx_trusted_lib/src/tests/acs_test.rs
+++ b/tests/functional_test/sgx_trusted_lib/src/tests/acs_test.rs
@@ -16,23 +16,23 @@ use super::common_setup::setup_acs_internal_client;
use std::collections::HashSet;
use std::string::ToString;
-
-const FUSION_TASK: &'static str = "data_fusion";
-const FUSION_TASK_PARTY_1: &'static str = "usr1";
-const FUSION_TASK_PARTY_2: &'static str = "usr2";
+const FUSION_TASK: &str = "data_fusion";
-const FUSION_TASK_DATA_1: &'static str = "data1";
-const FUSION_TASK_DATA_2: &'static str = "data2";
+const FUSION_TASK_PARTY_1: &str = "usr1";
+const FUSION_TASK_PARTY_2: &str = "usr2";
-const FUSION_TASK_SCRIPT: &'static str = "fusion_script";
-const FUSION_TASK_SCRIPT_WRITER: &'static str = "usr3";
-const PUBLIC_SCRIPT: &'static str = "public_script";
-const PUBLIC_SCRIPT_WRITER: &'static str = "usr4";
+const FUSION_TASK_DATA_1: &str = "data1";
+const FUSION_TASK_DATA_2: &str = "data2";
-const IRRELEVANT_TASK: &'static str = "task_irrelevant";
-const IRRELEVANT_PARTY: &'static str = "usr_irrelevant";
-const IRRELEVANT_DATA: &'static str = "data_irrelevant";
+const FUSION_TASK_SCRIPT: &str = "fusion_script";
+const FUSION_TASK_SCRIPT_WRITER: &str = "usr3";
+const PUBLIC_SCRIPT: &str = "public_script";
+const PUBLIC_SCRIPT_WRITER: &str = "usr4";
+
+const IRRELEVANT_TASK: &str = "task_irrelevant";
+const IRRELEVANT_PARTY: &str = "usr_irrelevant";
+const IRRELEVANT_DATA: &str = "data_irrelevant";
pub fn access_control_model() {
trace!("Test ACS: access control model.");
@@ -43,112 +43,113 @@ pub fn access_control_model() {
participants.insert(FUSION_TASK_PARTY_2.to_string());
participants.insert(FUSION_TASK_SCRIPT_WRITER.to_string());
- client.announce_task_creation(
- FUSION_TASK.to_string(),
- FUSION_TASK_PARTY_1.to_string(),
- &participants,
- ).expect("fusion task creation announcement failed");
-
- client.announce_data_creation(
- FUSION_TASK_DATA_1.to_string(),
- FUSION_TASK_PARTY_1.to_string(),
- ).expect("fusion data n1 creation announcement failed");
-
- client.announce_data_creation(
- FUSION_TASK_DATA_2.to_string(),
- FUSION_TASK_PARTY_2.to_string(),
- ).expect("fusion data 2 creation announcement failed");
-
- client.announce_data_creation(
- IRRELEVANT_DATA.to_string(),
- IRRELEVANT_PARTY.to_string(),
- ).expect("irrelevant data creation announcement failed");
-
- client.announce_script_creation(
- FUSION_TASK_SCRIPT.to_string(),
- FUSION_TASK_SCRIPT_WRITER.to_string(),
- false,
- ).expect("fusion script creation announcement failed");
+ client
+ .announce_task_creation(
+ FUSION_TASK.to_string(),
+ FUSION_TASK_PARTY_1.to_string(),
+ &participants,
+ )
+ .expect("fusion task creation announcement failed");
- client.announce_script_creation(
- PUBLIC_SCRIPT.to_string(),
- PUBLIC_SCRIPT_WRITER.to_string(),
- true,
- ).expect("public script creation announcement failed");
+ client
+ .announce_data_creation(
+ FUSION_TASK_DATA_1.to_string(),
+ FUSION_TASK_PARTY_1.to_string(),
+ )
+ .expect("fusion data n1 creation announcement failed");
+
+ client
+ .announce_data_creation(
+ FUSION_TASK_DATA_2.to_string(),
+ FUSION_TASK_PARTY_2.to_string(),
+ )
+ .expect("fusion data 2 creation announcement failed");
+
+ client
+ .announce_data_creation(IRRELEVANT_DATA.to_string(), IRRELEVANT_PARTY.to_string())
+ .expect("irrelevant data creation announcement failed");
+
+ client
+ .announce_script_creation(
+ FUSION_TASK_SCRIPT.to_string(),
+ FUSION_TASK_SCRIPT_WRITER.to_string(),
+ false,
+ )
+ .expect("fusion script creation announcement failed");
+
+ client
+ .announce_script_creation(
+ PUBLIC_SCRIPT.to_string(),
+ PUBLIC_SCRIPT_WRITER.to_string(),
+ true,
+ )
+ .expect("public script creation announcement failed");
let mut participants = HashSet::new();
-
+
assert_eq!(
- client.enforce_task_launch(
- FUSION_TASK.to_string(),
- participants.clone(),
- ).unwrap(),
+ client
+ .enforce_task_launch(FUSION_TASK.to_string(), participants.clone(),)
+ .unwrap(),
false,
);
participants.insert(FUSION_TASK_PARTY_1.to_string());
assert_eq!(
- client.enforce_task_launch(
- FUSION_TASK.to_string(),
- participants.clone(),
- ).unwrap(),
+ client
+ .enforce_task_launch(FUSION_TASK.to_string(), participants.clone(),)
+ .unwrap(),
false,
);
participants.insert(FUSION_TASK_PARTY_2.to_string());
- assert_eq!(
- client.enforce_task_launch(
- FUSION_TASK.to_string(),
- participants.clone(),
- ).unwrap(),
+ assert_eq!(
+ client
+ .enforce_task_launch(FUSION_TASK.to_string(), participants.clone(),)
+ .unwrap(),
false,
);
participants.insert(FUSION_TASK_SCRIPT_WRITER.to_string());
assert_eq!(
- client.enforce_task_launch(
- FUSION_TASK.to_string(),
- participants.clone(),
- ).unwrap(),
+ client
+ .enforce_task_launch(FUSION_TASK.to_string(), participants.clone(),)
+ .unwrap(),
true,
);
-
+
// Load fusion script
assert_eq!(
- client.enforce_script_access(
- FUSION_TASK.to_string(),
- FUSION_TASK_SCRIPT.to_string(),
- ).unwrap(),
+ client
+ .enforce_script_access(FUSION_TASK.to_string(), FUSION_TASK_SCRIPT.to_string(),)
+ .unwrap(),
true,
);
// Load public script
assert_eq!(
- client.enforce_script_access(
- FUSION_TASK.to_string(),
- PUBLIC_SCRIPT.to_string(),
- ).unwrap(),
+ client
+ .enforce_script_access(FUSION_TASK.to_string(), PUBLIC_SCRIPT.to_string(),)
+ .unwrap(),
true,
);
// Read data1
assert_eq!(
- client.enforce_data_access(
- FUSION_TASK.to_string(),
- FUSION_TASK_DATA_1.to_string(),
- ).unwrap(),
+ client
+ .enforce_data_access(FUSION_TASK.to_string(), FUSION_TASK_DATA_1.to_string(),)
+ .unwrap(),
true,
);
// Read data2
assert_eq!(
- client.enforce_data_access(
- FUSION_TASK.to_string(),
- FUSION_TASK_DATA_2.to_string(),
- ).unwrap(),
+ client
+ .enforce_data_access(FUSION_TASK.to_string(), FUSION_TASK_DATA_2.to_string(),)
+ .unwrap(),
true,
);
@@ -156,112 +157,116 @@ pub fn access_control_model() {
participants.insert(IRRELEVANT_PARTY.to_string());
participants.insert(FUSION_TASK_PARTY_2.to_string());
-
- client.announce_task_creation(
- IRRELEVANT_TASK.to_string(),
- IRRELEVANT_PARTY.to_string(),
- &participants,
- ).expect("irrelevant task creation announcement failed");
+
+ client
+ .announce_task_creation(
+ IRRELEVANT_TASK.to_string(),
+ IRRELEVANT_PARTY.to_string(),
+ &participants,
+ )
+ .expect("irrelevant task creation announcement failed");
// Launch irrelevant task
assert_eq!(
- client.enforce_task_launch(
- IRRELEVANT_TASK.to_string(),
- participants,
- ).unwrap(),
+ client
+ .enforce_task_launch(IRRELEVANT_TASK.to_string(), participants,)
+ .unwrap(),
true,
);
// Load fusion script; deny
assert_eq!(
- client.enforce_script_access(
- IRRELEVANT_TASK.to_string(),
- FUSION_TASK_SCRIPT.to_string(),
- ).unwrap(),
+ client
+ .enforce_script_access(IRRELEVANT_TASK.to_string(), FUSION_TASK_SCRIPT.to_string(),)
+ .unwrap(),
false,
);
// Load public script; allow
assert_eq!(
- client.enforce_script_access(
- IRRELEVANT_TASK.to_string(),
- PUBLIC_SCRIPT.to_string(),
- ).unwrap(),
+ client
+ .enforce_script_access(IRRELEVANT_TASK.to_string(), PUBLIC_SCRIPT.to_string(),)
+ .unwrap(),
true,
);
// Read data1; deny
assert_eq!(
- client.enforce_data_access(
- IRRELEVANT_TASK.to_string(),
- FUSION_TASK_DATA_1.to_string(),
- ).unwrap(),
+ client
+ .enforce_data_access(IRRELEVANT_TASK.to_string(), FUSION_TASK_DATA_1.to_string(),)
+ .unwrap(),
false,
);
// Read data2; allow
assert_eq!(
- client.enforce_data_access(
- IRRELEVANT_TASK.to_string(),
- FUSION_TASK_DATA_2.to_string(),
- ).unwrap(),
+ client
+ .enforce_data_access(IRRELEVANT_TASK.to_string(), FUSION_TASK_DATA_2.to_string(),)
+ .unwrap(),
true,
);
assert_eq!(
- client.enforce_data_deletion(
- FUSION_TASK_PARTY_1.to_string(),
- FUSION_TASK_DATA_1.to_string(),
- ).unwrap(),
+ client
+ .enforce_data_deletion(
+ FUSION_TASK_PARTY_1.to_string(),
+ FUSION_TASK_DATA_1.to_string(),
+ )
+ .unwrap(),
true,
);
assert_eq!(
- client.enforce_data_deletion(
- FUSION_TASK_PARTY_2.to_string(),
- FUSION_TASK_DATA_2.to_string(),
- ).unwrap(),
+ client
+ .enforce_data_deletion(
+ FUSION_TASK_PARTY_2.to_string(),
+ FUSION_TASK_DATA_2.to_string(),
+ )
+ .unwrap(),
true,
);
assert_eq!(
- client.enforce_data_deletion(
- FUSION_TASK_PARTY_1.to_string(),
- FUSION_TASK_DATA_2.to_string(),
- ).unwrap(),
+ client
+ .enforce_data_deletion(
+ FUSION_TASK_PARTY_1.to_string(),
+ FUSION_TASK_DATA_2.to_string(),
+ )
+ .unwrap(),
false,
);
assert_eq!(
- client.enforce_script_deletion(
- FUSION_TASK_PARTY_1.to_string(),
- FUSION_TASK_SCRIPT.to_string(),
- ).unwrap(),
+ client
+ .enforce_script_deletion(
+ FUSION_TASK_PARTY_1.to_string(),
+ FUSION_TASK_SCRIPT.to_string(),
+ )
+ .unwrap(),
false,
);
assert_eq!(
- client.enforce_script_deletion(
- FUSION_TASK_SCRIPT_WRITER.to_string(),
- FUSION_TASK_SCRIPT.to_string(),
- ).unwrap(),
+ client
+ .enforce_script_deletion(
+ FUSION_TASK_SCRIPT_WRITER.to_string(),
+ FUSION_TASK_SCRIPT.to_string(),
+ )
+ .unwrap(),
true,
);
assert_eq!(
- client.enforce_script_deletion(
- IRRELEVANT_PARTY.to_string(),
- PUBLIC_SCRIPT.to_string(),
- ).unwrap(),
+ client
+ .enforce_script_deletion(IRRELEVANT_PARTY.to_string(), PUBLIC_SCRIPT.to_string(),)
+ .unwrap(),
false,
);
assert_eq!(
- client.enforce_script_deletion(
- PUBLIC_SCRIPT_WRITER.to_string(),
- PUBLIC_SCRIPT.to_string(),
- ).unwrap(),
+ client
+ .enforce_script_deletion(PUBLIC_SCRIPT_WRITER.to_string(), PUBLIC_SCRIPT.to_string(),)
+ .unwrap(),
true,
);
-
}
diff --git a/tests/functional_test/sgx_trusted_lib/src/tests/common_setup.rs b/tests/functional_test/sgx_trusted_lib/src/tests/common_setup.rs
index 92244f3..ff571d0 100644
--- a/tests/functional_test/sgx_trusted_lib/src/tests/common_setup.rs
+++ b/tests/functional_test/sgx_trusted_lib/src/tests/common_setup.rs
@@ -11,8 +11,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-use kms_client::KMSClient;
use acs_client::ACSClient;
+use kms_client::KMSClient;
use mesatee_core::config;
use tdfs_internal_client::TDFSClient;
use tms_internal_client::TMSClient;
@@ -36,4 +36,3 @@ pub(crate) fn setup_tms_internal_client() -> TMSClient {
let target = config::Internal::target_tms();
TMSClient::new(target).unwrap()
}
-
diff --git a/tests/functional_test/sgx_trusted_lib/src/tests/mod.rs b/tests/functional_test/sgx_trusted_lib/src/tests/mod.rs
index d8b9735..7c44305 100644
--- a/tests/functional_test/sgx_trusted_lib/src/tests/mod.rs
+++ b/tests/functional_test/sgx_trusted_lib/src/tests/mod.rs
@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+pub mod acs_test;
pub mod common_setup;
pub mod kms_test;
pub mod protected_fs_test;
pub mod tdfs_test;
pub mod tms_test;
-pub mod acs_test;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@mesatee.apache.org
For additional commands, e-mail: commits-help@mesatee.apache.org