Skip to content
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

Use-clippy-features #65

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[alias]
t = "test --workspace --lib"
t = "test --workspace --lib"
god-clippy = "clippy --fix -- -W clippy::pedantic -W clippy::nursery -W clippy::unwrap_used -W clippy::expect_used"
6 changes: 3 additions & 3 deletions src/wf_core/crypted_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use wf_field::definitions::WhiteflagFields;

/// everything is encrypted in a whiteflag buffer except for the first few header fields
///
/// Prefix, Version, and EncryptionIndicator do not get encrypted
/// Prefix, Version, and `EncryptionIndicator` do not get encrypted
/// Therefore, when encrypting, the buffer is split and the second half gets encrypted
/// Likewise, when decrypting, the buffer is split and the second half gets decrypted
pub struct CryptedBuffer {
Expand All @@ -18,7 +18,7 @@ pub enum CryptMode {
}

impl CryptedBuffer {
/// creates a new [`CryptedBuffer`] by splitting the given buffer at the EncryptionHeader bit index
/// creates a new [`CryptedBuffer`] by splitting the given buffer at the `EncryptionHeader` bit index
pub fn new(buffer: WhiteflagBuffer) -> Self {
Self::new_split_at(
buffer,
Expand All @@ -33,7 +33,7 @@ impl CryptedBuffer {
let unencrypted_first_half = buffer.extract_bits(0, split_at);
let encrypted_second_half = buffer.extract_bits_from(split_at);

CryptedBuffer {
Self {
unencrypted_first_half,
encrypted_second_half,
}
Expand Down
8 changes: 4 additions & 4 deletions src/wf_core/edge_case_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::wf_core::message::Message;

mod test_message {
pub const SERIALIZED: &'static str = "WF101T33efb4e0cfa83122b242634254c1920a769d615dfcc4c670bb53eb6f12843c3aeM802013-08-31T04:29:15ZP00D00H00M22+30.79658-037.8260287653210042";
pub const SERIALIZED: &str = "WF101T33efb4e0cfa83122b242634254c1920a769d615dfcc4c670bb53eb6f12843c3aeM802013-08-31T04:29:15ZP00D00H00M22+30.79658-037.8260287653210042";
//pub const ENCODED: &'static str = "57463130aa19f7da7067d41891592131a12a60c9053b4eb0aefe6263385da9f5b789421e1d726c01009841882148a800000114c1e596006f04c050eca6420084";
pub const VALUES: &'static [&'static str] = &[
pub const VALUES: &[&str] = &[
"WF",
"1",
"0",
Expand All @@ -25,9 +25,9 @@ mod test_message {
}

mod request_signal_message {
pub const SERIALIZED: &'static str= "WF101Q13efb4e0cfa83122b242634254c1920a769d615dfcc4c670bb53eb6f12843c3ae802013-08-31T04:29:15ZP01D00H00M22+31.79658-033.826028799321000010022003";
pub const SERIALIZED: &str= "WF101Q13efb4e0cfa83122b242634254c1920a769d615dfcc4c670bb53eb6f12843c3ae802013-08-31T04:29:15ZP01D00H00M22+31.79658-033.826028799321000010022003";
//pub const ENCODED: &'static str = "";
pub const VALUES: &'static [&'static str] = &[
pub const VALUES: &[&str] = &[
"WF",
"1",
"0",
Expand Down
6 changes: 3 additions & 3 deletions src/wf_core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ impl std::error::Error for WhiteflagError {}
impl fmt::Display for WhiteflagError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
WhiteflagError::InvalidPattern => write!(f, "pattern was invalid"),
WhiteflagError::InvalidLength => write!(f, "length was too short"),
WhiteflagError::CannotRetrieveKey => {
Self::InvalidPattern => write!(f, "pattern was invalid"),
Self::InvalidLength => write!(f, "length was too short"),
Self::CannotRetrieveKey => {
write!(f, "cannot retrieve encryption key for method")
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/wf_core/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ impl Message {
body: Vec<Field>,
originator: Option<WhiteflagAccount>,
recipient: Option<WhiteflagAccount>,
) -> Message {
Message {
) -> Self {
Self {
message_code,
header: header.into(),
body: body.into(),
Expand All @@ -64,7 +64,7 @@ impl Message {
}

pub fn from_parser(parsed_message: Parser) -> Self {
Message::new(
Self::new(
parsed_message.code,
parsed_message.header,
parsed_message.body,
Expand All @@ -79,7 +79,7 @@ impl Message {
}

/// construct Message from a serialized string
pub fn deserialize(message: &str) -> Message {
pub fn deserialize(message: &str) -> Self {
Self::from_parser(builder_from_serialized(message))
}

Expand All @@ -105,7 +105,7 @@ impl Message {
) -> WhiteflagBuffer {
let encryption_indicator_index = 2_usize;
let encryption_indicator = &self.header[encryption_indicator_index]; // the encryption indicator is the 3rd index in the header
let method = WhiteflagEncryptionMethod::from_str(&encryption_indicator.get()).unwrap();
let method = WhiteflagEncryptionMethod::from_str(encryption_indicator.get()).unwrap();
let encoded: WhiteflagBuffer = self.encode().into();

match method {
Expand Down Expand Up @@ -145,6 +145,6 @@ impl Message {

impl<T: FieldValue> From<&[T]> for Message {
fn from(data: &[T]) -> Self {
Message::compile(data)
Self::compile(data)
}
}
6 changes: 3 additions & 3 deletions src/wf_core/message_feature_parity_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn message_encryption_1() {
)
.unwrap();

key.set_context(&address.to_byte_array());
key.set_context(address.to_byte_array());

//40aa85015d24e4601448c1ba8d7bf1aa
let iv = vec![
Expand Down Expand Up @@ -260,7 +260,7 @@ fn message_encryption_2() {
)
.unwrap();

key.set_context(&address.to_byte_array());
key.set_context(address.to_byte_array());

let iv = aes_tools::generate_random_buffer(16);
let cipher = key.aes_256_ctr_cipher(&iv);
Expand All @@ -285,7 +285,7 @@ fn message_encryption_3() {
)
.unwrap();

key.set_context(&address.to_byte_array());
key.set_context(address.to_byte_array());

let iv = aes_tools::generate_random_buffer(16);
let cipher = key.aes_256_ctr_cipher(&iv);
Expand Down
4 changes: 2 additions & 2 deletions src/wf_core/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl MessageSegment {
}

/// Returns the bit length up to and including the specified field, excluding the last variable length field if not set
/// field_index the index of the field up to which the segment length is calculated; negative index counts back from last field
/// `field_index` the index of the field up to which the segment length is calculated; negative index counts back from last field
/// returns the bit length of this segment up to and including the specified field, or 0 if the field does not exist
pub fn bit_length_of_field(&self, field_index: isize) -> usize {
/* converts potential negative index into a positive */
Expand Down Expand Up @@ -86,6 +86,6 @@ impl DerefMut for MessageSegment {

impl From<Vec<Field>> for MessageSegment {
fn from(fields: Vec<Field>) -> Self {
MessageSegment { fields }
Self { fields }
}
}
2 changes: 1 addition & 1 deletion src/wf_json/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'de> de::Visitor<'de> for FieldValuesVisitor {
sortable.sort_by_key(|p| p.0);

Ok(WhiteflagFieldValues {
fields: sortable.iter().map(|p| p.1.to_owned()).collect(),
fields: sortable.iter().map(|p| p.1.clone()).collect(),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wf_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ impl Message {
pub fn deserialize_from_json<T: AsRef<str>>(json: T) -> Result<Self, WhiteflagError> {
let message: WhiteflagFieldValues =
serde_json::from_str(json.as_ref()).map_err(WhiteflagError::Serde)?;
Ok(Message::compile(message.fields.as_ref()))
Ok(Self::compile(message.fields.as_ref()))
}
}