diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2be60ed..83f9698 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -89,7 +89,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: -- -D warnings + args: --all-targets -- -D warnings format: diff --git a/src/group/tests.rs b/src/group/tests.rs index c2ef057..5a130a3 100644 --- a/src/group/tests.rs +++ b/src/group/tests.rs @@ -36,10 +36,7 @@ fn test_group_properties() -> Result<(), InternalError> { fn test_identity_element_error() -> Result<(), InternalError> { let identity = CS::Group::identity(); let result = CS::Group::from_element_slice(&identity.to_arr()); - assert!(match result { - Err(InternalError::PointError) => true, - _ => false, - }); + assert!(matches!(result, Err(InternalError::PointError))); Ok(()) } @@ -48,10 +45,7 @@ fn test_identity_element_error() -> Result<(), InternalError> { fn test_zero_scalar_error() -> Result<(), InternalError> { let zero_scalar = CS::Group::scalar_zero(); let result = CS::Group::from_scalar_slice(&CS::Group::scalar_as_bytes(zero_scalar)); - assert!(match result { - Err(InternalError::ZeroScalarError) => true, - _ => false, - }); + assert!(matches!(result, Err(InternalError::ZeroScalarError))); Ok(()) } diff --git a/src/tests/parser.rs b/src/tests/parser.rs index a53cf56..a5e42ca 100644 --- a/src/tests/parser.rs +++ b/src/tests/parser.rs @@ -85,7 +85,7 @@ fn parse_params(input: &str) -> String { // If line contains =, then if line.contains('=') { // Clear out any existing string and flush to params - if param.len() > 0 { + if !param.is_empty() { param += "\""; params.push(param); } @@ -97,11 +97,11 @@ fn parse_params(input: &str) -> String { param = format!(" \"{}\": \"{}", key, val); } else { let s = line.trim().to_string(); - if s.contains("~") || s.contains("#") { + if s.contains('~') || s.contains('#') { // Ignore comment lines continue; } - if s.len() > 0 { + if !s.is_empty() { param += &s; } } diff --git a/src/tests/voprf_test_vectors.rs b/src/tests/voprf_test_vectors.rs index 8d3e658..87b2684 100644 --- a/src/tests/voprf_test_vectors.rs +++ b/src/tests/voprf_test_vectors.rs @@ -40,14 +40,14 @@ fn populate_test_vectors(values: &JsonValue) -> VOPRFTestVectorParameters { seed: decode(values, "seed"), sksm: decode(values, "skSm"), pksm: decode(values, "pkSm"), - input: decode_vec(&values, "Input"), + input: decode_vec(values, "Input"), info: decode(values, "Info"), - blind: decode_vec(&values, "Blind"), - blinded_element: decode_vec(&values, "BlindedElement"), - evaluation_element: decode_vec(&values, "EvaluationElement"), + blind: decode_vec(values, "Blind"), + blinded_element: decode_vec(values, "BlindedElement"), + evaluation_element: decode_vec(values, "EvaluationElement"), proof: decode(values, "Proof"), proof_random_scalar: decode(values, "ProofRandomScalar"), - output: decode_vec(&values, "Output"), + output: decode_vec(values, "Output"), } } @@ -55,7 +55,7 @@ fn decode(values: &JsonValue, key: &str) -> Vec { values[key] .as_str() .and_then(|s| hex::decode(&s.to_string()).ok()) - .unwrap_or(vec![]) + .unwrap_or_default() } fn decode_vec(values: &JsonValue, key: &str) -> Vec> { @@ -240,7 +240,7 @@ fn test_verifiable_evaluate( let mut blinded_elements = vec![]; for blinded_element_bytes in ¶meters.blinded_element { - blinded_elements.push(BlindedElement::deserialize(&blinded_element_bytes)?); + blinded_elements.push(BlindedElement::deserialize(blinded_element_bytes)?); } let batch_evaluate_result = server.batch_evaluate( @@ -269,7 +269,7 @@ fn test_base_finalize( for i in 0..parameters.input.len() { let client = NonVerifiableClient::::from_data_and_blind( ¶meters.input[i], - &::from_scalar_slice(&GenericArray::clone_from_slice( + ::from_scalar_slice(&GenericArray::clone_from_slice( ¶meters.blind[i], ))?, ); @@ -296,10 +296,10 @@ fn test_verifiable_finalize( for i in 0..parameters.input.len() { let client = VerifiableClient::::from_data_and_blind( ¶meters.input[i], - &::from_scalar_slice(&GenericArray::clone_from_slice( + ::from_scalar_slice(&GenericArray::clone_from_slice( ¶meters.blind[i], ))?, - &::from_element_slice(&GenericArray::clone_from_slice( + ::from_element_slice(&GenericArray::clone_from_slice( ¶meters.blinded_element[i], ))?, ); diff --git a/src/voprf.rs b/src/voprf.rs index d73e897..793fa62 100644 --- a/src/voprf.rs +++ b/src/voprf.rs @@ -177,10 +177,10 @@ impl NonVerifiableClient { #[cfg(test)] /// Only used for test functions - pub fn from_data_and_blind(data: &[u8], blind: &::Scalar) -> Self { + pub fn from_data_and_blind(data: &[u8], blind: ::Scalar) -> Self { Self { data: data.to_vec(), - blind: blind.clone(), + blind, } } @@ -271,13 +271,13 @@ impl VerifiableClient { /// Only used for test functions pub fn from_data_and_blind( data: &[u8], - blind: &::Scalar, - blinded_element: &CS::Group, + blind: ::Scalar, + blinded_element: CS::Group, ) -> Self { Self { data: data.to_vec(), - blind: blind.clone(), - blinded_element: blinded_element.clone(), + blind, + blinded_element, } } @@ -447,14 +447,9 @@ impl VerifiableServer { /// Allows for implementations to specify an optional sequence of /// public bytes that must be agreed-upon by the client and server +#[derive(Default)] pub struct Metadata(pub Vec); -impl Default for Metadata { - fn default() -> Self { - Self(vec![]) - } -} - impl Metadata { /// Specifies no metadata (the default option) pub fn none() -> Self { @@ -902,13 +897,8 @@ mod tests { ) .unwrap(); let mut res2 = vec![]; - for i in 0..num_iterations { - let output = prf::( - &inputs[i][..], - server.get_private_key(), - info, - Mode::Verifiable, - ); + for input in inputs.iter().take(num_iterations) { + let output = prf::(&input[..], server.get_private_key(), info, Mode::Verifiable); res2.push(output); } assert_eq!(client_finalize_result.outputs, res2);