From 7328b37166fdffcc74cf11763084d67029945df9 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Thu, 20 Feb 2020 07:37:07 +0100 Subject: [PATCH] fix some warnings and clippy errors --- host_calls/src/remote_attestation.rs | 13 +++++++------ runtime/src/lib.rs | 3 +++ runtime/src/substratee_registry.rs | 7 +++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/host_calls/src/remote_attestation.rs b/host_calls/src/remote_attestation.rs index ea4978d..c8cc1ec 100644 --- a/host_calls/src/remote_attestation.rs +++ b/host_calls/src/remote_attestation.rs @@ -28,7 +28,7 @@ use sgx_types::*; use sgx_ucrypto::SgxEccHandle; use super::{SgxReport, SgxStatus}; -use codec::{Decode, Encode}; +use codec::Encode; type SignatureAlgorithms = &'static [&'static webpki::SignatureAlgorithm]; @@ -50,12 +50,12 @@ pub const IAS_REPORT_CA: &[u8] = include_bytes!("../AttestationReportSigningCACe // prevents panics in case of index out of bounds fn safe_indexing(data: &[u8], start: usize, end: usize) -> Result<&[u8], &'static str> { - if (start > end) { return Err("Illegal indexing")} - if (data.len() < end) { return Err("Index would be out of bounds")} + if start > end { return Err("Illegal indexing")} + if data.len() < end { return Err("Index would be out of bounds")} Ok(&data[start..end]) } fn safe_indexing_one(data: &[u8], idx: usize) -> Result { - if (data.len() < idx) { return Err("Index would be out of bounds")} + if data.len() < idx { return Err("Index would be out of bounds")} Ok(data[idx]) } @@ -271,7 +271,7 @@ pub fn verify_mra_cert( let _result = ecc_handle.open(); let mut ephemeral_pub = sgx_ec256_public_t::default(); - if (pub_k.len() != 64) { return Err("wrong size of signer ephemeral public key") } + if pub_k.len() != 64 { return Err("wrong size of signer ephemeral public key") } ephemeral_pub.gx.copy_from_slice(&pub_k[..32]); ephemeral_pub.gy.copy_from_slice(&pub_k[32..]); // key is stored in little-endian order in RA report. reverse! @@ -279,7 +279,7 @@ pub fn verify_mra_cert( ephemeral_pub.gy.reverse(); let mut signature = sgx_ec256_signature_t::default(); - if (xt_signer_attn.len() != 16) { return Err("wrong size of signer attestation signature") } + if xt_signer_attn.len() != 16 { return Err("wrong size of signer attestation signature") } signature.x.copy_from_slice(&xt_signer_attn[..8]); signature.y.copy_from_slice(&xt_signer_attn[8..]); @@ -311,6 +311,7 @@ pub fn verify_mra_cert( #[cfg(test)] mod tests { use super::*; + use codec::Decode; // reproduce with "substratee_worker dump_ra" const TEST1_CERT: &[u8] = include_bytes!("../test/test_ra_cert_MRSIGNER1_MRENCLAVE1.der"); const TEST2_CERT: &[u8] = include_bytes!("../test/test_ra_cert_MRSIGNER2_MRENCLAVE2.der"); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 1605a39..a3930df 100755 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -4,6 +4,9 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] +//SCS: remove this once clippy rules are aligned with substrate +#![warn(clippy::not_unsafe_ptr_arg_deref)] + // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); diff --git a/runtime/src/substratee_registry.rs b/runtime/src/substratee_registry.rs index 14f5212..a20422d 100644 --- a/runtime/src/substratee_registry.rs +++ b/runtime/src/substratee_registry.rs @@ -17,7 +17,7 @@ use codec::{Decode, Encode}; use host_calls::runtime_interfaces::verify_ra_report; -use host_calls::{SgxReport, SgxStatus}; +use host_calls::SgxReport; use rstd::prelude::*; use rstd::str; use runtime_io::misc::print_utf8; @@ -31,7 +31,6 @@ pub trait Trait: balances::Trait { const MAX_RA_REPORT_LEN: usize = 4096; const MAX_URL_LEN: usize = 256; -const RA_SIGNER_ATTN_LEN: usize = 64; #[derive(Encode, Decode, Default, Copy, Clone, PartialEq)] #[cfg_attr(feature = "std", derive(Debug))] @@ -131,7 +130,7 @@ decl_module! { } pub fn call_worker(origin, request: Request) -> Result { - let sender = ensure_signed(origin)?; + let _sender = ensure_signed(origin)?; Self::deposit_event(RawEvent::Forwarded(request)); Ok(()) } @@ -156,7 +155,7 @@ impl Module { fn register_verified_enclave(sender: &T::AccountId, report: &SgxReport, url: &Vec) -> Result { let enclave = Enclave { pubkey: sender.clone(), - mr_enclave: report.mr_enclave.clone(), + mr_enclave: report.mr_enclave, timestamp: report.timestamp, url: url.clone(), };