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:
parent
1af6ff4394
commit
b6fda6517c
|
@ -14,6 +14,21 @@ use crate::HashEngine as _;
|
|||
#[repr(transparent)]
|
||||
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))]
|
||||
fn from_engine(e: HashEngine) -> Hash { Hash::from_u64(Hash::from_engine_to_u64(e)) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue