Merge rust-bitcoin/rust-bitcoin#3395: Remove schemars all together
58704c2eff
Remove schemars all together (Tobin C. Harding) Pull request description: We introduced schemars as a personal favor to a user, and it broke our CI repeatedly but eventually it seemed like it was stable (mainly, our MSRV caught up with its MSRV) so we just let it slide. In the end having schemars on hashes but nowhere else in the rust-bitcoin ecosystem did not prove that useful. Remove schemars all together. Fix: #3393 ACKs for top commit: apoelstra: ACK58704c2eff
successfully ran local tests Tree-SHA512: 11c136797f28903c7d6b5199ad55d86bc4bc29ee8dd6f0d575e029f4dbebebabed57ebce6cf773b286297ea84f18d0b6cc58e150299e99457e048226478b49cc
This commit is contained in:
commit
40ba08f369
|
@ -137,7 +137,6 @@ version = "0.14.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitcoin-io",
|
"bitcoin-io",
|
||||||
"hex-conservative",
|
"hex-conservative",
|
||||||
"schemars",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_test",
|
"serde_test",
|
||||||
|
@ -170,12 +169,6 @@ version = "0.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
|
checksum = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dyn-clone"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0da518043f6481364cd454be81dfe096cfd3f82daa1466f4946d24ea325b0941"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -364,17 +357,6 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
|
checksum = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "schemars"
|
|
||||||
version = "0.8.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bc6ab463ae35acccb5cba66c0084c985257b797d288b6050cc2f6ac1b266cb78"
|
|
||||||
dependencies = [
|
|
||||||
"dyn-clone",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "secp256k1"
|
name = "secp256k1"
|
||||||
version = "0.29.0"
|
version = "0.29.0"
|
||||||
|
|
|
@ -136,7 +136,6 @@ version = "0.14.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitcoin-io",
|
"bitcoin-io",
|
||||||
"hex-conservative",
|
"hex-conservative",
|
||||||
"schemars",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_test",
|
"serde_test",
|
||||||
|
@ -163,12 +162,6 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dyn-clone"
|
|
||||||
version = "1.0.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.9"
|
version = "0.2.9"
|
||||||
|
@ -347,17 +340,6 @@ version = "1.0.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "schemars"
|
|
||||||
version = "0.8.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f"
|
|
||||||
dependencies = [
|
|
||||||
"dyn-clone",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "secp256k1"
|
name = "secp256k1"
|
||||||
version = "0.29.0"
|
version = "0.29.0"
|
||||||
|
|
|
@ -17,7 +17,6 @@ exclude = ["tests", "contrib"]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["alloc", "bitcoin-io?/std", "hex/std"]
|
std = ["alloc", "bitcoin-io?/std", "hex/std"]
|
||||||
alloc = ["bitcoin-io?/alloc", "hex/alloc"]
|
alloc = ["bitcoin-io?/alloc", "hex/alloc"]
|
||||||
schemars = ["dep:schemars", "alloc"]
|
|
||||||
# Smaller (but slower) implementation of sha256, sha512 and ripemd160
|
# Smaller (but slower) implementation of sha256, sha512 and ripemd160
|
||||||
small-hash = []
|
small-hash = []
|
||||||
|
|
||||||
|
@ -25,7 +24,6 @@ small-hash = []
|
||||||
hex = { package = "hex-conservative", version = "0.2.0", default-features = false }
|
hex = { package = "hex-conservative", version = "0.2.0", default-features = false }
|
||||||
|
|
||||||
bitcoin-io = { version = "0.1.1", default-features = false, optional = true }
|
bitcoin-io = { version = "0.1.1", default-features = false, optional = true }
|
||||||
schemars = { version = "0.8.3", default-features = false, optional = true }
|
|
||||||
serde = { version = "1.0", default-features = false, optional = true }
|
serde = { version = "1.0", default-features = false, optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -euox pipefail
|
|
||||||
|
|
||||||
REPO_DIR=$(git rev-parse --show-toplevel)
|
|
||||||
|
|
||||||
pushd "$REPO_DIR/hashes/extended_tests/schemars" > /dev/null
|
|
||||||
|
|
||||||
# This comment mentions Rust 1.63 to assist grepping when doing MSRV update.
|
|
||||||
#
|
|
||||||
if cargo --version | grep -q '1\.63'; then
|
|
||||||
cargo update -p regex --precise 1.7.3
|
|
||||||
fi
|
|
||||||
|
|
||||||
cargo test
|
|
||||||
popd > /dev/null
|
|
|
@ -5,7 +5,7 @@
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
|
||||||
# Test all these features with "std" enabled.
|
# Test all these features with "std" enabled.
|
||||||
FEATURES_WITH_STD="bitcoin-io serde small-hash schemars"
|
FEATURES_WITH_STD="bitcoin-io serde small-hash"
|
||||||
|
|
||||||
# Test all these features without "std" enabled.
|
# Test all these features without "std" enabled.
|
||||||
FEATURES_WITHOUT_STD="alloc bitcoin-io serde small-hash"
|
FEATURES_WITHOUT_STD="alloc bitcoin-io serde small-hash"
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "schemars"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Jeremy Rubin <j@rubin.io>"]
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
# Prevent this from interfering with workspaces
|
|
||||||
[workspace]
|
|
||||||
members = ["."]
|
|
||||||
|
|
||||||
[dependencies.bitcoin_hashes]
|
|
||||||
path = "../.."
|
|
||||||
features = ['schemars', 'serde']
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
jsonschema-valid = "0.4.0"
|
|
||||||
serde = { version = "1.0", default-features = false}
|
|
||||||
schemars = "0.8.3"
|
|
||||||
serde_test = "1.0"
|
|
||||||
serde_json = "1.0"
|
|
||||||
|
|
||||||
[patch.crates-io.bitcoin-internals]
|
|
||||||
path = "../../../internals"
|
|
||||||
|
|
||||||
[patch.crates-io.bitcoin-io]
|
|
||||||
path = "../../../io"
|
|
||||||
|
|
||||||
[patch.crates-io.bitcoin-units]
|
|
||||||
path = "../../../units"
|
|
|
@ -1,9 +0,0 @@
|
||||||
# Test crate for the schemars feature
|
|
||||||
|
|
||||||
Run as usual with `cargo test`.
|
|
||||||
|
|
||||||
## Minimum Supported Rust Version (MSRV)
|
|
||||||
|
|
||||||
To run the tests with the current MSRV you will need to pin some
|
|
||||||
dependencies. See the `hashes/contrib/extra_tests.sh` script for the
|
|
||||||
current list of pins.
|
|
|
@ -1,193 +0,0 @@
|
||||||
fn main() {}
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use bitcoin_hashes::*;
|
|
||||||
use bitcoin_hashes::sha256::Midstate;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn hash160() {
|
|
||||||
static HASH_BYTES: [u8; 20] = [
|
|
||||||
0x13, 0x20, 0x72, 0xdf, 0x69, 0x09, 0x33, 0x83, 0x5e, 0xb8, 0xb6, 0xad, 0x0b, 0x77,
|
|
||||||
0xe7, 0xb6, 0xf1, 0x4a, 0xca, 0xd7,
|
|
||||||
];
|
|
||||||
|
|
||||||
let hash = hash160::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
|
|
||||||
let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap();
|
|
||||||
let s = schemars::schema_for!(hash160::Hash);
|
|
||||||
let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap();
|
|
||||||
assert!(jsonschema_valid::Config::from_schema(&schema, None)
|
|
||||||
.unwrap()
|
|
||||||
.validate(&js)
|
|
||||||
.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn hmac_sha512() {
|
|
||||||
static HASH_BYTES: [u8; 64] = [
|
|
||||||
0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21, 0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a,
|
|
||||||
0x1b, 0x8e, 0x0a, 0x19, 0x57, 0x54, 0xaa, 0x52, 0x7f, 0xcd, 0x00, 0xa4, 0x11, 0x62,
|
|
||||||
0x0b, 0x46, 0xf2, 0x0f, 0xff, 0xfb, 0x80, 0x88, 0xcc, 0xf8, 0x54, 0x97, 0x12, 0x1a,
|
|
||||||
0xd4, 0x49, 0x9e, 0x08, 0x45, 0xb8, 0x76, 0xf6, 0xdd, 0x66, 0x40, 0x08, 0x8a, 0x2f,
|
|
||||||
0x0b, 0x2d, 0x8a, 0x60, 0x0b, 0xdf, 0x4c, 0x0c,
|
|
||||||
];
|
|
||||||
|
|
||||||
let hash = Hmac::<sha512::Hash>::from_slice(&HASH_BYTES).expect("right number of bytes");
|
|
||||||
let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap();
|
|
||||||
let s = schemars::schema_for!(Hmac::<sha512::Hash>);
|
|
||||||
let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap();
|
|
||||||
assert!(jsonschema_valid::Config::from_schema(&schema, None)
|
|
||||||
.unwrap()
|
|
||||||
.validate(&js)
|
|
||||||
.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn ripemd160() {
|
|
||||||
static HASH_BYTES: [u8; 20] = [
|
|
||||||
0x13, 0x20, 0x72, 0xdf, 0x69, 0x09, 0x33, 0x83, 0x5e, 0xb8, 0xb6, 0xad, 0x0b, 0x77,
|
|
||||||
0xe7, 0xb6, 0xf1, 0x4a, 0xca, 0xd7,
|
|
||||||
];
|
|
||||||
|
|
||||||
let hash = ripemd160::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
|
|
||||||
let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap();
|
|
||||||
let s = schemars::schema_for!(ripemd160::Hash);
|
|
||||||
let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap();
|
|
||||||
assert!(jsonschema_valid::Config::from_schema(&schema, None)
|
|
||||||
.unwrap()
|
|
||||||
.validate(&js)
|
|
||||||
.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sha1() {
|
|
||||||
static HASH_BYTES: [u8; 20] = [
|
|
||||||
0x13, 0x20, 0x72, 0xdf, 0x69, 0x09, 0x33, 0x83, 0x5e, 0xb8, 0xb6, 0xad, 0x0b, 0x77,
|
|
||||||
0xe7, 0xb6, 0xf1, 0x4a, 0xca, 0xd7,
|
|
||||||
];
|
|
||||||
|
|
||||||
let hash = sha1::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
|
|
||||||
let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap();
|
|
||||||
let s = schemars::schema_for!(sha1::Hash);
|
|
||||||
let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap();
|
|
||||||
assert!(jsonschema_valid::Config::from_schema(&schema, None)
|
|
||||||
.unwrap()
|
|
||||||
.validate(&js)
|
|
||||||
.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sha256d() {
|
|
||||||
static HASH_BYTES: [u8; 32] = [
|
|
||||||
0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6,
|
|
||||||
0x3d, 0x97, 0xaa, 0x63, 0x15, 0x64, 0xd5, 0xd7, 0x89, 0xc2, 0xb7, 0x65, 0x44, 0x8c,
|
|
||||||
0x86, 0x35, 0xfb, 0x6c,
|
|
||||||
];
|
|
||||||
|
|
||||||
let hash = sha256d::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
|
|
||||||
let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap();
|
|
||||||
let s = schemars::schema_for!(sha256d::Hash);
|
|
||||||
let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap();
|
|
||||||
assert!(jsonschema_valid::Config::from_schema(&schema, None)
|
|
||||||
.unwrap()
|
|
||||||
.validate(&js)
|
|
||||||
.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sha256() {
|
|
||||||
static HASH_BYTES: [u8; 32] = [
|
|
||||||
0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6,
|
|
||||||
0x3d, 0x97, 0xaa, 0x63, 0x15, 0x64, 0xd5, 0xd7, 0x89, 0xc2, 0xb7, 0x65, 0x44, 0x8c,
|
|
||||||
0x86, 0x35, 0xfb, 0x6c,
|
|
||||||
];
|
|
||||||
|
|
||||||
let hash = sha256::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
|
|
||||||
let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap();
|
|
||||||
let s = schemars::schema_for!(sha256::Hash);
|
|
||||||
let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap();
|
|
||||||
assert!(jsonschema_valid::Config::from_schema(&schema, None)
|
|
||||||
.unwrap()
|
|
||||||
.validate(&js)
|
|
||||||
.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_hash() {
|
|
||||||
const TEST_MIDSTATE: [u8; 32] = [
|
|
||||||
156, 224, 228, 230, 124, 17, 108, 57, 56, 179, 202, 242, 195, 15, 80, 137, 211, 243,
|
|
||||||
147, 108, 71, 99, 110, 96, 125, 179, 62, 234, 221, 198, 240, 201,
|
|
||||||
];
|
|
||||||
|
|
||||||
// The midstate of an empty hash engine tagged with "TapLeaf".
|
|
||||||
const TAP_LEAF_MIDSTATE: Midstate = Midstate::new(TEST_MIDSTATE, 64);
|
|
||||||
|
|
||||||
#[derive(
|
|
||||||
Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default, Hash, schemars::JsonSchema,
|
|
||||||
)]
|
|
||||||
pub struct TestHashTag;
|
|
||||||
|
|
||||||
impl sha256t::Tag for TestHashTag {
|
|
||||||
fn engine() -> sha256::HashEngine {
|
|
||||||
sha256::HashEngine::from_midstate(TAP_LEAF_MIDSTATE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A hash tagged with `$name`.
|
|
||||||
pub type TestHash = sha256t::Hash<TestHashTag>;
|
|
||||||
|
|
||||||
sha256t_hash_newtype! {
|
|
||||||
struct NewTypeTag = raw(TEST_MIDSTATE, 64);
|
|
||||||
|
|
||||||
#[hash_newtype(backward)]
|
|
||||||
struct NewTypeHash(_);
|
|
||||||
}
|
|
||||||
static HASH_BYTES: [u8; 32] = [
|
|
||||||
0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6,
|
|
||||||
0x3d, 0x97, 0xaa, 0x63, 0x15, 0x64, 0xd5, 0xd7, 0x89, 0xc2, 0xb7, 0x65, 0x44, 0x8c,
|
|
||||||
0x86, 0x35, 0xfb, 0x6c,
|
|
||||||
];
|
|
||||||
|
|
||||||
let hash = TestHash::from_slice(&HASH_BYTES).expect("right number of bytes");
|
|
||||||
let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap();
|
|
||||||
let s = schemars::schema_for!(TestHash);
|
|
||||||
let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap();
|
|
||||||
assert!(jsonschema_valid::Config::from_schema(&schema, None)
|
|
||||||
.unwrap()
|
|
||||||
.validate(&js)
|
|
||||||
.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sha512() {
|
|
||||||
static HASH_BYTES: [u8; 64] = [
|
|
||||||
0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21, 0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a,
|
|
||||||
0x1b, 0x8e, 0x0a, 0x19, 0x57, 0x54, 0xaa, 0x52, 0x7f, 0xcd, 0x00, 0xa4, 0x11, 0x62,
|
|
||||||
0x0b, 0x46, 0xf2, 0x0f, 0xff, 0xfb, 0x80, 0x88, 0xcc, 0xf8, 0x54, 0x97, 0x12, 0x1a,
|
|
||||||
0xd4, 0x49, 0x9e, 0x08, 0x45, 0xb8, 0x76, 0xf6, 0xdd, 0x66, 0x40, 0x08, 0x8a, 0x2f,
|
|
||||||
0x0b, 0x2d, 0x8a, 0x60, 0x0b, 0xdf, 0x4c, 0x0c,
|
|
||||||
];
|
|
||||||
|
|
||||||
let hash = sha512::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
|
|
||||||
let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap();
|
|
||||||
let s = schemars::schema_for!(sha512::Hash);
|
|
||||||
let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap();
|
|
||||||
assert!(jsonschema_valid::Config::from_schema(&schema, None)
|
|
||||||
.unwrap()
|
|
||||||
.validate(&js)
|
|
||||||
.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn siphash24() {
|
|
||||||
static HASH_BYTES: [u8; 8] = [0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21];
|
|
||||||
|
|
||||||
let hash = siphash24::Hash::from_slice(&HASH_BYTES).expect("right number of bytes");
|
|
||||||
let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap();
|
|
||||||
let s = schemars::schema_for!(siphash24::Hash);
|
|
||||||
let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap();
|
|
||||||
assert!(jsonschema_valid::Config::from_schema(&schema, None)
|
|
||||||
.unwrap()
|
|
||||||
.validate(&js)
|
|
||||||
.is_ok());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,17 +19,6 @@ use crate::{FromSliceError, GeneralHash, Hash, HashEngine};
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct Hmac<T: GeneralHash>(T);
|
pub struct Hmac<T: GeneralHash>(T);
|
||||||
|
|
||||||
#[cfg(feature = "schemars")]
|
|
||||||
impl<T: GeneralHash + schemars::JsonSchema> schemars::JsonSchema for Hmac<T> {
|
|
||||||
fn is_referenceable() -> bool { <T as schemars::JsonSchema>::is_referenceable() }
|
|
||||||
|
|
||||||
fn schema_name() -> alloc::string::String { <T as schemars::JsonSchema>::schema_name() }
|
|
||||||
|
|
||||||
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
|
|
||||||
<T as schemars::JsonSchema>::json_schema(gen)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: GeneralHash + str::FromStr> str::FromStr for Hmac<T> {
|
impl<T: GeneralHash + str::FromStr> str::FromStr for Hmac<T> {
|
||||||
type Err = <T as str::FromStr>::Err;
|
type Err = <T as str::FromStr>::Err;
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> { Ok(Hmac(str::FromStr::from_str(s)?)) }
|
fn from_str(s: &str) -> Result<Self, Self::Err> { Ok(Hmac(str::FromStr::from_str(s)?)) }
|
||||||
|
|
|
@ -130,7 +130,6 @@ pub(crate) use hash_trait_impls;
|
||||||
/// * `$bits` - the number of bits of the hash type
|
/// * `$bits` - the number of bits of the hash type
|
||||||
/// * `$reverse` - `true` if the hash should be displayed backwards, `false` otherwise
|
/// * `$reverse` - `true` if the hash should be displayed backwards, `false` otherwise
|
||||||
/// * `$doc` - doc string to put on the type
|
/// * `$doc` - doc string to put on the type
|
||||||
/// * `$schemars` - a literal that goes into `schema_with`.
|
|
||||||
///
|
///
|
||||||
/// The `from_engine` free-standing function is still required with this macro. See the doc of
|
/// The `from_engine` free-standing function is still required with this macro. See the doc of
|
||||||
/// [`hash_trait_impls`].
|
/// [`hash_trait_impls`].
|
||||||
|
@ -217,30 +216,6 @@ macro_rules! hash_type_no_default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "schemars")]
|
|
||||||
impl schemars::JsonSchema for Hash {
|
|
||||||
fn schema_name() -> alloc::string::String {
|
|
||||||
use alloc::borrow::ToOwned;
|
|
||||||
|
|
||||||
"Hash".to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
|
|
||||||
use alloc::borrow::ToOwned;
|
|
||||||
use alloc::boxed::Box;
|
|
||||||
use alloc::string::String;
|
|
||||||
|
|
||||||
let len = $bits / 8;
|
|
||||||
let mut schema: schemars::schema::SchemaObject = <String>::json_schema(gen).into();
|
|
||||||
schema.string = Some(Box::new(schemars::schema::StringValidation {
|
|
||||||
max_length: Some(len * 2),
|
|
||||||
min_length: Some(len * 2),
|
|
||||||
pattern: Some("[0-9a-fA-F]+".to_owned()),
|
|
||||||
}));
|
|
||||||
schema.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$crate::internal_macros::hash_trait_impls!($bits, $reverse);
|
$crate::internal_macros::hash_trait_impls!($bits, $reverse);
|
||||||
|
|
||||||
$crate::internal_macros::impl_io_write!(
|
$crate::internal_macros::impl_io_write!(
|
||||||
|
|
|
@ -100,9 +100,6 @@ pub mod _export {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "schemars")]
|
|
||||||
extern crate schemars;
|
|
||||||
|
|
||||||
mod internal_macros;
|
mod internal_macros;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod util;
|
mod util;
|
||||||
|
|
|
@ -21,29 +21,6 @@ pub trait Tag {
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct Hash<T>([u8; 32], PhantomData<T>);
|
pub struct Hash<T>([u8; 32], PhantomData<T>);
|
||||||
|
|
||||||
#[cfg(feature = "schemars")]
|
|
||||||
impl<T: Tag> schemars::JsonSchema for Hash<T> {
|
|
||||||
fn schema_name() -> alloc::string::String {
|
|
||||||
use alloc::borrow::ToOwned;
|
|
||||||
|
|
||||||
"Hash".to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
|
|
||||||
use alloc::borrow::ToOwned;
|
|
||||||
use alloc::boxed::Box;
|
|
||||||
use alloc::string::String;
|
|
||||||
|
|
||||||
let mut schema: schemars::schema::SchemaObject = <String>::json_schema(gen).into();
|
|
||||||
schema.string = Some(Box::new(schemars::schema::StringValidation {
|
|
||||||
max_length: Some(32 * 2),
|
|
||||||
min_length: Some(32 * 2),
|
|
||||||
pattern: Some("[0-9a-fA-F]+".to_owned()),
|
|
||||||
}));
|
|
||||||
schema.into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Hash<T>
|
impl<T> Hash<T>
|
||||||
where
|
where
|
||||||
T: Tag,
|
T: Tag,
|
||||||
|
|
Loading…
Reference in New Issue