diff --git a/.cargo/config.toml b/.cargo/config.toml index 8bc12bb..b8b9fb9 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,3 @@ [alias] -t = "test --workspace --lib" \ No newline at end of file +t = "test --workspace --lib" +god-clippy = "clippy --fix -- -W clippy::pedantic -W clippy::nursery -W clippy::unwrap_used -W clippy::expect_used" \ No newline at end of file diff --git a/src/wf_core/crypted_buffer.rs b/src/wf_core/crypted_buffer.rs index 0f0e6da..299aab3 100644 --- a/src/wf_core/crypted_buffer.rs +++ b/src/wf_core/crypted_buffer.rs @@ -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 { @@ -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, @@ -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, } diff --git a/src/wf_core/edge_case_test.rs b/src/wf_core/edge_case_test.rs index d828721..3d95e3d 100644 --- a/src/wf_core/edge_case_test.rs +++ b/src/wf_core/edge_case_test.rs @@ -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", @@ -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", diff --git a/src/wf_core/error.rs b/src/wf_core/error.rs index ff902ac..13d2bf3 100644 --- a/src/wf_core/error.rs +++ b/src/wf_core/error.rs @@ -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") } } diff --git a/src/wf_core/message.rs b/src/wf_core/message.rs index d078006..36cac6c 100644 --- a/src/wf_core/message.rs +++ b/src/wf_core/message.rs @@ -45,8 +45,8 @@ impl Message { body: Vec, originator: Option, recipient: Option, - ) -> Message { - Message { + ) -> Self { + Self { message_code, header: header.into(), body: body.into(), @@ -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, @@ -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)) } @@ -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 { @@ -145,6 +145,6 @@ impl Message { impl From<&[T]> for Message { fn from(data: &[T]) -> Self { - Message::compile(data) + Self::compile(data) } } diff --git a/src/wf_core/message_feature_parity_tests.rs b/src/wf_core/message_feature_parity_tests.rs index 33dad8c..25f4a16 100644 --- a/src/wf_core/message_feature_parity_tests.rs +++ b/src/wf_core/message_feature_parity_tests.rs @@ -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![ @@ -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); @@ -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); diff --git a/src/wf_core/segment.rs b/src/wf_core/segment.rs index 7bb7432..beb8285 100644 --- a/src/wf_core/segment.rs +++ b/src/wf_core/segment.rs @@ -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 */ @@ -86,6 +86,6 @@ impl DerefMut for MessageSegment { impl From> for MessageSegment { fn from(fields: Vec) -> Self { - MessageSegment { fields } + Self { fields } } } diff --git a/src/wf_json/deserialize.rs b/src/wf_json/deserialize.rs index 6c95ee6..a038888 100644 --- a/src/wf_json/deserialize.rs +++ b/src/wf_json/deserialize.rs @@ -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(), }) } } diff --git a/src/wf_json/mod.rs b/src/wf_json/mod.rs index 2d28f6d..67c3c03 100644 --- a/src/wf_json/mod.rs +++ b/src/wf_json/mod.rs @@ -13,6 +13,6 @@ impl Message { pub fn deserialize_from_json>(json: T) -> Result { 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())) } }