Skip to content

Commit

Permalink
Merge pull request #87 from hug-dev/deny
Browse files Browse the repository at this point in the history
Deny compilation for some rustc lints
  • Loading branch information
hug-dev authored Jan 15, 2020
2 parents 7d16d7d + 3bf5ac7 commit e1df287
Show file tree
Hide file tree
Showing 20 changed files with 209 additions and 69 deletions.
23 changes: 21 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ log = { version = "0.4.8", features = ["serde"] }
pkcs11 = { version = "0.4.0", optional = true }
picky-asn1-der = { version = "0.2.0", optional = true }
picky-asn1 = { version = "0.1.0", optional = true }
tss-esapi = { git = "https://github.com/parallaxsecond/rust-tss-esapi", tag = "0.4.0", optional = true }
tss-esapi = { git = "https://github.com/parallaxsecond/rust-tss-esapi", tag = "0.5.0", optional = true }
bincode = "1.1.4"
structopt = "0.3.5"
derivative = "1.0.3"

[dev-dependencies]
parsec-client-test = { git = "https://github.com/parallaxsecond/parsec-client-test", tag = "0.1.8" }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Read the Parsec documentation [online](https://parallaxsecond.github.io/parsec-b

## Disclaimer

PARSEC is a new open source project and is under development. This code repository is being made
Parsec is a new open source project and is under development. This code repository is being made
available so that the developer community can learn and give feedback about the new interfaces and the concepts of platform-agnostic security.
The implementation that is provided is suitable for exploratory testing and experimentation only.
This test implementation does not offer any tangible security benefits and therefore is not
Expand Down Expand Up @@ -102,6 +102,7 @@ This project uses the following third party crates:
* picky-asn1 (MIT and Apache-2.0)
* bincode (MIT)
* structopt (MIT and Apache-2.0)
* derivative (MIT and Apache-2.0)

This project uses the following third party libraries:
* [Mbed Crypto](https://github.com/ARMmbed/mbed-crypto) (Apache-2.0)
3 changes: 2 additions & 1 deletion src/authenticators/simple_authenticator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use parsec_interface::requests::request::RequestAuth;
use parsec_interface::requests::{ResponseStatus, Result};
use std::str;

#[derive(Copy, Clone, Debug)]
pub struct SimpleAuthenticator;

impl Authenticate for SimpleAuthenticator {
Expand Down Expand Up @@ -63,7 +64,7 @@ mod test {
#[should_panic(expected = "Failed to authenticate")]
fn failed_authentication() {
let authenticator = SimpleAuthenticator {};
authenticator
let _ = authenticator
.authenticate(&RequestAuth::from_bytes(vec![0xff; 5]))
.expect("Failed to authenticate");
}
Expand Down
11 changes: 10 additions & 1 deletion src/back/backend_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
use crate::authenticators::ApplicationName;
use crate::providers::Provide;
use derivative::Derivative;
use parsec_interface::operations::Convert;
use parsec_interface::operations::{NativeOperation, NativeResult};
use parsec_interface::requests::{
Expand All @@ -26,9 +27,14 @@ use parsec_interface::requests::{BodyType, ProviderID};
///
/// It also provides assessment capabilities, letting the dispatcher know if
/// it can process a request.

#[derive(Derivative)]
#[derivative(Debug)]
pub struct BackEndHandler {
// Send and Sync are required for Arc<FrontEndHandler> to be Send.
#[derivative(Debug = "ignore")]
provider: Box<dyn Provide + Send + Sync>,
#[derivative(Debug = "ignore")]
converter: Box<dyn Convert + Send + Sync>,
provider_id: ProviderID,
content_type: BodyType,
Expand Down Expand Up @@ -158,9 +164,12 @@ impl BackEndHandler {
}
}

#[derive(Default)]
#[derive(Default, Derivative)]
#[derivative(Debug)]
pub struct BackEndHandlerBuilder {
#[derivative(Debug = "ignore")]
provider: Option<Box<dyn Provide + Send + Sync>>,
#[derivative(Debug = "ignore")]
converter: Option<Box<dyn Convert + Send + Sync>>,
provider_id: Option<ProviderID>,
content_type: Option<BodyType>,
Expand Down
5 changes: 3 additions & 2 deletions src/back/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::collections::HashMap;
///
/// As such, it owns all the backend handlers and attempts to match
/// the fields in the request header to the properties of the handlers.
#[derive(Debug)]
pub struct Dispatcher {
backends: HashMap<ProviderID, BackEndHandler>,
}
Expand Down Expand Up @@ -52,7 +53,7 @@ impl Dispatcher {
}
}

#[derive(Default)]
#[derive(Debug, Default)]
pub struct DispatcherBuilder {
backends: Option<HashMap<ProviderID, BackEndHandler>>,
}
Expand All @@ -68,7 +69,7 @@ impl DispatcherBuilder {
backend_handler: BackEndHandler,
) -> Self {
let mut backends = self.backends.unwrap_or_default();
backends.insert(provider_id, backend_handler);
let _ = backends.insert(provider_id, backend_handler);
self.backends = Some(backends);

self
Expand Down
46 changes: 39 additions & 7 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@
// 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,
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,
unused_comparisons,
unused_parens,
while_true,
missing_debug_implementations,
//TODO: activate this!
//missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results,
missing_copy_implementations
)]

use log::info;
use parsec::utils::{ServiceBuilder, ServiceConfig};
use signal_hook::{flag, SIGHUP, SIGTERM};
Expand Down Expand Up @@ -49,8 +81,8 @@ fn main() -> Result<(), Error> {
let kill_signal = Arc::new(AtomicBool::new(false));
// Register a boolean set to true when the SIGHUP signal is received.
let reload_signal = Arc::new(AtomicBool::new(false));
flag::register(SIGTERM, kill_signal.clone())?;
flag::register(SIGHUP, reload_signal.clone())?;
let _ = flag::register(SIGTERM, kill_signal.clone())?;
let _ = flag::register(SIGHUP, reload_signal.clone())?;

let mut config_file =
::std::fs::read_to_string(opts.config.clone()).expect("Failed to read configuration file");
Expand All @@ -67,7 +99,7 @@ fn main() -> Result<(), Error> {
// outlive the run function. It is needed to give them all ownership of the front end handler
// through an Arc.
let mut front_end_handler = Arc::from(front_end_handler);
let mut listener = ServiceBuilder::start_listener(&config.listener);
let mut listener = ServiceBuilder::start_listener(config.listener);
let mut threadpool = ServiceBuilder::build_threadpool(config.core_settings.thread_pool_size);

// Notify systemd that the daemon is ready, the start command will block until this point.
Expand Down Expand Up @@ -96,7 +128,7 @@ fn main() -> Result<(), Error> {
Arc::from(ServiceBuilder::build_service(&config).ok_or_else(|| {
Error::new(ErrorKind::Other, "Parsec can not be configured.")
})?);
listener = ServiceBuilder::start_listener(&config.listener);
listener = ServiceBuilder::start_listener(config.listener);
threadpool = ServiceBuilder::build_threadpool(config.core_settings.thread_pool_size);

let _ = sd_notify::notify(false, &[sd_notify::NotifyState::Ready]);
Expand Down Expand Up @@ -130,12 +162,12 @@ fn log_setup(config: &ServiceConfig) {
let mut env_log_builder = env_logger::builder();

if let Some(level) = config.core_settings.log_level {
env_log_builder.filter_level(level);
let _ = env_log_builder.filter_level(level);
}
if let Some(true) = config.core_settings.log_timestamp {
env_log_builder.format_timestamp_millis();
let _ = env_log_builder.format_timestamp_millis();
} else {
env_log_builder.format_timestamp(None);
let _ = env_log_builder.format_timestamp(None);
}
env_log_builder.init();
}
3 changes: 2 additions & 1 deletion src/front/domain_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static SOCKET_PATH: &str = "/tmp/security-daemon-socket";
/// Holds references to a `UnixListener`.
///
/// Only works on Unix systems.
#[derive(Debug)]
pub struct DomainSocketListener {
listener: UnixListener,
timeout: Duration,
Expand Down Expand Up @@ -112,7 +113,7 @@ impl Listen for DomainSocketListener {
}
}

#[derive(Default)]
#[derive(Copy, Clone, Debug, Default)]
pub struct DomainSocketListenerBuilder {
timeout: Option<Duration>,
}
Expand Down
12 changes: 9 additions & 3 deletions src/front/front_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
use crate::authenticators::Authenticate;
use crate::back::dispatcher::Dispatcher;
use derivative::Derivative;
use log::{error, info};
use parsec_interface::requests::AuthType;
use parsec_interface::requests::ResponseStatus;
Expand All @@ -25,9 +26,12 @@ use std::io::{Read, Write};
/// from/to the stream provided by the listener.
///
/// Requests are passed forward to the `Dispatcher`.
#[derive(Derivative)]
#[derivative(Debug)]
pub struct FrontEndHandler {
dispatcher: Dispatcher,
// Send and Sync are required for Arc<FrontEndHandler> to be Send.
#[derivative(Debug = "ignore")]
authenticators: HashMap<AuthType, Box<dyn Authenticate + Send + Sync>>,
}

Expand Down Expand Up @@ -82,9 +86,11 @@ impl FrontEndHandler {
}
}

#[derive(Default)]
#[derive(Default, Derivative)]
#[derivative(Debug)]
pub struct FrontEndHandlerBuilder {
dispatcher: Option<Dispatcher>,
#[derivative(Debug = "ignore")]
authenticators: Option<HashMap<AuthType, Box<dyn Authenticate + Send + Sync>>>,
}

Expand All @@ -108,11 +114,11 @@ impl FrontEndHandlerBuilder {
) -> Self {
match &mut self.authenticators {
Some(authenticators) => {
authenticators.insert(auth_type, authenticator);
let _ = authenticators.insert(auth_type, authenticator);
}
None => {
let mut map = HashMap::new();
map.insert(auth_type, authenticator);
let _ = map.insert(auth_type, authenticator);
self.authenticators = Some(map);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/front/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ pub trait ReadWrite: std::io::Read + std::io::Write {}
// Automatically implements ReadWrite for all types that implement Read and Write.
impl<T: std::io::Read + std::io::Write> ReadWrite for T {}

#[derive(Deserialize, Debug)]
#[derive(Copy, Clone, Deserialize, Debug)]
pub enum ListenerType {
DomainSocket,
}

#[derive(Deserialize, Debug)]
#[derive(Copy, Clone, Deserialize, Debug)]
pub struct ListenerConfig {
pub listener_type: ListenerType,
pub timeout: u64,
Expand Down
2 changes: 1 addition & 1 deletion src/key_id_managers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::fmt;

pub mod on_disk_manager;

#[derive(Deserialize, Debug)]
#[derive(Copy, Clone, Deserialize, Debug)]
pub enum KeyIdManagerType {
OnDisk,
}
Expand Down
Loading

0 comments on commit e1df287

Please sign in to comment.