secure-gate 0.9.0-rc.7

Secure wrappers for secrets with explicit access and mandatory zeroization — no_std-compatible, zero-overhead library with audit-friendly access patterns.
Documentation
//! Opt-in marker trait for safe, explicit Serde serialization of secrets.
//!
//! This trait acts as a deliberate security gate: it enables `Serialize` (and
//! optionally `Deserialize`) implementations on secret wrapper types (`Fixed<T>`,
//! `Dynamic<T>`, aliases) **only** when the inner type explicitly opts in.
//!
//! Requires the `serde-serialize` feature.
//!
//! # Security Properties
//!
//! - **No automatic exposure** — Serialization is impossible unless the inner type
//!   implements `SerializableSecret`.
//! - **Explicit risk acceptance** — Cloning/serialization increases the chance of
//!   secret leakage (e.g., via logs, network, disk). This marker forces developers
//!   to acknowledge and accept that risk.
//! - **Zeroization preserved** — Serialization does **not** bypass `ZeroizeOnDrop`;
//!   all copies zeroize on drop.
//! - **No deserialization by default** — `Deserialize` is **not** automatically
//!   enabled; use `serde-deserialize` feature + manual impl if needed.
//!
//! # When to Use
//!
//! Implement `SerializableSecret` **only** when serialization is **truly necessary**:
//!
//! - Encrypted backups of keys/tokens
//! - Secure export for cross-process or cross-device transfer
//! - Persistent storage in encrypted form
//!
//! Prefer **non-serializable designs** wherever possible:
//! - Derive keys on-the-fly from a master secret
//! - Use ephemeral in-memory secrets
//! - Avoid persisting raw secrets at all
//!
//! # A newtype inner type is required (orphan rule)
//!
//! Rust's coherence (orphan) rules prevent downstream crates from implementing
//! this marker for foreign types: `impl SerializableSecret for String`,
//! `Vec<u8>`, or `[u8; 32]` does **not compile** outside this crate, because
//! both the trait and the type would be foreign. Consequently `Fixed<[u8; N]>`,
//! `Dynamic<String>`, and `Dynamic<Vec<u8>>` can never be serialized directly.
//!
//! This is deliberate, not an oversight: if the marker were pre-implemented for
//! the standard container types, enabling the `serde-serialize` feature would
//! silently make *every* wrapped secret in a dependency graph serializable.
//! Requiring a local newtype (as in the example below) keeps each serializable
//! secret type defined — and auditable — in your own code.
//!
//! (`Deserialize` is unaffected: it is implemented on the wrapper types
//! directly, gated by the `serde-deserialize` feature, because deserialization
//! *constructs* a protected secret rather than exposing one.)
//!
//! # Example
//!
//! ```rust
//! use secure_gate::{SerializableSecret, Fixed};
//! use serde::{Serialize, Deserialize};
//! use zeroize::Zeroize;
//!
//! #[derive(Serialize, Deserialize)]
//! struct BackupKey(Vec<u8>);
//!
//! impl Zeroize for BackupKey {
//!     fn zeroize(&mut self) { self.0.zeroize(); }
//! }
//!
//! // Every impl is a deliberate security decision — audit all usages.
//! impl SerializableSecret for BackupKey {}
//!
//! let key = Fixed::new(BackupKey(vec![0u8; 32]));
//! // Serialization exposes the secret — encrypt/authenticate output before storage.
//! // let bytes = bincode::serialize(&key).unwrap();
//! let _ = key;
//! ```
//!
//! # Warnings
//!
//! - **Serialization exposes the secret** — treat serialized output as sensitive.
//!   Encrypt, authenticate, and protect transmission/storage.
//! - **Audit every impl** — ensure the inner type correctly implements `Serialize`
//!   (and `Deserialize` if needed) and `Zeroize`.
//! - **Prefer ephemeral secrets** — avoid persisting raw secrets when possible.
//!
//! This trait is a **marker only** — it has no methods and adds no runtime behavior.
//! It exists solely to gate `Serialize` (and optionally `Deserialize`) on wrapper types.

/// Marker trait that opts a secret type into serialization.
///
/// No methods — its only purpose is to gate the `Serialize` impl on
/// [`Fixed<T>`](crate::Fixed) and [`Dynamic<T>`](crate::Dynamic).
/// Requires the `serde-serialize` feature.
#[cfg(feature = "serde-serialize")]
pub trait SerializableSecret: serde::Serialize {}