crypto: Re-order taproot::Signature methods
What changed, and why it matters
This commit simply reorders two methods inside the same Rust source file so that the taproot signature code matches the layout of the ECDSA signature code. No code behavior, logic, or public API changed. It is a cosmetic cleanup only.
No action required. This is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff moves serialize() above to_vec() and write_to() within impl Signature in bitcoin/src/crypto/taproot.rs. The method bodies are byte-for-byte identical to their previous versions; only their source order changed. The commit message explicitly states ‘Code move only, no logic change.’
Changed components
bitcoin/src/crypto/taproot.rsInspect captured patch +18 / −18
diff --git a/bitcoin/src/crypto/taproot.rs b/bitcoin/src/crypto/taproot.rs
index 38820016..373d7d35 100644
--- a/bitcoin/src/crypto/taproot.rs
+++ b/bitcoin/src/crypto/taproot.rs
@@ -44,6 +44,24 @@ impl Signature {
}
}
+ /// Serializes the signature (without heap allocation).
+ ///
+ /// This returns a type with an API very similar to that of `Box<[u8]>`.
+ /// You can get a slice from it using deref coercions or turn it into an iterator.
+ pub fn serialize(self) -> SerializedSignature {
+ let mut buf = [0; serialized_signature::MAX_LEN];
+ let ser_sig = self.signature.to_byte_array();
+ buf[..64].copy_from_slice(&ser_sig);
+ let len = if self.sighash_type == TapSighashType::Default {
+ // default sighash type, don't add extra sighash byte
+ 64
+ } else {
+ buf[64] = self.sighash_type as u8;
+ 65
+ };
+ SerializedSignature::from_raw_parts(buf, len)
+ }
+
/// Serializes the signature.
///
/// Note: this allocates on the heap, prefer [`serialize`](Self::serialize) if vec is not needed.
@@ -62,24 +80,6 @@ impl Signature {
let sig = self.serialize();
sig.write_to(writer)
}
-
- /// Serializes the signature (without heap allocation).
- ///
- /// This returns a type with an API very similar to that of `Box<[u8]>`.
- /// You can get a slice from it using deref coercions or turn it into an iterator.
- pub fn serialize(self) -> SerializedSignature {
- let mut buf = [0; serialized_signature::MAX_LEN];
- let ser_sig = self.signature.to_byte_array();
- buf[..64].copy_from_slice(&ser_sig);
- let len = if self.sighash_type == TapSighashType::Default {
- // default sighash type, don't add extra sighash byte
- 64
- } else {
- buf[64] = self.sighash_type as u8;
- 65
- };
- SerializedSignature::from_raw_parts(buf, len)
- }
}
/// An error constructing a [`taproot::Signature`] from a byte slice.
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.