Skip to content

Add cargo clippy lints to the CI #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2020
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
249 changes: 205 additions & 44 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ version = "0.1.0"
authors = ["Paul Howard <[email protected]>",
"Ionut Mihalcea <[email protected]>",
"Hugues de Valon <[email protected]>"]
description = "A language-agnostic API to secure services in a platform-agnostic way"
license = "Apache-2.0"
repository = "https://github.com/parallaxsecond/parsec"
readme = "README.md"
keywords = ["security", "service"]
categories = ["cryptography", "hardware-support"]
edition = "2018"

[[bin]]
name = "parsec"
path = "src/bin/main.rs"

[dependencies]
parsec-interface = { git = "https://github.com/parallaxsecond/parsec-interface-rs", tag = "0.6.0" }
parsec-interface = { git = "https://github.com/parallaxsecond/parsec-interface-rs", tag = "0.6.1" }
rand = "0.7.2"
base64 = "0.10.1"
uuid = "0.7.4"
Expand All @@ -33,7 +39,7 @@ derivative = "1.0.3"
arbitrary = { version = "0.4.0", features = ["derive"], optional = true }

[dev-dependencies]
parsec-client-test = { git = "https://github.com/parallaxsecond/parsec-client-test", tag = "0.1.13" }
parsec-client-test = { git = "https://github.com/parallaxsecond/parsec-client-test", tag = "0.1.14" }
num_cpus = "1.10.1"

[build-dependencies]
Expand Down
136 changes: 85 additions & 51 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![deny(
nonstandard_style,
const_err,
dead_code,
improper_ctypes,
non_shorthand_field_patterns,
no_mangle_generic_items,
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
private_in_public,
unconditional_recursion,
unused,
unused_allocation,
unused_comparisons,
unused_parens,
while_true,
missing_debug_implementations,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results,
missing_copy_implementations
)]
// This one is hard to avoid.
#![allow(clippy::multiple_crate_versions)]

