Implement JsonSchema for siphash::Hash

We lost this impl at some stage in the last few weeks and did not notice
because of a bug in `run_task` [0].

Implement `JsonSchema` for `siphash` as we do for all the other hash
types.

[0] https://github.com/rust-bitcoin/rust-bitcoin-maintainer-tools/issues/10
This commit is contained in:
Tobin C. Harding 2024-08-10 06:57:04 +10:00
parent 1af6ff4394
commit b6fda6517c
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 15 additions and 0 deletions

View File

@ -14,6 +14,21 @@ use crate::HashEngine as _;
#[repr(transparent)] #[repr(transparent)]
pub struct Hash([u8; 8]); pub struct Hash([u8; 8]);
#[cfg(feature = "schemars")]
impl schemars::JsonSchema for Hash {
fn schema_name() -> String { "Hash".to_owned() }
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
let mut schema: schemars::schema::SchemaObject = <String>::json_schema(gen).into();
schema.string = Some(Box::new(schemars::schema::StringValidation {
max_length: Some(8 * 2),
min_length: Some(8 * 2),
pattern: Some("[0-9a-fA-F]+".to_owned()),
}));
schema.into()
}
}
#[cfg(not(hashes_fuzz))] #[cfg(not(hashes_fuzz))]
fn from_engine(e: HashEngine) -> Hash { Hash::from_u64(Hash::from_engine_to_u64(e)) } fn from_engine(e: HashEngine) -> Hash { Hash::from_u64(Hash::from_engine_to_u64(e)) }