1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
//! secrecy **v0.8.0** compatibility layer.
//!
//! This module is a near-exact API mirror of [`secrecy`](https://crates.io/crates/secrecy)
//! v0.8.0 (`edition = "2018"`, `rust-version = "~1.52"`).
//!
//! # Drop-in replacement
//!
//! The only required change for secrecy 0.8.x users is a mechanical import swap:
//!
//! ```text
//! // Before
//! use secrecy::{Secret, SecretString, SecretVec, DebugSecret, CloneableSecret, ExposeSecret};
//!
//! // After (one global find/replace)
//! use secure_gate::compat::v08::{Secret, SecretString, SecretVec, DebugSecret};
//! use secure_gate::compat::{CloneableSecret, ExposeSecret};
//! ```
//!
//! # API table
//!
//! | secrecy 0.8 | This module | Notes |
//! |---|---|---|
//! | `Secret<S>` | [`Secret<S>`] | Stack/inline; `S: Zeroize` |
//! | `SecretString` | [`SecretString`] | = `Secret<String>` |
//! | `SecretVec<T>` | [`SecretVec<T>`] | = `Secret<Vec<T>>` |
//! | `SecretBox<S>` | [`SecretBox<S>`] | = `Secret<Box<S>>` |
//! | `ExposeSecret<S>` | [`compat::ExposeSecret`](super::ExposeSecret) | Shared trait |
//! | `CloneableSecret` | [`compat::CloneableSecret`](super::CloneableSecret) | Shared trait |
//! | `DebugSecret` | [`DebugSecret`] | v0.8-only trait |
//! | `SerializableSecret` | [`compat::SerializableSecret`](super::SerializableSecret) | Shared trait |
//! | `Zeroize` re-export | [`compat::zeroize`](super::zeroize) | Shared re-export |
//!
//! # Key differences from v0.10
//!
//! - `Secret<S>` is **stack-allocated** (inline `S`) — no `Box`. Use `SecretBox<S>` for
//! heap-allocated variants.
//! - No [`ExposeSecretMut`](super::ExposeSecretMut) — mutable access was added in v0.9.
//! - [`DebugSecret`] trait is required for `Debug` impls. Not present in v0.10.
//!
//! # Step-by-step migration
//!
//! 1. Replace `secrecy` dependency with `secure-gate` + `features = ["secrecy-compat"]`
//! 2. Find/replace `use secrecy::` → `use secure_gate::compat::v08::` (types) or
//! `use secure_gate::compat::` (traits)
//! 3. Gradually replace `v08::Secret<String>` with [`Dynamic<String>`](crate::Dynamic) using
//! the provided [`From`] conversions
//! 4. Replace `v08::Secret<[T; N]>` with [`Fixed<[T; N]>`](crate::Fixed)
//! 5. Remove `secrecy-compat` feature once fully migrated
extern crate alloc;
use Box;
use String;
use Vec;
use FromStr;
use ;
use Zeroize;
use CloneableSecret;
use ExposeSecret;
use SerializableSecret;
// ── DebugSecret ───────────────────────────────────────────────────────────────
/// Opt-in debug display for secret types — mirrors `secrecy::DebugSecret`.
///
/// Implementing this trait on a type `S` enables `Debug for Secret<S>`, which
/// will call `S::debug_secret` instead of exposing the value.
///
/// The default impl prints `[REDACTED typename]`. Override to customize the label.
///
/// # Example
///
/// ```rust
/// # #[cfg(feature = "secrecy-compat")] {
/// use secure_gate::compat::v08::{DebugSecret, Secret};
///
/// struct ApiKey(String);
/// impl zeroize::Zeroize for ApiKey { fn zeroize(&mut self) { self.0.zeroize(); } }
/// impl DebugSecret for ApiKey {}
///
/// let key = Secret::new(ApiKey(String::from("sk_live_xyz")));
/// // prints: Secret([REDACTED secrecy_compat_test::ApiKey]) or similar
/// println!("{:?}", key);
/// # }
/// ```
// Blanket impls mirroring v0.8 — upgraded from size-list macros to const generics.
// ── Additional CloneableSecret impls (v0.8-specific) ─────────────────────────
//
// secrecy 0.8 provides `CloneableSecret` for `String` and `Vec<S: CloneableSecret>`.
// These are not included in the shared mod.rs (where the trait is defined) because
// v0.10 deliberately does NOT make `SecretBox<String>` auto-cloneable.
// ── Secret<S> ────────────────────────────────────────────────────────────────
/// Stack/inline secret wrapper — mirrors `secrecy::Secret`.
///
/// Stores the secret value **directly** (no heap allocation). On drop, calls
/// `S::zeroize()` to wipe the memory. Access is only possible through
/// [`ExposeSecret`](super::ExposeSecret).
///
/// # Generic parameter
///
/// `S` must implement [`Zeroize`] for secure erasure on drop.
///
/// # Debug
///
/// `Debug` is only available when `S: DebugSecret`. The output is always
/// `Secret([REDACTED typename])` — the inner value is never printed.
///
/// # Migration to native secure-gate
///
/// ```rust
/// # #[cfg(feature = "secrecy-compat")] {
/// use secure_gate::compat::v08::Secret;
/// use secure_gate::Dynamic;
///
/// // String → heap-allocated Dynamic<String>
/// let old: Secret<String> = Secret::new(String::from("hunter2"));
/// let native: Dynamic<String> = old.into();
///
/// // [u8; 32] → stack-allocated Fixed<[u8; 32]>
/// use secure_gate::Fixed;
/// let key: Secret<[u8; 32]> = Secret::new([0xABu8; 32]);
/// let fixed: Fixed<[u8; 32]> = key.into();
/// # }
/// ```
// ── SecretString ─────────────────────────────────────────────────────────────
/// Secret string type — mirrors `secrecy::SecretString` (v0.8).
///
/// Type alias for `Secret<String>`. Implements `FromStr`, `Clone` (via
/// `String: CloneableSecret`), and `Debug` (via `String: DebugSecret`).
///
/// Note: secrecy 0.10's `SecretString` is `SecretBox<str>` (different type).
/// Use [`v10::SecretString`](super::v10::SecretString) when migrating to v0.10 semantics.
pub type SecretString = ;
// ── SecretVec ─────────────────────────────────────────────────────────────────
/// Secret vector type — mirrors `secrecy::SecretVec` (v0.8).
///
/// Type alias for `Secret<Vec<T>>`.
pub type SecretVec<T> = ;
// ── SecretBox ─────────────────────────────────────────────────────────────────
/// Secret boxed type — mirrors `secrecy::SecretBox` (v0.8).
///
/// Type alias for `Secret<Box<S>>`. Note that this is **different** from
/// [`v10::SecretBox`](super::v10::SecretBox), which is a newtype around `Box<S>` with
/// `?Sized` support. This v0.8 variant stores `Box<S>` as the `S` in `Secret<S>`.
///
/// # Zeroize requirement
///
/// `Box<S>` must implement [`Zeroize`]. In zeroize ≥ 1.8, this is only provided for
/// `Box<[Z]>` (heap slices, `Z: Zeroize`) and `Box<str>`. For sized secret buffers,
/// prefer [`v10::SecretBox`](super::v10::SecretBox) or the native
/// [`Dynamic<T>`](crate::Dynamic).
pub type SecretBox<S> = ;
// ── Serde ─────────────────────────────────────────────────────────────────────
// ── Conversions: Secret ↔ Dynamic / Fixed ────────────────────────────────────
//
// All conversions require Clone because `Secret<S>` has a `Drop` impl and
// `#![forbid(unsafe_code)]` prevents us from moving the field out directly.
// The clone is brief: the original is zeroized when it drops at the end of the
// conversion function body.
/// Converts `Secret<String>` into a [`Dynamic<String>`](crate::Dynamic).
/// Converts a [`Dynamic<String>`](crate::Dynamic) into `Secret<String>`.
/// Converts `Secret<Vec<T>>` into a [`Dynamic<Vec<T>>`](crate::Dynamic).
/// Converts a [`Dynamic<Vec<T>>`](crate::Dynamic) into `Secret<Vec<T>>`.
/// Converts `Secret<[T; N]>` into a [`Fixed<[T; N]>`](crate::Fixed).
/// Converts a [`Fixed<[T; N]>`](crate::Fixed) into `Secret<[T; N]>`.