Skip to content

Commit

Permalink
Merge pull request #106 from hug-dev/fix-clippy
Browse files Browse the repository at this point in the history
Fix latest clippy lints
  • Loading branch information
ionut-arm authored Apr 29, 2021
2 parents 90103c9 + 81a83da commit 76e20d8
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 66 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
//!# }
//!# let mut stream = MockWrite { buffer: Vec::new() };
//!use parsec_interface::operations::{Convert, NativeResult, psa_generate_key::Result};
//!use parsec_interface::requests::{ProviderID, Opcode, BodyType, Response, ResponseStatus};
//!use parsec_interface::requests::{ProviderId, Opcode, BodyType, Response, ResponseStatus};
//!use parsec_interface::requests::response::ResponseHeader;
//!use parsec_interface::operations_protobuf::ProtobufConverter;
//!
Expand All @@ -116,7 +116,7 @@
//!let result_body = converter.result_to_body(result).unwrap();
//!let response = Response {
//! header: ResponseHeader {
//! provider: ProviderID::MbedCrypto,
//! provider: ProviderId::MbedCrypto,
//! session: 0,
//! content_type: BodyType::Protobuf,
//! opcode: Opcode::PsaGenerateKey,
Expand Down Expand Up @@ -157,7 +157,7 @@
//!#
//!# let mut stream = MockWrite { buffer: Vec::new() };
//!use parsec_interface::operations::{Convert, NativeOperation};
//!use parsec_interface::requests::{Request, ProviderID, BodyType, AuthType, Opcode};
//!use parsec_interface::requests::{Request, ProviderId, BodyType, AuthType, Opcode};
//!use parsec_interface::requests::request::{RequestHeader, RequestAuth};
//!use parsec_interface::operations_protobuf::ProtobufConverter;
//!use parsec_interface::operations::ping::Operation;
Expand All @@ -166,7 +166,7 @@
//!let operation = NativeOperation::Ping(Operation {});
//!let request = Request {
//! header: RequestHeader {
//! provider: ProviderID::Core,
//! provider: ProviderId::Core,
//! session: 0,
//! content_type: BodyType::Protobuf,
//! accept_type: BodyType::Protobuf,
Expand Down
4 changes: 2 additions & 2 deletions src/operations/list_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
//!
//! Lists all keys belonging to the application.
use super::psa_key_attributes::Attributes;
use crate::requests::ProviderID;
use crate::requests::ProviderId;

