Use Clippy on test code too (#22)
This commit is contained in:
@@ -89,7 +89,7 @@ jobs:
|
|||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: clippy
|
command: clippy
|
||||||
args: -- -D warnings
|
args: --all-targets -- -D warnings
|
||||||
|
|
||||||
|
|
||||||
format:
|
format:
|
||||||
|
|||||||
+2
-8
@@ -36,10 +36,7 @@ fn test_group_properties() -> Result<(), InternalError> {
|
|||||||
fn test_identity_element_error<CS: CipherSuite>() -> Result<(), InternalError> {
|
fn test_identity_element_error<CS: CipherSuite>() -> Result<(), InternalError> {
|
||||||
let identity = CS::Group::identity();
|
let identity = CS::Group::identity();
|
||||||
let result = CS::Group::from_element_slice(&identity.to_arr());
|
let result = CS::Group::from_element_slice(&identity.to_arr());
|
||||||
assert!(match result {
|
assert!(matches!(result, Err(InternalError::PointError)));
|
||||||
Err(InternalError::PointError) => true,
|
|
||||||
_ => false,
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -48,10 +45,7 @@ fn test_identity_element_error<CS: CipherSuite>() -> Result<(), InternalError> {
|
|||||||
fn test_zero_scalar_error<CS: CipherSuite>() -> Result<(), InternalError> {
|
fn test_zero_scalar_error<CS: CipherSuite>() -> Result<(), InternalError> {
|
||||||
let zero_scalar = CS::Group::scalar_zero();
|
let zero_scalar = CS::Group::scalar_zero();
|
||||||
let result = CS::Group::from_scalar_slice(&CS::Group::scalar_as_bytes(zero_scalar));
|
let result = CS::Group::from_scalar_slice(&CS::Group::scalar_as_bytes(zero_scalar));
|
||||||
assert!(match result {
|
assert!(matches!(result, Err(InternalError::ZeroScalarError)));
|
||||||
Err(InternalError::ZeroScalarError) => true,
|
|
||||||
_ => false,
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -85,7 +85,7 @@ fn parse_params(input: &str) -> String {
|
|||||||
// If line contains =, then
|
// If line contains =, then
|
||||||
if line.contains('=') {
|
if line.contains('=') {
|
||||||
// Clear out any existing string and flush to params
|
// Clear out any existing string and flush to params
|
||||||
if param.len() > 0 {
|
if !param.is_empty() {
|
||||||
param += "\"";
|
param += "\"";
|
||||||
params.push(param);
|
params.push(param);
|
||||||
}
|
}
|
||||||
@@ -97,11 +97,11 @@ fn parse_params(input: &str) -> String {
|
|||||||
param = format!(" \"{}\": \"{}", key, val);
|
param = format!(" \"{}\": \"{}", key, val);
|
||||||
} else {
|
} else {
|
||||||
let s = line.trim().to_string();
|
let s = line.trim().to_string();
|
||||||
if s.contains("~") || s.contains("#") {
|
if s.contains('~') || s.contains('#') {
|
||||||
// Ignore comment lines
|
// Ignore comment lines
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if s.len() > 0 {
|
if !s.is_empty() {
|
||||||
param += &s;
|
param += &s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,14 +40,14 @@ fn populate_test_vectors(values: &JsonValue) -> VOPRFTestVectorParameters {
|
|||||||
seed: decode(values, "seed"),
|
seed: decode(values, "seed"),
|
||||||
sksm: decode(values, "skSm"),
|
sksm: decode(values, "skSm"),
|
||||||
pksm: decode(values, "pkSm"),
|
pksm: decode(values, "pkSm"),
|
||||||
input: decode_vec(&values, "Input"),
|
input: decode_vec(values, "Input"),
|
||||||
info: decode(values, "Info"),
|
info: decode(values, "Info"),
|
||||||
blind: decode_vec(&values, "Blind"),
|
blind: decode_vec(values, "Blind"),
|
||||||
blinded_element: decode_vec(&values, "BlindedElement"),
|
blinded_element: decode_vec(values, "BlindedElement"),
|
||||||
evaluation_element: decode_vec(&values, "EvaluationElement"),
|
evaluation_element: decode_vec(values, "EvaluationElement"),
|
||||||
proof: decode(values, "Proof"),
|
proof: decode(values, "Proof"),
|
||||||
proof_random_scalar: decode(values, "ProofRandomScalar"),
|
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]
|
values[key]
|
||||||
.as_str()
|
.as_str()
|
||||||
.and_then(|s| hex::decode(&s.to_string()).ok())
|
.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>> {
|
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![];
|
let mut blinded_elements = vec![];
|
||||||
for blinded_element_bytes in ¶meters.blinded_element {
|
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(
|
let batch_evaluate_result = server.batch_evaluate(
|
||||||
@@ -269,7 +269,7 @@ fn test_base_finalize<CS: CipherSuite>(
|
|||||||
for i in 0..parameters.input.len() {
|
for i in 0..parameters.input.len() {
|
||||||
let client = NonVerifiableClient::<CS>::from_data_and_blind(
|
let client = NonVerifiableClient::<CS>::from_data_and_blind(
|
||||||
¶meters.input[i],
|
¶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],
|
¶meters.blind[i],
|
||||||
))?,
|
))?,
|
||||||
);
|
);
|
||||||
@@ -296,10 +296,10 @@ fn test_verifiable_finalize<CS: CipherSuite>(
|
|||||||
for i in 0..parameters.input.len() {
|
for i in 0..parameters.input.len() {
|
||||||
let client = VerifiableClient::<CS>::from_data_and_blind(
|
let client = VerifiableClient::<CS>::from_data_and_blind(
|
||||||
¶meters.input[i],
|
¶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],
|
¶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],
|
¶meters.blinded_element[i],
|
||||||
))?,
|
))?,
|
||||||
);
|
);
|
||||||
|
|||||||
+9
-19
@@ -177,10 +177,10 @@ impl<CS: CipherSuite> NonVerifiableClient<CS> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
/// Only used for test functions
|
/// 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 {
|
Self {
|
||||||
data: data.to_vec(),
|
data: data.to_vec(),
|
||||||
blind: blind.clone(),
|
blind,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,13 +271,13 @@ impl<CS: CipherSuite> VerifiableClient<CS> {
|
|||||||
/// Only used for test functions
|
/// Only used for test functions
|
||||||
pub fn from_data_and_blind(
|
pub fn from_data_and_blind(
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
blind: &<CS::Group as Group>::Scalar,
|
blind: <CS::Group as Group>::Scalar,
|
||||||
blinded_element: &CS::Group,
|
blinded_element: CS::Group,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
data: data.to_vec(),
|
data: data.to_vec(),
|
||||||
blind: blind.clone(),
|
blind,
|
||||||
blinded_element: blinded_element.clone(),
|
blinded_element,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,14 +447,9 @@ impl<CS: CipherSuite> VerifiableServer<CS> {
|
|||||||
|
|
||||||
/// Allows for implementations to specify an optional sequence of
|
/// Allows for implementations to specify an optional sequence of
|
||||||
/// public bytes that must be agreed-upon by the client and server
|
/// public bytes that must be agreed-upon by the client and server
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Metadata(pub Vec<u8>);
|
pub struct Metadata(pub Vec<u8>);
|
||||||
|
|
||||||
impl Default for Metadata {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self(vec![])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
/// Specifies no metadata (the default option)
|
/// Specifies no metadata (the default option)
|
||||||
pub fn none() -> Self {
|
pub fn none() -> Self {
|
||||||
@@ -902,13 +897,8 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut res2 = vec![];
|
let mut res2 = vec![];
|
||||||
for i in 0..num_iterations {
|
for input in inputs.iter().take(num_iterations) {
|
||||||
let output = prf::<CS>(
|
let output = prf::<CS>(&input[..], server.get_private_key(), info, Mode::Verifiable);
|
||||||
&inputs[i][..],
|
|
||||||
server.get_private_key(),
|
|
||||||
info,
|
|
||||||
Mode::Verifiable,
|
|
||||||
);
|
|
||||||
res2.push(output);
|
res2.push(output);
|
||||||
}
|
}
|
||||||
assert_eq!(client_finalize_result.outputs, res2);
|
assert_eq!(client_finalize_result.outputs, res2);
|
||||||
|
|||||||
Reference in New Issue
Block a user