use cargo_toml::{Manifest, Value};
use serde::Deserialize;
use std::env;
Expand Down Expand Up @@ -75,63 +105,67 @@ fn get_value_from_table<'a>(table: &'a Value, key: &str) -> Result<&'a Value> {
// parameters to the setup_mbed_crypto.sh script which clones and builds Mbed Crypto and create
// a static library.
fn setup_mbed_crypto(mbed_config: &MbedConfig, mbed_version: &str) -> Result<()> {
let mut run_script = ::std::process::Command::new(SETUP_MBED_SCRIPT_PATH);
run_script.arg(mbed_version).arg(
mbed_config
.mbed_path
.clone()
.unwrap_or(String::from(env::var("OUT_DIR").unwrap())),
);

let toolchain;
let mbed_compiler;
let mbed_archiver;
if std::env::var("TARGET").unwrap() == "aarch64-unknown-linux-gnu" {
toolchain = mbed_config
.aarch64_unknown_linux_gnu
.as_ref()
.ok_or_else(|| {
let (mbed_compiler, mbed_archiver) =
if std::env::var("TARGET").unwrap() == "aarch64-unknown-linux-gnu" {
let toolchain;
toolchain = mbed_config
.aarch64_unknown_linux_gnu
.as_ref()
.ok_or_else(|| {
Error::new(
ErrorKind::InvalidInput,
"The aarch64_unknown_linux_gnu subtable of mbed_config should exist",
)
})?;
(
toolchain
.mbed_compiler
.clone()
.unwrap_or_else(|| DEFAULT_ARM64_MBED_COMPILER.to_string()),
toolchain
.mbed_archiver
.clone()
.unwrap_or_else(|| DEFAULT_ARM64_MBED_ARCHIVER.to_string()),
)
} else {
let toolchain;
toolchain = mbed_config.native.as_ref().ok_or_else(|| {
Error::new(
ErrorKind::InvalidInput,
"The aarch64_unknown_linux_gnu subtable of mbed_config should exist",
"The native subtable of mbed_config should exist",
)
})?;
mbed_compiler = toolchain
.mbed_compiler
.clone()
.unwrap_or(DEFAULT_ARM64_MBED_COMPILER.to_string());
mbed_archiver = toolchain
.mbed_archiver
.clone()
.unwrap_or(DEFAULT_ARM64_MBED_ARCHIVER.to_string());
} else {
toolchain = mbed_config.native.as_ref().ok_or_else(|| {
Error::new(
ErrorKind::InvalidInput,
"The native subtable of mbed_config should exist",
(
toolchain
.mbed_compiler
.clone()
.unwrap_or_else(|| DEFAULT_NATIVE_MBED_COMPILER.to_string()),
toolchain
.mbed_archiver
.clone()
.unwrap_or_else(|| DEFAULT_NATIVE_MBED_ARCHIVER.to_string()),
)
})?;
mbed_compiler = toolchain
.mbed_compiler
.clone()
.unwrap_or(DEFAULT_NATIVE_MBED_COMPILER.to_string());
mbed_archiver = toolchain
.mbed_archiver
.clone()
.unwrap_or(DEFAULT_NATIVE_MBED_ARCHIVER.to_string());
}
};

run_script.arg(format!("CC={}", mbed_compiler));
run_script.arg(format!("AR={}", mbed_archiver));
let script_fail = |_| {
Err(Error::new(
ErrorKind::Other,
"setup_mbed_crypto.sh script failed",
))
};

if !run_script
if !::std::process::Command::new(SETUP_MBED_SCRIPT_PATH)
.arg(mbed_version)
.arg(
mbed_config
.mbed_path
.clone()
.unwrap_or_else(|| env::var("OUT_DIR").unwrap()),
)
.arg(format!("CC={}", mbed_compiler))
.arg(format!("AR={}", mbed_archiver))
.status()
.or_else(|_| {
Err(Error::new(
ErrorKind::Other,
"setup_mbed_crypto.sh script failed",
))
})?
.or_else(script_fail)?
.success()
{
Err(Error::new(
Expand All @@ -147,7 +181,7 @@ fn generate_mbed_bindings(mbed_config: &MbedConfig, mbed_version: &str) -> Resul
let mbed_include_dir = mbed_config
.mbed_path
.clone()
.unwrap_or(String::from(env::var("OUT_DIR").unwrap()))
.unwrap_or_else(|| env::var("OUT_DIR").unwrap())
+ "/mbed-crypto-"
+ mbed_version
+ "/include";
Expand Down Expand Up @@ -236,7 +270,7 @@ fn main() -> Result<()> {
"cargo:rustc-link-search=native={}/mbed-crypto-{}/library/",
mbed_config
.mbed_path
.unwrap_or(String::from(env::var("OUT_DIR").unwrap())),
.unwrap_or_else(|| env::var("OUT_DIR").unwrap()),
mbed_version,
);
println!("cargo:rustc-link-lib=static=mbedcrypto");
Expand Down
5 changes: 2 additions & 3 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
const_err,
dead_code,
improper_ctypes,
legacy_directory_ownership,
non_shorthand_field_patterns,
no_mangle_generic_items,
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
plugin_as_library,
private_in_public,
safe_extern_statics,
unconditional_recursion,
unused,
unused_allocation,
Expand All @@ -43,6 +40,8 @@
unused_results,
missing_copy_implementations
)]
// This one is hard to avoid.
#![allow(clippy::multiple_crate_versions)]

use log::info;
use parsec::utils::{ServiceBuilder, ServiceConfig};
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
const_err,
dead_code,
improper_ctypes,
legacy_directory_ownership,
non_shorthand_field_patterns,
no_mangle_generic_items,
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
plugin_as_library,
private_in_public,
safe_extern_statics,
unconditional_recursion,
unused,
unused_allocation,
Expand All @@ -43,6 +40,8 @@
unused_results,
missing_copy_implementations
)]
// This one is hard to avoid.
#![allow(clippy::multiple_crate_versions)]

pub mod authenticators;
pub mod back;
Expand Down
2 changes: 1 addition & 1 deletion tests/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ then
fi
if rustup component list | grep -q clippy
then
cargo clippy --all-targets $FEATURES -- -D clippy::all
cargo clippy --all-targets $FEATURES -- -D clippy::all -D clippy::cargo
fi

############################
Expand Down
30 changes: 30 additions & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,35 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![deny(
nonstandard_style,
const_err,
dead_code,
improper_ctypes,
non_shorthand_field_patterns,
no_mangle_generic_items,
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
private_in_public,
unconditional_recursion,
unused,
unused_allocation,
unused_comparisons,
unused_parens,
while_true,
missing_debug_implementations,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results,
missing_copy_implementations
)]
// This one is hard to avoid.
#![allow(clippy::multiple_crate_versions)]

mod all_providers;
mod per_provider;
2 changes: 1 addition & 1 deletion tests/per_provider/normal_tests/export_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn export_public_key() -> Result<()> {

client.create_rsa_sign_key(key_name.clone())?;

client.export_public_key(key_name)?;
let _ = client.export_public_key(key_name)?;

Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion tests/per_provider/provider_cfg/mbed-crypto/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y git make gcc python3 python curl wget libgcc1 && \
# These libraries are needed for bindgen as it uses libclang.so
apt-get install -y clang libclang-dev
apt-get install -y clang libclang-dev && \
# Needed for Open SSL
apt-get install -y pkg-config libssl-dev

WORKDIR /tmp
RUN wget https://github.com/ARMmbed/mbed-crypto/archive/mbedcrypto-2.0.0.tar.gz
Expand Down