Skip to content

zeroize: replace derived Debug with opaque impl for Zeroizing - #1497

Merged
tarcieri merged 1 commit into
RustCrypto:masterfrom
umudique:zeroize/opaque-debug
Jun 13, 2026
Merged

tarcieri merged 1 commit into
RustCrypto:masterfrom
umudique:zeroize/opaque-debug

Conversation

@umudique

Copy link
Copy Markdown
Contributor

Closes #825

Zeroizing<Z> derives Debug right now, which just prints the inner value. Saw this while working on a secret vault project and it was a bit surprising — the whole point of the wrapper is to protect the data.

Going with @tarcieri's suggestion from the issue:

impl<Z: Zeroize + ?Sized> core::fmt::Debug for Zeroizing<Z> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.debug_struct("Zeroizing").finish_non_exhaustive()
    }
}

Now prints Zeroizing { .. }. Also relaxes the bound from Z: Debug to Z: Zeroize + ?Sized so it works for all wrappable types.

Reference project if curious: MeissnerSeal

@tarcieri
tarcieri merged commit 2afc28d into RustCrypto:master Jun 13, 2026
27 checks passed
@tarcieri tarcieri mentioned this pull request Oct 6, 2026
tarcieri added a commit that referenced this pull request Oct 6, 2026
## Changed
- Replace `Zeroizing`'s derived `Debug` with opaque impl (#1497)

## Removed
- Internal use of `optimization_barrier` (#1535)

## Fixed
- Avoid double-zeroizing `Vec`'s initialized elements (#1525)
- False positive failures in proxy allocator test (#1538)
- Potential uninitialized memory read in fallback code used by
  `optimization_barrier` (#1551)
Slurp9187 added a commit to Slurp9187/secure-gate that referenced this pull request Oct 29, 2026
zeroize 1.9.1 replaced Zeroizing's derived Debug with an opaque
`Zeroizing { .. }` (RustCrypto/utils#1497); 1.9.0 and earlier printed the
wrapped value. The test that pinned the old printing behavior
(encoded_secret_into_zeroizing_carries_the_content) failed on the 1.9.1
lockfile, which is what it was there to catch.

With the requirement at "1.9.1" (>= 1.9.1, < 2) a dependent cannot
resolve a printing version, so the docs can state the opaque form without
a version caveat. EncodedSecret::into_zeroizing, the crate docs and
SECURITY.md now say: the wipe and an opaque Debug carry over, and what is
lost is the rest of EncodedSecret, since Zeroizing<String> derefs to
String. The test now pins the opaque Debug, with a positive control that
the deref still reaches the bytes.

The dev-dependency and the fuzz crate move with it. 1.9.1 declares
rust-version 1.85, inside this release's 1.87 floor. guarded-block's own
requirement moved to 1.9 separately in 98851f8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SL2CGpoMkfiH32imMDifH8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace Zeroizing derive(Debug) with an empty block

2 participants