diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock index 53a1cb9d5..e05ddb2b1 100644 --- a/Cargo-minimal.lock +++ b/Cargo-minimal.lock @@ -137,7 +137,6 @@ version = "0.14.0" dependencies = [ "bitcoin-io", "hex-conservative", - "schemars", "serde", "serde_json", "serde_test", @@ -170,12 +169,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" -[[package]] -name = "dyn-clone" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0da518043f6481364cd454be81dfe096cfd3f82daa1466f4946d24ea325b0941" - [[package]] name = "getrandom" version = "0.2.0" @@ -364,17 +357,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "secp256k1" version = "0.29.0" diff --git a/Cargo-recent.lock b/Cargo-recent.lock index 3bd3f7acb..f0f208b2c 100644 --- a/Cargo-recent.lock +++ b/Cargo-recent.lock @@ -136,7 +136,6 @@ version = "0.14.0" dependencies = [ "bitcoin-io", "hex-conservative", - "schemars", "serde", "serde_json", "serde_test", @@ -163,12 +162,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "dyn-clone" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" - [[package]] name = "getrandom" version = "0.2.9" @@ -347,17 +340,6 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "secp256k1" version = "0.29.0" diff --git a/hashes/Cargo.toml b/hashes/Cargo.toml index 299b675d6..3806cf935 100644 --- a/hashes/Cargo.toml +++ b/hashes/Cargo.toml @@ -17,7 +17,6 @@ exclude = ["tests", "contrib"] default = ["std"] std = ["alloc", "bitcoin-io?/std", "hex/std"] alloc = ["bitcoin-io?/alloc", "hex/alloc"] -schemars = ["dep:schemars", "alloc"] # Smaller (but slower) implementation of sha256, sha512 and ripemd160 small-hash = [] @@ -25,7 +24,6 @@ small-hash = [] hex = { package = "hex-conservative", version = "0.2.0", default-features = false } 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 } [dev-dependencies] diff --git a/hashes/contrib/extra_tests.sh b/hashes/contrib/extra_tests.sh deleted file mode 100755 index 4a39a1f1b..000000000 --- a/hashes/contrib/extra_tests.sh +++ /dev/null @@ -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 diff --git a/hashes/contrib/test_vars.sh b/hashes/contrib/test_vars.sh index 67bd292da..35360740a 100644 --- a/hashes/contrib/test_vars.sh +++ b/hashes/contrib/test_vars.sh @@ -5,7 +5,7 @@ # shellcheck disable=SC2034 # 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. FEATURES_WITHOUT_STD="alloc bitcoin-io serde small-hash" diff --git a/hashes/extended_tests/schemars/Cargo.toml b/hashes/extended_tests/schemars/Cargo.toml deleted file mode 100644 index 8d262dff0..000000000 --- a/hashes/extended_tests/schemars/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -name = "schemars" -version = "0.1.0" -authors = ["Jeremy Rubin "] -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" diff --git a/hashes/extended_tests/schemars/README.md b/hashes/extended_tests/schemars/README.md deleted file mode 100644 index e93cd0b0a..000000000 --- a/hashes/extended_tests/schemars/README.md +++ /dev/null @@ -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. diff --git a/hashes/extended_tests/schemars/src/main.rs b/hashes/extended_tests/schemars/src/main.rs deleted file mode 100644 index c9f73d40a..000000000 --- a/hashes/extended_tests/schemars/src/main.rs +++ /dev/null @@ -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::::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::); - 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; - - 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()); - } -} diff --git a/hashes/src/hmac.rs b/hashes/src/hmac.rs index 73ff4b13a..089e3a2bc 100644 --- a/hashes/src/hmac.rs +++ b/hashes/src/hmac.rs @@ -19,17 +19,6 @@ use crate::{FromSliceError, GeneralHash, Hash, HashEngine}; #[repr(transparent)] pub struct Hmac(T); -#[cfg(feature = "schemars")] -impl schemars::JsonSchema for Hmac { - fn is_referenceable() -> bool { ::is_referenceable() } - - fn schema_name() -> alloc::string::String { ::schema_name() } - - fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { - ::json_schema(gen) - } -} - impl str::FromStr for Hmac { type Err = ::Err; fn from_str(s: &str) -> Result { Ok(Hmac(str::FromStr::from_str(s)?)) } diff --git a/hashes/src/internal_macros.rs b/hashes/src/internal_macros.rs index 65e5ddb17..39ae23001 100644 --- a/hashes/src/internal_macros.rs +++ b/hashes/src/internal_macros.rs @@ -130,7 +130,6 @@ pub(crate) use hash_trait_impls; /// * `$bits` - the number of bits of the hash type /// * `$reverse` - `true` if the hash should be displayed backwards, `false` otherwise /// * `$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 /// [`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 = ::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::impl_io_write!( diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs index b332b9a1f..077ee8762 100644 --- a/hashes/src/lib.rs +++ b/hashes/src/lib.rs @@ -104,9 +104,6 @@ pub mod _export { } } -#[cfg(feature = "schemars")] -extern crate schemars; - mod internal_macros; #[macro_use] mod util; diff --git a/hashes/src/sha256t.rs b/hashes/src/sha256t.rs index 7f2fae50e..0f099cb4b 100644 --- a/hashes/src/sha256t.rs +++ b/hashes/src/sha256t.rs @@ -21,29 +21,6 @@ pub trait Tag { #[repr(transparent)] pub struct Hash([u8; 32], PhantomData); -#[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 mut schema: schemars::schema::SchemaObject = ::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 Hash where T: Tag,