From a8ff182fc52a447a1f968e2515e742f591df6bbc Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Thu, 19 Jan 2023 22:13:59 +0100 Subject: [PATCH] Replace `json` with `serde_json` --- Cargo.toml | 2 +- src/tests/test_cfrg_vectors.rs | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 15f3dde..ea205dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ zeroize = { version = "1.5", default-features = false } [dev-dependencies] generic-array = { version = "0.14", features = ["more_lengths"] } hex = "0.4" -json = "0.12" +serde_json = "1" p256 = { version = "0.12", default-features = false, features = [ "hash2curve", "voprf", diff --git a/src/tests/test_cfrg_vectors.rs b/src/tests/test_cfrg_vectors.rs index 80b6f35..6c21ca0 100644 --- a/src/tests/test_cfrg_vectors.rs +++ b/src/tests/test_cfrg_vectors.rs @@ -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::*; @@ -40,7 +40,7 @@ struct VOPRFTestVectorParameters { output: Vec>, } -fn populate_test_vectors(values: &JsonValue) -> VOPRFTestVectorParameters { +fn populate_test_vectors(values: &Value) -> VOPRFTestVectorParameters { VOPRFTestVectorParameters { seed: decode(values, "Seed"), sksm: decode(values, "skSm"), @@ -57,14 +57,14 @@ fn populate_test_vectors(values: &JsonValue) -> VOPRFTestVectorParameters { } } -fn decode(values: &JsonValue, key: &str) -> Vec { +fn decode(values: &Value, key: &str) -> Vec { values[key] .as_str() .and_then(|s| hex::decode(s).ok()) .unwrap_or_default() } -fn decode_vec(values: &JsonValue, key: &str) -> Vec> { +fn decode_vec(values: &Value, key: &str) -> Vec> { let s = values[key].as_str().unwrap(); let res = match s.contains(',') { true => Some(s.split(',').map(|x| hex::decode(x).unwrap()).collect()), @@ -76,8 +76,10 @@ fn decode_vec(values: &JsonValue, key: &str) -> Vec> { 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::>() }; } @@ -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")]