Add Lower/UperHex impls for taproot::SerializedSignature
What changed, and why it matters
This commit adds two new ways to display a taproot serialized signature as hexadecimal text (lowercase and uppercase). It is a pure API-consistency change to make taproot signatures match the existing ecdsa signature API. There is no security issue visible in the diff.
No security action required. Review as normal API addition if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change implements fmt::LowerHex and fmt::UpperHex for taproot::SerializedSignature, plus a helper macro impl_to_hex_from_lower_hex! that derives a to_hex method. The implementations delegate to the existing as_hex()/DisplayHex machinery and use the signature length to size the output. No cryptographic operations, parsing, memory-unsafe code, or authorization logic is introduced or modified.
Changed components
bitcoin/src/crypto/taproot.rsInspect captured patch +18 / −2
diff --git a/bitcoin/src/crypto/taproot.rs b/bitcoin/src/crypto/taproot.rs
index 30f69356..17ce395e 100644
--- a/bitcoin/src/crypto/taproot.rs
+++ b/bitcoin/src/crypto/taproot.rs
@@ -11,10 +11,10 @@ use core::{fmt, ops};
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
use internals::array::ArrayExt;
-use internals::write_err;
+use internals::{impl_to_hex_from_lower_hex, write_err};
use io::Write;
-use crate::prelude::Vec;
+use crate::prelude::{DisplayHex, Vec};
use crate::sighash::{InvalidSighashTypeError, TapSighashType};
pub use self::into_iter::IntoIter;
@@ -148,6 +148,22 @@ impl fmt::Display for SerializedSignature {
}
}
+impl fmt::LowerHex for SerializedSignature {
+ #[inline]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fmt::LowerHex::fmt(&(**self).as_hex(), f)
+ }
+}
+impl_to_hex_from_lower_hex!(SerializedSignature, |signature: &SerializedSignature| signature.len
+ * 2);
+
+impl fmt::UpperHex for SerializedSignature {
+ #[inline]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fmt::UpperHex::fmt(&(**self).as_hex(), f)
+ }
+}
+
impl PartialEq for SerializedSignature {
#[inline]
fn eq(&self, other: &Self) -> bool { **self == **other }
Why this scored 16/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.