primitives: Remove Witness::from_parts__unstable
What changed, and why it matters
This commit simply removes an internal helper function that was no longer used. It is a routine cleanup change with no security relevance.
No action needed; this is a non-security refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch removes Witness::from_parts__unstable, a #[doc(hidden)] public-but-unstable constructor in primitives/src/witness.rs. The only remaining caller was the WitnessDecoder implementation, which is rewritten to construct the Witness struct directly. Associated unit tests and a test helper are also removed. There is no change to parsing logic, validation, or exposed behavior.
Changed components
primitives/src/witness.rsInspect captured patch +4 / −43
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index ab7c0917..900a6ed7 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -70,23 +70,6 @@ impl Witness {
Self { content: Vec::new(), witness_elements: 0, indices_start: 0 }
}
- /// Constructs a new [`Witness`] from inner parts.
- ///
- /// This function leaks implementation details of the `Witness`, as such it is unstable and
- /// should not be relied upon (it is primarily provided for use in `rust-bitcoin`).
- ///
- /// UNSTABLE: This function may change, break, or disappear in any release.
- #[inline]
- #[doc(hidden)]
- #[allow(non_snake_case)] // Because of `__unstable`.
- pub fn from_parts__unstable(
- content: Vec<u8>,
- witness_elements: usize,
- indices_start: usize,
- ) -> Self {
- Self { content, witness_elements, indices_start }
- }
-
/// Constructs a new [`Witness`] object from a slice of bytes slices where each slice is a witness item.
pub fn from_slice<T: AsRef<[u8]>>(slice: &[T]) -> Self {
let witness_elements = slice.len();
@@ -483,11 +466,11 @@ impl Decoder for WitnessDecoder {
let witness_index_space = witness_elements * 4;
self.content.rotate_left(witness_index_space);
- Ok(Witness::from_parts__unstable(
- self.content,
+ Ok(Witness {
+ content: self.content,
witness_elements,
- self.cursor - witness_index_space,
- ))
+ indices_start: self.cursor - witness_index_space,
+ })
} else {
Err(E(Inner::UnexpectedEof(UnexpectedEofError { missing_elements: remaining })))
}
@@ -912,15 +895,6 @@ mod test {
use super::*;
- // Appends all the indices onto the end of a list of elements.
- fn append_u32_vec(elements: &[u8], indices: &[u32]) -> Vec<u8> {
- let mut v = elements.to_vec();
- for &num in indices {
- v.extend_from_slice(&num.to_ne_bytes());
- }
- v
- }
-
// A witness with a single element that is empty (zero length).
fn single_empty_element() -> Witness { Witness::from([[0u8; 0]]) }
@@ -1018,19 +992,6 @@ mod test {
}
}
- #[test]
- fn witness_from_parts() {
- let elements = [1u8, 11, 2, 21, 22];
- let witness_elements = 2;
- let content = append_u32_vec(&elements, &[0, 2]);
- let indices_start = elements.len();
- let witness =
- Witness::from_parts__unstable(content, witness_elements, indices_start);
- assert_eq!(witness.get(0).unwrap(), [11_u8]);
- assert_eq!(witness.get(1).unwrap(), [21_u8, 22]);
- assert_eq!(witness.size(), 6);
- }
-
#[test]
fn witness_from_impl() {
// Test From implementations with the same 2 elements
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.