Skip to content

Commit c8de516

Browse files
authoredJan 19, 2023
Replace json with serde_json (#92)
1 parent daa8dc0 commit c8de516

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed
 

‎Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ zeroize = { version = "1.5", default-features = false }
4444
[dev-dependencies]
4545
generic-array = { version = "0.14", features = ["more_lengths"] }
4646
hex = "0.4"
47-
json = "0.12"
4847
p256 = { version = "0.12", default-features = false, features = [
4948
"hash2curve",
5049
"voprf",
5150
] }
5251
proptest = "1"
5352
rand = "0.8"
5453
regex = "1"
54+
serde_json = "1"
5555
sha2 = "0.10"
5656

5757
[package.metadata.docs.rs]

‎src/tests/test_cfrg_vectors.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use digest::core_api::BlockSizeUser;
1414
use digest::OutputSizeUser;
1515
use generic_array::typenum::{IsLess, IsLessOrEqual, Sum, U256};
1616
use generic_array::ArrayLength;
17-
use json::JsonValue;
17+
use serde_json::Value;
1818

1919
use crate::tests::mock_rng::CycleRng;
2020
use crate::tests::parser::*;
@@ -40,7 +40,7 @@ struct VOPRFTestVectorParameters {
4040
output: Vec<Vec<u8>>,
4141
}
4242

43-
fn populate_test_vectors(values: &JsonValue) -> VOPRFTestVectorParameters {
43+
fn populate_test_vectors(values: &Value) -> VOPRFTestVectorParameters {
4444
VOPRFTestVectorParameters {
4545
seed: decode(values, "Seed"),
4646
sksm: decode(values, "skSm"),
@@ -57,14 +57,14 @@ fn populate_test_vectors(values: &JsonValue) -> VOPRFTestVectorParameters {
5757
}
5858
}
5959

60-
fn decode(values: &JsonValue, key: &str) -> Vec<u8> {
60+
fn decode(values: &Value, key: &str) -> Vec<u8> {
6161
values[key]
6262
.as_str()
6363
.and_then(|s| hex::decode(s).ok())
6464
.unwrap_or_default()
6565
}
6666

67-
fn decode_vec(values: &JsonValue, key: &str) -> Vec<Vec<u8>> {
67+
fn decode_vec(values: &Value, key: &str) -> Vec<Vec<u8>> {
6868
let s = values[key].as_str().unwrap();
6969
let res = match s.contains(',') {
7070
true => Some(s.split(',').map(|x| hex::decode(x).unwrap()).collect()),
@@ -76,8 +76,10 @@ fn decode_vec(values: &JsonValue, key: &str) -> Vec<Vec<u8>> {
7676
macro_rules! json_to_test_vectors {
7777
( $v:ident, $cs:expr, $mode:expr ) => {
7878
$v[$cs][$mode]
79-
.members()
80-
.map(|x| populate_test_vectors(&x))
79+
.as_array()
80+
.into_iter()
81+
.flatten()
82+
.map(populate_test_vectors)
8183
.collect::<Vec<VOPRFTestVectorParameters>>()
8284
};
8385
}
@@ -86,7 +88,7 @@ macro_rules! json_to_test_vectors {
8688
fn test_vectors() -> Result<()> {
8789
use p256::NistP256;
8890

89-
let rfc = json::parse(rfc_to_json(super::cfrg_vectors::VECTORS).as_str())
91+
let rfc: Value = serde_json::from_str(rfc_to_json(super::cfrg_vectors::VECTORS).as_str())
9092
.expect("Could not parse json");
9193

9294
#[cfg(feature = "ristretto255")]

0 commit comments

Comments
 (0)