Remove Index<RangeFull> from PrivateKey
What changed, and why it matters
This commit removes the ability to use square-bracket slicing (like `private_key[..]`) on a Bitcoin private key. The change is part of a longer-term effort to prevent secret key material from being accidentally exposed through Rust's indexing features. It is a hardening cleanup rather than a fix for an active security flaw.
Treat as a routine hardening improvement. Reviewers should verify that remaining public methods on `PrivateKey` still expose secret bytes only intentionally (e.g., explicit serialization APIs), and that downstream code does not rely on `private_key[..]` syntax, which will now fail to compile.
Security signals we found
Removal of direct secret-key byte exposure through indexing
Defensive API hardening for private key material
No explicit vulnerability, exploit, or incident described in commit
Evidence from the diff
The patch deletes the impl ops::Index<ops::RangeFull> for PrivateKey block in bitcoin/src/crypto/key.rs. That implementation returned a byte slice of the underlying secret key via &self.as_inner()[..]. Removing it closes one direct path for code to obtain a raw reference to secret bytes simply by indexing the PrivateKey. It is a defensive API-hardening change; the commit message frames it as working toward hiding secret data in PrivateKey.
Changed components
bitcoin/src/crypto/key.rsPrivateKey typecore::ops::Index<RangeFull> implementationInspect captured patch +0 / −6
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 772bba3b..8b54f624 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -7,7 +7,6 @@
use core::convert::Infallible;
use core::fmt::{self, Write as _};
-use core::ops;
use core::str::FromStr;
use hashes::hash160;
@@ -1041,11 +1040,6 @@ impl FromStr for PrivateKey {
fn from_str(s: &str) -> Result<Self, FromWifError> { Self::from_wif(s) }
}
-impl ops::Index<ops::RangeFull> for PrivateKey {
- type Output = [u8];
- fn index(&self, _: ops::RangeFull) -> &[u8] { &self.as_inner()[..] }
-}
-
#[cfg(feature = "serde")]
impl serde::Serialize for PrivateKey {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
Why this scored 29/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.