Move impl_asref_push_bytes macro to include
What changed, and why it matters
This commit is a routine code reorganization. It moves a small helper macro that implements conversions for script push bytes from one internal file to a shared include directory, then pulls it back in with no functional changes. There is no security issue here.
No action required. This is a non-functional refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change relocates the impl_asref_push_bytes! macro from bitcoin/src/internal_macros.rs to include/asref_push_bytes.rs and includes it via include!() in bitcoin/src/lib.rs. Call sites are updated from crate::internal_macros::impl_asref_push_bytes! or crate::internal_macros::impl_asref_push_bytes to crate::impl_asref_push_bytes!. The macro body is identical, and the generated implementations remain the same. This is pure refactoring to support future multi-crate reuse.
Changed components
bitcoin/src/blockdata/script/mod.rsbitcoin/src/blockdata/script/push_bytes.rsbitcoin/src/crypto/key.rsbitcoin/src/internal_macros.rsbitcoin/src/lib.rsinclude/asref_push_bytes.rsInspect captured patch +24 / −24
diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs
index d7a2d951..82da4f23 100644
--- a/bitcoin/src/blockdata/script/mod.rs
+++ b/bitcoin/src/blockdata/script/mod.rs
@@ -59,7 +59,6 @@ use io::{BufRead, Write};
use self::witness_version::WitnessVersion;
use crate::consensus::{encode, Decodable, Encodable};
-use crate::internal_macros::impl_asref_push_bytes;
use crate::key::WPubkeyHash;
use crate::opcodes::all::*;
use crate::opcodes::Opcode;
diff --git a/bitcoin/src/blockdata/script/push_bytes.rs b/bitcoin/src/blockdata/script/push_bytes.rs
index 9160e4a6..aa6bb639 100644
--- a/bitcoin/src/blockdata/script/push_bytes.rs
+++ b/bitcoin/src/blockdata/script/push_bytes.rs
@@ -7,7 +7,6 @@ use core::fmt;
use core::ops::{Deref, DerefMut};
use crate::crypto::{ecdsa, taproot};
-use crate::internal_macros::impl_asref_push_bytes;
use crate::prelude::{Borrow, BorrowMut};
use crate::script;
@@ -448,7 +447,7 @@ impl AsRef<PushBytes> for taproot::SerializedSignature {
}
}
-impl_asref_push_bytes! {
+crate::impl_asref_push_bytes! {
hashes::ripemd160::Hash,
hashes::hash160::Hash,
hashes::sha1::Hash,
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 85815ee4..b7f31708 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -194,7 +194,7 @@ impl TapTweak for UntweakedKeypair {
}
}
-crate::internal_macros::impl_asref_push_bytes!(PubkeyHash, WPubkeyHash);
+crate::impl_asref_push_bytes!(PubkeyHash, WPubkeyHash);
#[cfg(test)]
mod tests {
diff --git a/bitcoin/src/internal_macros.rs b/bitcoin/src/internal_macros.rs
index 8c614c6f..de9b54e2 100644
--- a/bitcoin/src/internal_macros.rs
+++ b/bitcoin/src/internal_macros.rs
@@ -46,26 +46,6 @@ pub(crate) use impl_consensus_encoding;
// Pull in shared impl_array_newtype_stringify macro from include
include!("../include/array_newtype.rs");
-#[rustfmt::skip]
-macro_rules! impl_asref_push_bytes {
- ($($hashtype:ty),* $(,)?) => {
- $(
- impl AsRef<$crate::script::PushBytes> for $hashtype {
- fn as_ref(&self) -> &$crate::script::PushBytes {
- self.as_byte_array().into()
- }
- }
-
- impl From<$hashtype> for $crate::script::PushBytesBuf {
- fn from(hash: $hashtype) -> Self {
- hash.as_byte_array().into()
- }
- }
- )*
- };
-}
-pub(crate) use impl_asref_push_bytes;
-
macro_rules! only_doc_attrs {
({}, {$($fun:tt)*}) => {
$($fun)*
diff --git a/bitcoin/src/lib.rs b/bitcoin/src/lib.rs
index fc1a53e0..4178e170 100644
--- a/bitcoin/src/lib.rs
+++ b/bitcoin/src/lib.rs
@@ -80,6 +80,7 @@ pub extern crate serde;
mod internal_macros;
include!("../include/newtype.rs"); // Explained in `REPO_DIR/docs/README.md`.
+include!("../include/asref_push_bytes.rs"); // impl_asref_push_bytes! macro
pub mod ext {
//! Re-export all the extension traits so downstream can use wildcard imports.
diff --git a/include/asref_push_bytes.rs b/include/asref_push_bytes.rs
new file mode 100644
index 00000000..e9ef6c22
--- /dev/null
+++ b/include/asref_push_bytes.rs
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: CC0-1.0
+
+/// Implement `AsRef<PushBytes>` and From<$type> for `PushBytesBuf`.
+macro_rules! impl_asref_push_bytes {
+ ($($hashtype:ty),* $(,)?) => {
+ $(
+ impl AsRef<$crate::script::PushBytes> for $hashtype {
+ fn as_ref(&self) -> &$crate::script::PushBytes {
+ self.as_byte_array().into()
+ }
+ }
+
+ impl From<$hashtype> for $crate::script::PushBytesBuf {
+ fn from(hash: $hashtype) -> Self {
+ hash.as_byte_array().into()
+ }
+ }
+ )*
+ };
+}
+pub(crate) use impl_asref_push_bytes;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.