#![allow(dead_code)]
#![allow(clippy::expect_used, clippy::panic, clippy::unwrap_used)]
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct TestVectorSuite<T> {
pub name: String,
pub tests: Vec<T>,
}
#[derive(Debug, Deserialize)]
pub struct BaseTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct LocalTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub key: Option<String>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct PublicTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub key: Option<String>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct SecretTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub key: Option<String>,
#[serde(rename = "secret-key-seed")]
pub secret_key_seed: Option<String>,
#[serde(rename = "public-key")]
pub public_key: Option<String>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct LidTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub key: Option<String>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct PidTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub key: Option<String>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct SidTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub key: Option<String>,
#[serde(rename = "public-key")]
pub public_key: Option<String>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct LocalWrapTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub unwrapped: Option<String>,
#[serde(rename = "wrapping-key")]
pub wrapping_key: Option<String>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct SecretWrapTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub unwrapped: Option<String>,
#[serde(rename = "wrapping-key")]
pub wrapping_key: Option<String>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct PbkwOptions {
#[serde(default)]
pub memlimit: Option<u32>,
#[serde(default)]
pub opslimit: Option<u32>,
#[serde(default)]
pub iterations: Option<u32>,
}
#[derive(Debug, Deserialize)]
pub struct LocalPwTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub unwrapped: Option<String>,
pub password: Option<String>,
pub options: Option<PbkwOptions>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct SecretPwTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
pub unwrapped: Option<String>,
pub password: Option<String>,
pub options: Option<PbkwOptions>,
pub paserk: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct SealTestVector {
pub name: String,
#[serde(rename = "expect-fail")]
pub expect_fail: bool,
#[serde(default)]
pub comment: Option<String>,
#[serde(rename = "sealing-secret-key")]
pub sealing_secret_key: Option<String>,
#[serde(rename = "sealing-public-key")]
pub sealing_public_key: Option<String>,
pub unsealed: Option<String>,
pub paserk: Option<String>,
}
pub fn hex_decode(s: &str) -> Option<Vec<u8>> {
hex::decode(s).ok()
}
pub fn decode_password(s: &str) -> Vec<u8> {
s.as_bytes().to_vec()
}
pub fn load_vectors<T: serde::de::DeserializeOwned>(path: &str) -> TestVectorSuite<T> {
let content = std::fs::read_to_string(path)
.unwrap_or_else(|e| panic!("Failed to read test vector file {path}: {e}"));
serde_json::from_str(&content)
.unwrap_or_else(|e| panic!("Failed to parse test vector file {path}: {e}"))
}