Use Clippy on test code too (#22)
This commit is contained in:
@@ -89,7 +89,7 @@ jobs:
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: -- -D warnings
|
||||
args: --all-targets -- -D warnings
|
||||
|
||||
|
||||
format:
|
||||
|
||||
+2
-8
@@ -36,10 +36,7 @@ fn test_group_properties() -> Result<(), InternalError> {
|
||||
fn test_identity_element_error<CS: CipherSuite>() -> 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<CS: CipherSuite>() -> Result<(), InternalError> {
|
||||
fn test_zero_scalar_error<CS: CipherSuite>() -> 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(())
|
||||
}
|
||||
|
||||
+3
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<u8> {
|
||||
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<Vec<u8>> {
|
||||
@@ -240,7 +240,7 @@ fn test_verifiable_evaluate<CS: CipherSuite>(
|
||||
|
||||
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<CS: CipherSuite>(
|
||||
for i in 0..parameters.input.len() {
|
||||
let client = NonVerifiableClient::<CS>::from_data_and_blind(
|
||||
¶meters.input[i],
|
||||
&<CS::Group as Group>::from_scalar_slice(&GenericArray::clone_from_slice(
|
||||
<CS::Group as Group>::from_scalar_slice(&GenericArray::clone_from_slice(
|
||||
¶meters.blind[i],
|
||||
))?,
|
||||
);
|
||||
@@ -296,10 +296,10 @@ fn test_verifiable_finalize<CS: CipherSuite>(
|
||||
for i in 0..parameters.input.len() {
|
||||
let client = VerifiableClient::<CS>::from_data_and_blind(
|
||||
¶meters.input[i],
|
||||
&<CS::Group as Group>::from_scalar_slice(&GenericArray::clone_from_slice(
|
||||
<CS::Group as Group>::from_scalar_slice(&GenericArray::clone_from_slice(
|
||||
¶meters.blind[i],
|
||||
))?,
|
||||
&<CS::Group as Group>::from_element_slice(&GenericArray::clone_from_slice(
|
||||
<CS::Group as Group>::from_element_slice(&GenericArray::clone_from_slice(
|
||||
¶meters.blinded_element[i],
|
||||
))?,
|
||||
);
|
||||
|
||||
+9
-19
@@ -177,10 +177,10 @@ impl<CS: CipherSuite> NonVerifiableClient<CS> {
|
||||
|
||||
#[cfg(test)]
|
||||
/// Only used for test functions
|
||||
pub fn from_data_and_blind(data: &[u8], blind: &<CS::Group as Group>::Scalar) -> Self {
|
||||
pub fn from_data_and_blind(data: &[u8], blind: <CS::Group as Group>::Scalar) -> Self {
|
||||
Self {
|
||||
data: data.to_vec(),
|
||||
blind: blind.clone(),
|
||||
blind,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,13 +271,13 @@ impl<CS: CipherSuite> VerifiableClient<CS> {
|
||||
/// Only used for test functions
|
||||
pub fn from_data_and_blind(
|
||||
data: &[u8],
|
||||
blind: &<CS::Group as Group>::Scalar,
|
||||
blinded_element: &CS::Group,
|
||||
blind: <CS::Group as Group>::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<CS: CipherSuite> VerifiableServer<CS> {
|
||||
|
||||
/// 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<u8>);
|
||||
|
||||
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::<CS>(
|
||||
&inputs[i][..],
|
||||
server.get_private_key(),
|
||||
info,
|
||||
Mode::Verifiable,
|
||||
);
|
||||
for input in inputs.iter().take(num_iterations) {
|
||||
let output = prf::<CS>(&input[..], server.get_private_key(), info, Mode::Verifiable);
|
||||
res2.push(output);
|
||||
}
|
||||
assert_eq!(client_finalize_result.outputs, res2);
|
||||
|
||||
Reference in New Issue
Block a user