Skip to content

Commit

Permalink
Replace json with serde_json (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Jan 19, 2023
1 parent daa8dc0 commit c8de516
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ zeroize = { version = "1.5", default-features = false }
[dev-dependencies]
generic-array = { version = "0.14", features = ["more_lengths"] }
hex = "0.4"
json = "0.12"
p256 = { version = "0.12", default-features = false, features = [
"hash2curve",
"voprf",
] }
proptest = "1"
rand = "0.8"
regex = "1"
serde_json = "1"
sha2 = "0.10"

[package.metadata.docs.rs]
Expand Down
16 changes: 9 additions & 7 deletions src/tests/test_cfrg_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use digest::core_api::BlockSizeUser;
use digest::OutputSizeUser;
use generic_array::typenum::{IsLess, IsLessOrEqual, Sum, U256};
use generic_array::ArrayLength;
use json::JsonValue;
use serde_json::Value;

use crate::tests::mock_rng::CycleRng;
use crate::tests::parser::*;
Expand All @@ -40,7 +40,7 @@ struct VOPRFTestVectorParameters {
output: Vec<Vec<u8>>,
}

fn populate_test_vectors(values: &JsonValue) -> VOPRFTestVectorParameters {
fn populate_test_vectors(values: &Value) -> VOPRFTestVectorParameters {
VOPRFTestVectorParameters {
seed: decode(values, "Seed"),
sksm: decode(values, "skSm"),
Expand All @@ -57,14 +57,14 @@ fn populate_test_vectors(values: &JsonValue) -> VOPRFTestVectorParameters {
}
}

fn decode(values: &JsonValue, key: &str) -> Vec<u8> {
fn decode(values: &Value, key: &str) -> Vec<u8> {
values[key]
.as_str()
.and_then(|s| hex::decode(s).ok())
.unwrap_or_default()
}

fn decode_vec(values: &JsonValue, key: &str) -> Vec<Vec<u8>> {
fn decode_vec(values: &Value, key: &str) -> Vec<Vec<u8>> {
let s = values[key].as_str().unwrap();
let res = match s.contains(',') {
true => Some(s.split(',').map(|x| hex::decode(x).unwrap()).collect()),
Expand All @@ -76,8 +76,10 @@ fn decode_vec(values: &JsonValue, key: &str) -> Vec<Vec<u8>> {
macro_rules! json_to_test_vectors {
( $v:ident, $cs:expr, $mode:expr ) => {
$v[$cs][$mode]
.members()
.map(|x| populate_test_vectors(&x))
.as_array()
.into_iter()
.flatten()
.map(populate_test_vectors)
.collect::<Vec<VOPRFTestVectorParameters>>()
};
}
Expand All @@ -86,7 +88,7 @@ macro_rules! json_to_test_vectors {
fn test_vectors() -> Result<()> {
use p256::NistP256;

let rfc = json::parse(rfc_to_json(super::cfrg_vectors::VECTORS).as_str())
let rfc: Value = serde_json::from_str(rfc_to_json(super::cfrg_vectors::VECTORS).as_str())
.expect("Could not parse json");

#[cfg(feature = "ristretto255")]
Expand Down

0 comments on commit c8de516

Please sign in to comment.