/// Structure holding the basic information for a key in the application for client discovery.
#[derive(Debug, Clone, PartialEq)]
pub struct KeyInfo {
/// The ID of the associated provider.
pub provider_id: ProviderID,
pub provider_id: ProviderId,
/// The name of the key.
pub name: String,
/// The key attributes.
Expand Down
4 changes: 2 additions & 2 deletions src/operations/list_opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
//!
//! List the opcodes supported by the provider.

use crate::requests::{Opcode, ProviderID};
use crate::requests::{Opcode, ProviderId};
use std::collections::HashSet;

/// Native object for opcode listing operation.
#[derive(Copy, Clone, Debug)]
pub struct Operation {
/// Provider for which the supported opcodes are requsted.
pub provider_id: ProviderID,
pub provider_id: ProviderId,
}

/// Native object for opcode listing result.
Expand Down
4 changes: 2 additions & 2 deletions src/operations/list_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! # ListProviders operation
//!
//! List the providers available in the service, with some information.
use crate::requests::ProviderID;
use crate::requests::ProviderId;
use std::cmp::Eq;
pub use uuid::Uuid;

Expand All @@ -24,7 +24,7 @@ pub struct ProviderInfo {
/// Provider implementation version revision number.
pub version_rev: u32,
/// Provider ID to use on the wire protocol to communicate with this provider.
pub id: ProviderID,
pub id: ProviderId,
}

/// Native object for provider listing operation.
Expand Down
18 changes: 9 additions & 9 deletions src/operations_protobuf/convert_list_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::generated_ops::list_keys::{
KeyInfo as KeyInfoProto, Operation as OperationProto, Result as ResultProto,
};
use crate::operations::list_keys::{KeyInfo, Operation, Result};
use crate::requests::{ProviderID, ResponseStatus};
use crate::requests::{ProviderId, ResponseStatus};
use log::error;
use num::FromPrimitive;
use std::convert::{TryFrom, TryInto};
Expand All @@ -29,7 +29,7 @@ impl TryFrom<KeyInfoProto> for KeyInfo {
type Error = ResponseStatus;

fn try_from(proto_info: KeyInfoProto) -> std::result::Result<Self, Self::Error> {
let id: ProviderID = match FromPrimitive::from_u32(proto_info.provider_id) {
let id: ProviderId = match FromPrimitive::from_u32(proto_info.provider_id) {
Some(id) => id,
None => return Err(ResponseStatus::ProviderDoesNotExist),
};
Expand Down Expand Up @@ -98,7 +98,7 @@ mod test {
use crate::operations::psa_algorithm::{Algorithm, AsymmetricSignature, Hash};
use crate::operations::psa_key_attributes::{self, Attributes, Lifetime, Policy, UsageFlags};
use crate::operations::{NativeOperation, NativeResult};
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode, ProviderID};
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode, ProviderId};
use std::convert::TryInto;

static CONVERTER: ProtobufConverter = ProtobufConverter {};
Expand Down Expand Up @@ -134,7 +134,7 @@ mod test {

let key_attrs_proto: KeyAttributesProto = key_attrs.try_into().unwrap();
let key_info = KeyInfoProto {
provider_id: ProviderID::MbedCrypto as u32,
provider_id: ProviderId::MbedCrypto as u32,
name: String::from("Some Key Name"),
attributes: Some(key_attrs_proto),
};
Expand All @@ -144,7 +144,7 @@ mod test {

assert_eq!(resp.keys.len(), 1);
assert_eq!(resp.keys[0].name, "Some Key Name");
assert_eq!(resp.keys[0].provider_id, ProviderID::MbedCrypto);
assert_eq!(resp.keys[0].provider_id, ProviderId::MbedCrypto);
assert_eq!(resp.keys[0].attributes, key_attrs);
}

Expand Down Expand Up @@ -176,7 +176,7 @@ mod test {
},
};
let key_info = KeyInfo {
provider_id: ProviderID::MbedCrypto,
provider_id: ProviderId::MbedCrypto,
name: String::from("Foo"),
attributes: key_attributes,
};
Expand All @@ -186,7 +186,7 @@ mod test {
let key_attributes_proto: KeyAttributesProto = key_attributes.try_into().unwrap();

assert_eq!(proto.keys.len(), 1);
assert_eq!(proto.keys[0].provider_id, ProviderID::MbedCrypto as u32);
assert_eq!(proto.keys[0].provider_id, ProviderId::MbedCrypto as u32);
assert_eq!(proto.keys[0].name, "Foo");
assert_eq!(proto.keys[0].attributes, Some(key_attributes_proto));
}
Expand Down Expand Up @@ -242,7 +242,7 @@ mod test {
fn result_list_keys_from_native() {
let mut list_keys = Result { keys: Vec::new() };
let key_info = KeyInfo {
provider_id: ProviderID::MbedCrypto,
provider_id: ProviderId::MbedCrypto,
name: String::from("Bar"),
attributes: Attributes {
lifetime: Lifetime::Persistent,
Expand Down Expand Up @@ -281,7 +281,7 @@ mod test {
fn list_keys_result_e2e() {
let mut list_keys = Result { keys: Vec::new() };
let key_info = KeyInfo {
provider_id: ProviderID::MbedCrypto,
provider_id: ProviderId::MbedCrypto,
name: String::from("Baz"),
attributes: Attributes {
lifetime: Lifetime::Persistent,
Expand Down
6 changes: 3 additions & 3 deletions src/operations_protobuf/convert_list_opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod test {
use crate::operations::{
list_opcodes::Operation, list_opcodes::Result, NativeOperation, NativeResult,
};
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode, ProviderID};
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode, ProviderId};
use std::collections::HashSet;
use std::convert::TryInto;

Expand Down Expand Up @@ -109,7 +109,7 @@ mod test {
#[test]
fn op_list_opcodes_from_native() {
let list_opcodes = Operation {
provider_id: ProviderID::Core,
provider_id: ProviderId::Core,
};
let body = CONVERTER
.operation_to_body(NativeOperation::ListOpcodes(list_opcodes))
Expand All @@ -120,7 +120,7 @@ mod test {
#[test]
fn op_list_opcodes_e2e() {
let list_opcodes = Operation {
provider_id: ProviderID::Pkcs11,
provider_id: ProviderId::Pkcs11,
};
let req_body = CONVERTER
.operation_to_body(NativeOperation::ListOpcodes(list_opcodes))
Expand Down
14 changes: 7 additions & 7 deletions src/operations_protobuf/convert_list_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::generated_ops::list_providers::{
Operation as OperationProto, ProviderInfo as ProviderInfoProto, Result as ResultProto,
};
use crate::operations::list_providers::{Operation, ProviderInfo, Result};
use crate::requests::{ProviderID, ResponseStatus};
use crate::requests::{ProviderId, ResponseStatus};
use num::FromPrimitive;
use std::convert::{TryFrom, TryInto};
use uuid::Uuid;
Expand Down Expand Up @@ -35,7 +35,7 @@ impl TryFrom<ProviderInfoProto> for ProviderInfo {
Ok(provider_uuid) => provider_uuid,
Err(_) => return Err(ResponseStatus::WrongProviderUuid),
};
let id: ProviderID = match FromPrimitive::from_u32(proto_info.id) {
let id: ProviderId = match FromPrimitive::from_u32(proto_info.id) {
Some(id) => id,
None => return Err(ResponseStatus::ProviderDoesNotExist),
};
Expand Down Expand Up @@ -103,7 +103,7 @@ mod test {
use super::super::{Convert, ProtobufConverter};
use crate::operations::list_providers::{Operation, ProviderInfo, Result};
use crate::operations::{NativeOperation, NativeResult};
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode, ProviderID};
use crate::requests::{request::RequestBody, response::ResponseBody, Opcode, ProviderId};
use std::convert::TryInto;
use uuid::Uuid;

Expand Down Expand Up @@ -134,7 +134,7 @@ mod test {
assert_eq!(resp.providers[0].version_maj, 0);
assert_eq!(resp.providers[0].version_min, 1);
assert_eq!(resp.providers[0].version_rev, 0);
assert_eq!(resp.providers[0].id, ProviderID::MbedCrypto);
assert_eq!(resp.providers[0].id, ProviderId::MbedCrypto);
}

#[test]
Expand All @@ -149,7 +149,7 @@ mod test {
version_maj: 0,
version_min: 1,
version_rev: 0,
id: ProviderID::MbedCrypto,
id: ProviderId::MbedCrypto,
};
resp.providers.push(provider_info);

Expand Down Expand Up @@ -226,7 +226,7 @@ mod test {
version_maj: 0,
version_min: 1,
version_rev: 0,
id: ProviderID::MbedCrypto,
id: ProviderId::MbedCrypto,
};
list_providers.providers.push(provider_info);

Expand All @@ -248,7 +248,7 @@ mod test {
version_maj: 0,
version_min: 1,
version_rev: 0,
id: ProviderID::MbedCrypto,
id: ProviderId::MbedCrypto,
};
list_providers.providers.push(provider_info);

Expand Down
24 changes: 12 additions & 12 deletions src/operations_protobuf/generated_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,78 +49,78 @@ use std::convert::TryFrom;
impl TryFrom<i32> for Cipher {
type Error = ResponseStatus;
fn try_from(cipher_val: i32) -> Result<Self> {
Ok(Cipher::from_i32(cipher_val).ok_or_else(|| {
Cipher::from_i32(cipher_val).ok_or_else(|| {
error!(
"Value {} not recognised as a valid cipher algorithm encoding.",
cipher_val
);
ResponseStatus::InvalidEncoding
})?)
})
}
}

impl TryFrom<i32> for Hash {
type Error = ResponseStatus;
fn try_from(hash_val: i32) -> Result<Self> {
Ok(Hash::from_i32(hash_val).ok_or_else(|| {
Hash::from_i32(hash_val).ok_or_else(|| {
error!(
"Value {} not recognised as a valid hash algorithm encoding.",
hash_val
);
ResponseStatus::InvalidEncoding
})?)
})
}
}

impl TryFrom<i32> for AeadWithDefaultLengthTag {
type Error = ResponseStatus;
fn try_from(aead_val: i32) -> Result<Self> {
Ok(AeadWithDefaultLengthTag::from_i32(aead_val).ok_or_else(|| {
AeadWithDefaultLengthTag::from_i32(aead_val).ok_or_else(|| {
error!(
"Value {} not recognised as a valid AEAD with default tag length algorithm encoding.",
aead_val
);
ResponseStatus::InvalidEncoding
})?)
})
}
}

impl TryFrom<i32> for Raw {
type Error = ResponseStatus;
fn try_from(key_agreement_val: i32) -> Result<Self> {
Ok(Raw::from_i32(key_agreement_val).ok_or_else(|| {
Raw::from_i32(key_agreement_val).ok_or_else(|| {
error!(
"Value {} not recognised as a valid raw key agreement algorithm encoding.",
key_agreement_val
);
ResponseStatus::InvalidEncoding
})?)
})
}
}

impl TryFrom<i32> for EccFamily {
type Error = ResponseStatus;
fn try_from(ecc_family_val: i32) -> Result<Self> {
Ok(EccFamily::from_i32(ecc_family_val).ok_or_else(|| {
EccFamily::from_i32(ecc_family_val).ok_or_else(|| {
error!(
"Value {} not recognised as a valid ECC family encoding.",
ecc_family_val
);
ResponseStatus::InvalidEncoding
})?)
})
}
}

impl TryFrom<i32> for DhFamily {
type Error = ResponseStatus;
fn try_from(dh_family_val: i32) -> Result<Self> {
Ok(DhFamily::from_i32(dh_family_val).ok_or_else(|| {
DhFamily::from_i32(dh_family_val).ok_or_else(|| {
error!(
"Value {} not recognised as a valid DH family encoding.",
dh_family_val
);
ResponseStatus::InvalidEncoding
})?)
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/operations_protobuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod convert_psa_generate_random;
mod convert_psa_raw_key_agreement;

#[rustfmt::skip]
#[allow(unused_qualifications, missing_copy_implementations, clippy::pedantic, clippy::module_inception)]
#[allow(unused_qualifications, missing_copy_implementations, clippy::pedantic, clippy::module_inception, clippy::upper_case_acronyms)]
mod generated_ops;

use crate::operations::{Convert, NativeOperation, NativeResult};
Expand Down
18 changes: 9 additions & 9 deletions src/requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::fmt;
#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
#[derive(FromPrimitive, PartialEq, Eq, Hash, Copy, Clone, Debug)]
#[repr(u8)]
pub enum ProviderID {
pub enum ProviderId {
/// Provider to use for core Parsec operations.
Core = 0,
/// Provider using Mbed Crypto software library.
Expand All @@ -41,20 +41,20 @@ pub enum ProviderID {
CryptoAuthLib = 5,
}

impl fmt::Display for ProviderID {
impl fmt::Display for ProviderId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ProviderID::Core => write!(f, "Core provider"),
ProviderID::MbedCrypto => write!(f, "Mbed Crypto provider"),
ProviderID::Pkcs11 => write!(f, "PKCS #11 provider"),
ProviderID::Tpm => write!(f, "TPM provider"),
ProviderID::TrustedService => write!(f, "Trusted Service provider"),
ProviderID::CryptoAuthLib => write!(f, "CryptoAuthentication Library provider"),
ProviderId::Core => write!(f, "Core provider"),
ProviderId::MbedCrypto => write!(f, "Mbed Crypto provider"),
ProviderId::Pkcs11 => write!(f, "PKCS #11 provider"),
ProviderId::Tpm => write!(f, "TPM provider"),
ProviderId::TrustedService => write!(f, "Trusted Service provider"),
ProviderId::CryptoAuthLib => write!(f, "CryptoAuthentication Library provider"),
}
}
}

impl TryFrom<u8> for ProviderID {
impl TryFrom<u8> for ProviderId {
type Error = ResponseStatus;

fn try_from(provider_id: u8) -> ::std::result::Result<Self, Self::Error> {
Expand Down
Loading

0 comments on commit 76e20d8

Please sign in to comment.