secure-gate 0.8.0-rc.7

Secure wrappers for secrets with explicit access and automatic zeroization (requires inner type: Zeroize)
Documentation
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
//! Stack-allocated wrapper for fixed-size secrets.
//!
//! [`Fixed<T>`] is a zero-cost wrapper that enforces explicit, auditable access to
//! sensitive data stored inline on the stack. It is the primary secret type for
//! fixed-length material such as cryptographic keys, nonces, and seeds.
//!
//! # Security invariants
//!
//! - **No `Deref`, `AsRef`, or `Copy`** — the inner value cannot leak through
//!   implicit conversions.
//! - **`Debug` always prints `[REDACTED]`** — secrets never appear in logs or
//!   panic messages.
//! - **Unconditional zeroization on drop** — the inner `T` is overwritten with
//!   zeroes when the wrapper is dropped, even on error paths.
//! - **Opt-in `Clone`** — requires `T: CloneableSecret` and the `cloneable` feature.
//! - **Opt-in `Serialize`/`Deserialize`** — requires marker traits and the
//!   `serde-serialize`/`serde-deserialize` features.
//!
//! # Construction
//!
//! | Constructor | Notes |
//! |---|---|
//! | [`Fixed::new(value)`](Fixed::new) | Ergonomic default; `const fn`. |
//! | [`Fixed::new_with(f)`](Fixed::new_with) | Scoped — preferred for stack-residue minimization. |
//!
//! Prefer [`new_with`](Fixed::new_with) in high-assurance code: it writes directly
//! into the wrapper's storage, avoiding the intermediate stack copy that `new` may
//! produce.
//!
//! # 3-tier access model
//!
//! ```rust
//! use secure_gate::{Fixed, RevealSecret, RevealSecretMut};
//!
//! let mut secret = Fixed::new([1u8, 2, 3, 4]);
//!
//! // Tier 1 — scoped (preferred): borrow is confined to the closure.
//! let sum = secret.with_secret(|arr| arr.iter().sum::<u8>());
//! assert_eq!(sum, 10);
//!
//! // Tier 2 — direct: returns a reference. Use as an escape hatch.
//! let first: u8 = secret.expose_secret()[0];
//! assert_eq!(first, 1);
//!
//! // Tier 1 mutable — scoped mutation (preferred over Tier 2 mutable).
//! secret.with_secret_mut(|arr| arr[0] = 0xFF);
//!
//! // Tier 3 — owned: consumes the wrapper for final use.
//! let owned = secret.into_inner();
//! ```
//!
//! # Warning: no `static` secrets
//!
//! `Drop` does not run on `static` items. Placing a `Fixed` in a `static` or
//! `lazy_static!` will **skip zeroization**. Always use stack or heap allocation.
//!
//! Also ensure your profile sets `panic = "unwind"` — `panic = "abort"` skips
//! destructors and therefore skips zeroization.
//!
//! # Import path
//!
//! All public items are re-exported at the crate root. Use:
//!
//! ```rust
//! use secure_gate::Fixed;
//! ```
//!
//! Not `secure_gate::fixed::Fixed`.
//!
//! # See also
//!
//! - [`Dynamic<T>`](crate::Dynamic) — heap-allocated alternative for variable-length
//!   secrets (passwords, API keys, ciphertexts). Requires the `alloc` feature.
//!
//! # Examples
//!
//! ```rust
//! use secure_gate::{Fixed, RevealSecret};
//!
//! let secret = Fixed::new([1u8, 2, 3, 4]);
//! let sum = secret.with_secret(|arr| arr.iter().sum::<u8>());
//! assert_eq!(sum, 10);
//! ```

use crate::RevealSecret;
use crate::RevealSecretMut;

#[cfg(all(feature = "encoding-base64", feature = "alloc"))]
use crate::traits::encoding::base64_url::ToBase64Url;
#[cfg(all(feature = "encoding-bech32", feature = "alloc"))]
use crate::traits::encoding::bech32::ToBech32;
#[cfg(all(feature = "encoding-bech32m", feature = "alloc"))]
use crate::traits::encoding::bech32m::ToBech32m;
#[cfg(all(feature = "encoding-hex", feature = "alloc"))]
use crate::traits::encoding::hex::ToHex;

#[cfg(feature = "rand")]
use rand::{rngs::OsRng, TryCryptoRng, TryRngCore};
use zeroize::Zeroize;

/// Zero-cost stack-allocated wrapper for fixed-size secrets.
///
/// `Fixed<T>` stores a `T: Zeroize` value inline and unconditionally zeroizes it
/// on drop. There is no `Deref`, `AsRef`, or `Copy` — every access is explicit
/// through [`RevealSecret`] or [`RevealSecretMut`].
///
/// # Examples
///
/// ```rust
/// use secure_gate::{Fixed, RevealSecret};
///
/// // Create a secret key.
/// let key = Fixed::new([0xABu8; 32]);
///
/// // Scoped access — the borrow cannot escape the closure.
/// let first = key.with_secret(|k| k[0]);
/// assert_eq!(first, 0xAB);
///
/// // Debug is always redacted.
/// assert_eq!(format!("{:?}", key), "[REDACTED]");
/// ```
///
/// # Constructors
///
/// | Constructor | Feature | Notes |
/// |---|---|---|
/// | [`new(value)`](Self::new) | — | `const fn`, ergonomic default |
/// | [`new_with(f)`](Self::new_with) | — | Scoped; preferred for stack-residue minimization |
/// | [`From<[u8; N]>`](#impl-From<%5Bu8;+N%5D>-for-Fixed<%5Bu8;+N%5D>) | — | Equivalent to `new` |
/// | [`TryFrom<&[u8]>`](#impl-TryFrom<%26%5Bu8%5D>-for-Fixed<%5Bu8;+N%5D>) | — | Length-checked slice conversion |
/// | [`try_from_hex`](Self::try_from_hex) | `encoding-hex` | Constant-time hex decoding |
/// | [`try_from_base64url`](Self::try_from_base64url) | `encoding-base64` | Constant-time Base64url decoding |
/// | [`try_from_bech32`](Self::try_from_bech32) | `encoding-bech32` | HRP-validated Bech32 decoding |
/// | [`try_from_bech32_unchecked`](Self::try_from_bech32_unchecked) | `encoding-bech32` | Bech32 without HRP check |
/// | [`try_from_bech32m`](Self::try_from_bech32m) | `encoding-bech32m` | HRP-validated Bech32m decoding |
/// | [`try_from_bech32m_unchecked`](Self::try_from_bech32m_unchecked) | `encoding-bech32m` | Bech32m without HRP check |
/// | [`from_random()`](Self::from_random) | `rand` | System RNG |
/// | [`from_rng(rng)`](Self::from_rng) | `rand` | Custom RNG |
///
/// # See also
///
/// - [`RevealSecret`] / [`RevealSecretMut`] — the 3-tier access traits.
/// - [`new_with`](Self::new_with) — scoped constructor preferred over [`new`](Self::new).
///
/// # Note
///
/// `const fn new` compiles in `static` position, but **must not** be used there
/// because `Drop` does not run on statics, which means zeroization is skipped.
pub struct Fixed<T: zeroize::Zeroize> {
    inner: T,
}

impl<T: zeroize::Zeroize> Fixed<T> {
    /// Creates a new [`Fixed<T>`] by wrapping a value.
    ///
    /// This is a `const fn`, so it can be evaluated at compile time. However,
    /// **do not** use it to initialize `static` items — `Drop` does not run on
    /// statics, so zeroization would be skipped.
    ///
    /// For `Fixed<[u8; N]>`, prefer [`new_with`](Fixed::new_with) when minimizing
    /// stack residue matters, as `new` may leave an intermediate copy of `value`
    /// on the caller's stack frame.
    ///
    /// # Examples
    ///
    /// ```rust
    /// use secure_gate::{Fixed, RevealSecret};
    ///
    /// let secret = Fixed::new([0u8; 32]);
    /// assert_eq!(secret.len(), 32);
    /// ```
    #[inline(always)]
    pub const fn new(value: T) -> Self {
        Fixed { inner: value }
    }
}

/// Converts a byte array into a [`Fixed`] wrapper (equivalent to [`Fixed::new`]).
///
/// # Examples
///
/// ```rust
/// use secure_gate::Fixed;
///
/// let secret: Fixed<[u8; 4]> = [1u8, 2, 3, 4].into();
/// ```
impl<const N: usize> From<[u8; N]> for Fixed<[u8; N]> {
    #[inline(always)]
    fn from(arr: [u8; N]) -> Self {
        Self::new(arr)
    }
}

/// Converts a byte slice into `Fixed<[u8; N]>`, failing if the length does not
/// match `N`.
///
/// Internally uses [`Fixed::new_with`] so the secret is written directly into
/// the wrapper's storage.
///
/// # Errors
///
/// Returns [`FromSliceError::InvalidLength`](crate::error::FromSliceError) when
/// `slice.len() != N`.
///
/// # Examples
///
/// ```rust
/// use secure_gate::{Fixed, RevealSecret};
///
/// // Success — exact length.
/// let data = [0xFFu8; 4];
/// let secret = Fixed::<[u8; 4]>::try_from(data.as_slice()).unwrap();
/// assert_eq!(secret.expose_secret()[0], 0xFF);
///
/// // Failure — wrong length.
/// let short = [0u8; 2];
/// assert!(Fixed::<[u8; 4]>::try_from(short.as_slice()).is_err());
/// ```
impl<const N: usize> core::convert::TryFrom<&[u8]> for Fixed<[u8; N]> {
    type Error = crate::error::FromSliceError;

    fn try_from(slice: &[u8]) -> Result<Self, Self::Error> {
        if slice.len() != N {
            #[cfg(debug_assertions)]
            return Err(crate::error::FromSliceError::InvalidLength {
                actual: slice.len(),
                expected: N,
            });
            #[cfg(not(debug_assertions))]
            return Err(crate::error::FromSliceError::InvalidLength);
        }
        Ok(Self::new_with(|arr| arr.copy_from_slice(slice)))
    }
}

/// Construction and ergonomic encoding helpers for `Fixed<[u8; N]>`.
impl<const N: usize> Fixed<[u8; N]> {
    /// Writes directly into the wrapper's storage via a user-supplied closure,
    /// eliminating the intermediate stack copy that [`new`](Self::new) may produce.
    ///
    /// The array is zero-initialized before the closure runs. Prefer this over
    /// [`new(value)`](Self::new) when minimizing stack residue matters
    /// (long-lived keys, high-assurance environments).
    ///
    /// # Security rationale
    ///
    /// With [`Fixed::new(value)`](Self::new), the caller first builds `value` on
    /// its own stack frame, then moves it into the wrapper. The compiler *may*
    /// elide the copy, but this is not guaranteed — leaving a plaintext residue
    /// on the stack. `new_with` avoids this by giving the closure a mutable
    /// reference to the wrapper's *own* storage, so the secret is never placed
    /// anywhere else.
    ///
    /// # Examples
    ///
    /// ```rust
    /// use secure_gate::{Fixed, RevealSecret};
    ///
    /// // Fill from a closure — no intermediate stack copy.
    /// let secret = Fixed::<[u8; 4]>::new_with(|arr| arr.fill(0xAB));
    /// assert_eq!(secret.expose_secret(), &[0xAB; 4]);
    ///
    /// // Copy from an existing slice.
    /// let src = [1u8, 2, 3, 4];
    /// let secret = Fixed::<[u8; 4]>::new_with(|arr| arr.copy_from_slice(&src));
    /// ```
    ///
    /// # See also
    ///
    /// - [`Dynamic::new_with`](crate::Dynamic::new_with) — the heap-allocated
    ///   equivalent (requires `alloc`).
    #[inline(always)]
    pub fn new_with<F>(f: F) -> Self
    where
        F: FnOnce(&mut [u8; N]),
    {
        let mut this = Self { inner: [0u8; N] };
        f(&mut this.inner);
        this
    }
}

/// Hex encoding and decoding for `Fixed<[u8; N]>`.
///
/// Encoding uses a constant-time backend (`base16ct`). Decoding works with or without
/// the `alloc` feature — on no-alloc targets the bytes are decoded directly into a
/// `Zeroizing<[u8; N]>` stack buffer.
#[cfg(feature = "encoding-hex")]
impl<const N: usize> Fixed<[u8; N]> {
    /// Encodes the secret bytes as a lowercase hex string.
    ///
    /// Requires the `encoding-hex` and `alloc` features.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(all(feature = "encoding-hex", feature = "alloc"))]
    /// # {
    /// use secure_gate::Fixed;
    ///
    /// let secret = Fixed::new([0xDE, 0xAD]);
    /// assert_eq!(secret.to_hex(), "dead");
    /// # }
    /// ```
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn to_hex(&self) -> alloc::string::String {
        self.with_secret(|s: &[u8; N]| s.to_hex())
    }

    /// Encodes the secret bytes as an uppercase hex string.
    ///
    /// Requires the `encoding-hex` and `alloc` features.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(all(feature = "encoding-hex", feature = "alloc"))]
    /// # {
    /// use secure_gate::Fixed;
    ///
    /// let secret = Fixed::new([0xDE, 0xAD]);
    /// assert_eq!(secret.to_hex_upper(), "DEAD");
    /// # }
    /// ```
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn to_hex_upper(&self) -> alloc::string::String {
        self.with_secret(|s: &[u8; N]| s.to_hex_upper())
    }

    /// Encodes the secret bytes as a lowercase hex string, returning
    /// [`EncodedSecret`](crate::EncodedSecret) to preserve zeroization.
    ///
    /// Prefer this over [`to_hex`](Self::to_hex) when the encoded form should
    /// still be treated as sensitive (e.g. private keys). The returned
    /// [`EncodedSecret`](crate::EncodedSecret) is zeroized on drop.
    ///
    /// Requires the `encoding-hex` and `alloc` features.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(all(feature = "encoding-hex", feature = "alloc"))]
    /// # {
    /// use secure_gate::{Fixed, RevealSecret};
    ///
    /// let secret = Fixed::new([0xCA, 0xFE]);
    /// let encoded = secret.to_hex_zeroizing();
    /// assert_eq!(&*encoded, "cafe");
    /// // `encoded` is zeroized when it goes out of scope.
    /// # }
    /// ```
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn to_hex_zeroizing(&self) -> crate::EncodedSecret {
        self.with_secret(|s: &[u8; N]| s.to_hex_zeroizing())
    }

    /// Encodes the secret bytes as an uppercase hex string, returning
    /// [`EncodedSecret`](crate::EncodedSecret) to preserve zeroization.
    ///
    /// Requires the `encoding-hex` and `alloc` features.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(all(feature = "encoding-hex", feature = "alloc"))]
    /// # {
    /// use secure_gate::{Fixed, RevealSecret};
    ///
    /// let secret = Fixed::new([0xCA, 0xFE]);
    /// let encoded = secret.to_hex_upper_zeroizing();
    /// assert_eq!(&*encoded, "CAFE");
    /// # }
    /// ```
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn to_hex_upper_zeroizing(&self) -> crate::EncodedSecret {
        self.with_secret(|s: &[u8; N]| s.to_hex_upper_zeroizing())
    }

    /// Decodes a hex string (lowercase, uppercase, or mixed) into `Fixed<[u8; N]>`.
    ///
    /// Uses a constant-time backend (`base16ct`) for both paths.
    ///
    /// - **With `alloc`**: decodes into a `Zeroizing<Vec<u8>>` then copies onto the stack.
    ///   The temporary heap buffer is zeroed on drop even if an error occurs.
    /// - **Without `alloc`**: decodes directly into a `Zeroizing<[u8; N]>` stack buffer.
    ///   No heap allocation occurs.
    ///
    /// # Errors
    ///
    /// - [`HexError::InvalidHex`] — non-hex characters or odd-length input.
    /// - [`HexError::InvalidLength`] — decoded byte count does not equal `N`.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(feature = "encoding-hex")]
    /// # {
    /// use secure_gate::{Fixed, RevealSecret};
    ///
    /// // Round-trip: encode then decode.
    /// let original = Fixed::new([0xDE, 0xAD, 0xBE, 0xEF]);
    /// # #[cfg(feature = "alloc")]
    /// # {
    /// let hex_str = original.to_hex();
    /// let decoded = Fixed::<[u8; 4]>::try_from_hex(&hex_str).unwrap();
    /// assert_eq!(decoded.expose_secret(), &[0xDE, 0xAD, 0xBE, 0xEF]);
    /// # }
    ///
    /// // Wrong length fails.
    /// assert!(Fixed::<[u8; 2]>::try_from_hex("deadbeef").is_err());
    /// # }
    /// ```
    pub fn try_from_hex(hex: &str) -> Result<Self, crate::error::HexError> {
        #[cfg(feature = "alloc")]
        {
            use zeroize::Zeroizing;
            let bytes = Zeroizing::new(
                base16ct::mixed::decode_vec(hex.as_bytes())
                    .map_err(|_| crate::error::HexError::InvalidHex)?,
            );
            if bytes.len() != N {
                #[cfg(debug_assertions)]
                return Err(crate::error::HexError::InvalidLength {
                    expected: N,
                    got: bytes.len(),
                });
                #[cfg(not(debug_assertions))]
                return Err(crate::error::HexError::InvalidLength);
            }
            Ok(Self::new_with(|arr| arr.copy_from_slice(&bytes)))
        }
        #[cfg(not(feature = "alloc"))]
        {
            use zeroize::Zeroizing;
            // no-alloc path: decode directly into a stack buffer; no heap allocation
            // base16ct::mixed accepts upper, lower, and mixed-case hex
            let mut buf = Zeroizing::new([0u8; N]);
            let decoded = base16ct::mixed::decode(hex.as_bytes(), &mut *buf)
                .map_err(|_| crate::error::HexError::InvalidHex)?;
            if decoded.len() != N {
                #[cfg(debug_assertions)]
                return Err(crate::error::HexError::InvalidLength {
                    expected: N,
                    got: decoded.len(),
                });
                #[cfg(not(debug_assertions))]
                return Err(crate::error::HexError::InvalidLength);
            }
            Ok(Self::new_with(|arr| arr.copy_from_slice(decoded)))
            // buf is zeroized on drop (both success and error paths)
        }
    }
}

/// Base64url encoding and decoding for `Fixed<[u8; N]>`.
///
/// Encoding uses a constant-time backend (`base64ct`). Decoding works with or without
/// the `alloc` feature — on no-alloc targets the bytes are decoded directly into a
/// `Zeroizing<[u8; N]>` stack buffer.
#[cfg(feature = "encoding-base64")]
impl<const N: usize> Fixed<[u8; N]> {
    /// Encodes the secret bytes as an unpadded Base64url string (RFC 4648, URL-safe alphabet).
    ///
    /// Requires the `encoding-base64` and `alloc` features.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(all(feature = "encoding-base64", feature = "alloc"))]
    /// # {
    /// use secure_gate::Fixed;
    ///
    /// let secret = Fixed::new([0xDE, 0xAD, 0xBE, 0xEF]);
    /// let encoded = secret.to_base64url();
    /// assert_eq!(encoded, "3q2-7w");
    /// # }
    /// ```
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn to_base64url(&self) -> alloc::string::String {
        self.with_secret(|s: &[u8; N]| s.to_base64url())
    }

    /// Encodes the secret bytes as an unpadded Base64url string, returning
    /// [`EncodedSecret`](crate::EncodedSecret) to preserve zeroization.
    ///
    /// Prefer this over [`to_base64url`](Self::to_base64url) when the encoded
    /// form should still be treated as sensitive. The returned
    /// [`EncodedSecret`](crate::EncodedSecret) is zeroized on drop.
    ///
    /// Requires the `encoding-base64` and `alloc` features.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(all(feature = "encoding-base64", feature = "alloc"))]
    /// # {
    /// use secure_gate::{Fixed, RevealSecret};
    ///
    /// let secret = Fixed::new([0xDE, 0xAD, 0xBE, 0xEF]);
    /// let encoded = secret.to_base64url_zeroizing();
    /// assert_eq!(&*encoded, "3q2-7w");
    /// // `encoded` is zeroized when it goes out of scope.
    /// # }
    /// ```
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn to_base64url_zeroizing(&self) -> crate::EncodedSecret {
        self.with_secret(|s: &[u8; N]| s.to_base64url_zeroizing())
    }

    /// Decodes an unpadded Base64url string (RFC 4648, URL-safe alphabet) into
    /// `Fixed<[u8; N]>`.
    ///
    /// Uses a constant-time backend (`base64ct`) on both paths.
    ///
    /// - **With `alloc`**: decodes into a `Zeroizing<Vec<u8>>` then copies onto the stack.
    /// - **Without `alloc`**: decodes directly into a `Zeroizing<[u8; N]>` stack buffer.
    ///
    /// # Errors
    ///
    /// - [`Base64Error::InvalidBase64`] — non-base64 characters or invalid padding.
    /// - [`Base64Error::InvalidLength`] — decoded byte count does not equal `N`.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(feature = "encoding-base64")]
    /// # {
    /// use secure_gate::{Fixed, RevealSecret};
    ///
    /// # #[cfg(feature = "alloc")]
    /// # {
    /// // Round-trip.
    /// let original = Fixed::new([0xDE, 0xAD, 0xBE, 0xEF]);
    /// let encoded = original.to_base64url();
    /// let decoded = Fixed::<[u8; 4]>::try_from_base64url(&encoded).unwrap();
    /// assert_eq!(decoded.expose_secret(), &[0xDE, 0xAD, 0xBE, 0xEF]);
    /// # }
    /// # }
    /// ```
    pub fn try_from_base64url(s: &str) -> Result<Self, crate::error::Base64Error> {
        #[cfg(feature = "alloc")]
        {
            use base64ct::{Base64UrlUnpadded, Encoding};
            use zeroize::Zeroizing;
            let bytes = Zeroizing::new(
                Base64UrlUnpadded::decode_vec(s)
                    .map_err(|_| crate::error::Base64Error::InvalidBase64)?,
            );
            if bytes.len() != N {
                #[cfg(debug_assertions)]
                return Err(crate::error::Base64Error::InvalidLength {
                    expected: N,
                    got: bytes.len(),
                });
                #[cfg(not(debug_assertions))]
                return Err(crate::error::Base64Error::InvalidLength);
            }
            Ok(Self::new_with(|arr| arr.copy_from_slice(&bytes)))
        }
        #[cfg(not(feature = "alloc"))]
        {
            use base64ct::{Base64UrlUnpadded, Encoding};
            use zeroize::Zeroizing;
            let mut buf = Zeroizing::new([0u8; N]);
            let decoded = Base64UrlUnpadded::decode(s, &mut *buf)
                .map_err(|_| crate::error::Base64Error::InvalidBase64)?;
            if decoded.len() != N {
                #[cfg(debug_assertions)]
                return Err(crate::error::Base64Error::InvalidLength {
                    expected: N,
                    got: decoded.len(),
                });
                #[cfg(not(debug_assertions))]
                return Err(crate::error::Base64Error::InvalidLength);
            }
            Ok(Self::new_with(|arr| arr.copy_from_slice(decoded)))
            // buf is zeroized on drop (both success and error paths)
        }
    }
}

/// Bech32 (BIP-173) encoding and decoding for `Fixed<[u8; N]>`.
///
/// Uses the extended `Bech32Large` checksum variant (~5 KB payload limit) rather than
/// the 90-character standard limit. For Bitcoin address formats use `ToBech32m`.
#[cfg(feature = "encoding-bech32")]
impl<const N: usize> Fixed<[u8; N]> {
    /// Encodes the secret bytes as a Bech32 (BIP-173) string with the given HRP.
    ///
    /// Requires the `encoding-bech32` and `alloc` features.
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn try_to_bech32(
        &self,
        hrp: &str,
    ) -> Result<alloc::string::String, crate::error::Bech32Error> {
        self.with_secret(|s: &[u8; N]| s.try_to_bech32(hrp))
    }

    /// Encodes the secret bytes as a Bech32 string, returning
    /// [`EncodedSecret`](crate::EncodedSecret) to preserve zeroization.
    ///
    /// Requires the `encoding-bech32` and `alloc` features.
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn try_to_bech32_zeroizing(
        &self,
        hrp: &str,
    ) -> Result<crate::EncodedSecret, crate::error::Bech32Error> {
        self.with_secret(|s: &[u8; N]| s.try_to_bech32_zeroizing(hrp))
    }

    /// Decodes a Bech32 (BIP-173) string into `Fixed<[u8; N]>`, validating that the HRP
    /// matches `expected_hrp` (case-insensitive).
    ///
    /// HRP comparison is non-constant-time — this is intentional, as the HRP is public
    /// metadata, not secret material. Timing leaks on HRP mismatch are acceptable because
    /// the HRP is not secret. Prefer this over
    /// [`try_from_bech32_unchecked`](Self::try_from_bech32_unchecked) to prevent
    /// cross-protocol confusion attacks.
    ///
    /// Works without `alloc` — decodes into a stack-allocated `Zeroizing<[u8; N]>` buffer.
    pub fn try_from_bech32(s: &str, expected_hrp: &str) -> Result<Self, crate::error::Bech32Error> {
        use crate::traits::encoding::bech32::Bech32Large;
        use bech32::primitives::decode::CheckedHrpstring;
        let checked = CheckedHrpstring::new::<Bech32Large>(s)
            .map_err(|_| crate::error::Bech32Error::OperationFailed)?;
        // HRP check (case-insensitive comparison follows — timing leak is acceptable since HRP is public metadata)
        if !checked.hrp().as_str().eq_ignore_ascii_case(expected_hrp) {
            #[cfg(debug_assertions)]
            return Err(crate::error::Bech32Error::UnexpectedHrp {
                expected: expected_hrp.to_string(),
                got: checked.hrp().as_str().to_string(),
            });
            #[cfg(not(debug_assertions))]
            return Err(crate::error::Bech32Error::UnexpectedHrp);
        }
        let mut buf = zeroize::Zeroizing::new([0u8; N]);
        let mut count = 0usize;
        for byte in checked.byte_iter() {
            if count >= N {
                #[cfg(debug_assertions)]
                return Err(crate::error::Bech32Error::InvalidLength {
                    expected: N,
                    got: count + 1,
                });
                #[cfg(not(debug_assertions))]
                return Err(crate::error::Bech32Error::InvalidLength);
            }
            buf[count] = byte;
            count += 1;
        }
        if count != N {
            #[cfg(debug_assertions)]
            return Err(crate::error::Bech32Error::InvalidLength {
                expected: N,
                got: count,
            });
            #[cfg(not(debug_assertions))]
            return Err(crate::error::Bech32Error::InvalidLength);
        }
        Ok(Self::new_with(|arr| arr.copy_from_slice(&*buf)))
        // buf is zeroized on drop
    }

    /// Decodes a Bech32 (BIP-173) string into `Fixed<[u8; N]>` without validating the HRP.
    ///
    /// Any valid HRP is accepted as long as the checksum is valid and the payload length
    /// equals `N`. Use [`try_from_bech32`](Self::try_from_bech32) in security-critical code
    /// to prevent cross-protocol confusion attacks.
    ///
    /// Works without `alloc` — decodes into a stack-allocated `Zeroizing<[u8; N]>` buffer.
    pub fn try_from_bech32_unchecked(s: &str) -> Result<Self, crate::error::Bech32Error> {
        use crate::traits::encoding::bech32::Bech32Large;
        use bech32::primitives::decode::CheckedHrpstring;
        let checked = CheckedHrpstring::new::<Bech32Large>(s)
            .map_err(|_| crate::error::Bech32Error::OperationFailed)?;
        let mut buf = zeroize::Zeroizing::new([0u8; N]);
        let mut count = 0usize;
        for byte in checked.byte_iter() {
            if count >= N {
                #[cfg(debug_assertions)]
                return Err(crate::error::Bech32Error::InvalidLength {
                    expected: N,
                    got: count + 1,
                });
                #[cfg(not(debug_assertions))]
                return Err(crate::error::Bech32Error::InvalidLength);
            }
            buf[count] = byte;
            count += 1;
        }
        if count != N {
            #[cfg(debug_assertions)]
            return Err(crate::error::Bech32Error::InvalidLength {
                expected: N,
                got: count,
            });
            #[cfg(not(debug_assertions))]
            return Err(crate::error::Bech32Error::InvalidLength);
        }
        Ok(Self::new_with(|arr| arr.copy_from_slice(&*buf)))
        // buf is zeroized on drop
    }
}

/// Bech32m (BIP-350) encoding and decoding for `Fixed<[u8; N]>`.
///
/// Uses the standard BIP-350 payload limit (~90 bytes). For large secrets
/// (ciphertexts, recipients) use `ToBech32` / `Bech32Large` instead.
#[cfg(feature = "encoding-bech32m")]
impl<const N: usize> Fixed<[u8; N]> {
    /// Encodes the secret bytes as a Bech32m (BIP-350) string with the given HRP.
    ///
    /// Requires the `encoding-bech32m` and `alloc` features.
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn try_to_bech32m(
        &self,
        hrp: &str,
    ) -> Result<alloc::string::String, crate::error::Bech32Error> {
        self.with_secret(|s: &[u8; N]| s.try_to_bech32m(hrp))
    }

    /// Encodes the secret bytes as a Bech32m string, returning
    /// [`EncodedSecret`](crate::EncodedSecret) to preserve zeroization.
    ///
    /// Requires the `encoding-bech32m` and `alloc` features.
    #[cfg(feature = "alloc")]
    #[inline]
    pub fn try_to_bech32m_zeroizing(
        &self,
        hrp: &str,
    ) -> Result<crate::EncodedSecret, crate::error::Bech32Error> {
        self.with_secret(|s: &[u8; N]| s.try_to_bech32m_zeroizing(hrp))
    }

    /// Decodes a Bech32m (BIP-350) string into `Fixed<[u8; N]>`, validating that the HRP
    /// matches `expected_hrp` (case-insensitive).
    ///
    /// HRP comparison is non-constant-time — this is intentional, as the HRP is public
    /// metadata, not secret material. Timing leaks on HRP mismatch are acceptable because
    /// the HRP is not secret. Prefer this over
    /// [`try_from_bech32m_unchecked`](Self::try_from_bech32m_unchecked) to prevent
    /// cross-protocol confusion attacks.
    ///
    /// Works without `alloc` — decodes into a stack-allocated `Zeroizing<[u8; N]>` buffer.
    pub fn try_from_bech32m(
        s: &str,
        expected_hrp: &str,
    ) -> Result<Self, crate::error::Bech32Error> {
        use bech32::{primitives::decode::CheckedHrpstring, Bech32m};
        let checked = CheckedHrpstring::new::<Bech32m>(s)
            .map_err(|_| crate::error::Bech32Error::OperationFailed)?;
        // HRP check (case-insensitive comparison follows — timing leak is acceptable since HRP is public metadata)
        if !checked.hrp().as_str().eq_ignore_ascii_case(expected_hrp) {
            #[cfg(debug_assertions)]
            return Err(crate::error::Bech32Error::UnexpectedHrp {
                expected: expected_hrp.to_string(),
                got: checked.hrp().as_str().to_string(),
            });
            #[cfg(not(debug_assertions))]
            return Err(crate::error::Bech32Error::UnexpectedHrp);
        }
        let mut buf = zeroize::Zeroizing::new([0u8; N]);
        let mut count = 0usize;
        for byte in checked.byte_iter() {
            if count >= N {
                #[cfg(debug_assertions)]
                return Err(crate::error::Bech32Error::InvalidLength {
                    expected: N,
                    got: count + 1,
                });
                #[cfg(not(debug_assertions))]
                return Err(crate::error::Bech32Error::InvalidLength);
            }
            buf[count] = byte;
            count += 1;
        }
        if count != N {
            #[cfg(debug_assertions)]
            return Err(crate::error::Bech32Error::InvalidLength {
                expected: N,
                got: count,
            });
            #[cfg(not(debug_assertions))]
            return Err(crate::error::Bech32Error::InvalidLength);
        }
        Ok(Self::new_with(|arr| arr.copy_from_slice(&*buf)))
        // buf is zeroized on drop
    }

    /// Decodes a Bech32m (BIP-350) string into `Fixed<[u8; N]>` without validating the HRP.
    ///
    /// Any valid HRP is accepted as long as the checksum is valid and the payload length
    /// equals `N`. Use [`try_from_bech32m`](Self::try_from_bech32m) in security-critical
    /// code to prevent cross-protocol confusion attacks.
    ///
    /// Works without `alloc` — decodes into a stack-allocated `Zeroizing<[u8; N]>` buffer.
    pub fn try_from_bech32m_unchecked(s: &str) -> Result<Self, crate::error::Bech32Error> {
        use bech32::{primitives::decode::CheckedHrpstring, Bech32m};
        let checked = CheckedHrpstring::new::<Bech32m>(s)
            .map_err(|_| crate::error::Bech32Error::OperationFailed)?;
        let mut buf = zeroize::Zeroizing::new([0u8; N]);
        let mut count = 0usize;
        for byte in checked.byte_iter() {
            if count >= N {
                #[cfg(debug_assertions)]
                return Err(crate::error::Bech32Error::InvalidLength {
                    expected: N,
                    got: count + 1,
                });
                #[cfg(not(debug_assertions))]
                return Err(crate::error::Bech32Error::InvalidLength);
            }
            buf[count] = byte;
            count += 1;
        }
        if count != N {
            #[cfg(debug_assertions)]
            return Err(crate::error::Bech32Error::InvalidLength {
                expected: N,
                got: count,
            });
            #[cfg(not(debug_assertions))]
            return Err(crate::error::Bech32Error::InvalidLength);
        }
        Ok(Self::new_with(|arr| arr.copy_from_slice(&*buf)))
        // buf is zeroized on drop
    }
}

/// Explicit access to immutable [`Fixed<[T; N]>`] contents.
impl<const N: usize, T: zeroize::Zeroize> RevealSecret for Fixed<[T; N]> {
    type Inner = [T; N];

    #[inline(always)]
    fn with_secret<F, R>(&self, f: F) -> R
    where
        F: FnOnce(&[T; N]) -> R,
    {
        f(&self.inner)
    }

    #[inline(always)]
    fn expose_secret(&self) -> &[T; N] {
        &self.inner
    }

    #[inline(always)]
    fn len(&self) -> usize {
        N * core::mem::size_of::<T>()
    }

    /// Consumes `self` and returns the inner `[T; N]` wrapped in [`crate::InnerSecret`].
    ///
    /// Zero cost — no allocation. The sentinel placed in `self.inner` is
    /// `[T::default(); N]` (already zeroed for `u8`), so `Fixed::drop` zeroizes
    /// an already-zero array — a harmless no-op.
    ///
    /// See [`RevealSecret::into_inner`] for full documentation including the
    /// `Default` bound rationale and redacted `Debug` behavior.
    #[inline(always)]
    fn into_inner(mut self) -> crate::InnerSecret<[T; N]>
    where
        Self: Sized,
        Self::Inner: Sized + Default + zeroize::Zeroize,
    {
        // Replace inner with a zero-sentinel so Fixed::drop zeroizes a harmless
        // default value while the caller receives the real secret.
        // Default::default() is inferred as [T; N] from context; [T; N]: Default
        // is guaranteed by the where clause above.
        let inner = core::mem::take(&mut self.inner);
        crate::InnerSecret::new(inner)
    }
}

/// Explicit access to mutable [`Fixed<[T; N]>`] contents.
impl<const N: usize, T: zeroize::Zeroize> RevealSecretMut for Fixed<[T; N]> {
    #[inline(always)]
    fn with_secret_mut<F, R>(&mut self, f: F) -> R
    where
        F: FnOnce(&mut [T; N]) -> R,
    {
        f(&mut self.inner)
    }

    #[inline(always)]
    fn expose_secret_mut(&mut self) -> &mut [T; N] {
        &mut self.inner
    }
}

#[cfg(feature = "rand")]
impl<const N: usize> Fixed<[u8; N]> {
    /// Fills a new `[u8; N]` with cryptographically secure random bytes and wraps it.
    ///
    /// Uses the system RNG ([`OsRng`](rand::rngs::OsRng)) via [`TryRngCore::try_fill_bytes`](rand::TryRngCore::try_fill_bytes).
    /// In `rand` 0.9, `OsRng` is a zero-sized handle to the OS generator (not user-seedable). Requires the `rand`
    /// feature. Heap-free and works in `no_std` / `no_alloc` builds.
    ///
    /// # Panics
    ///
    /// Panics if the system RNG fails to provide bytes ([`TryRngCore::try_fill_bytes`](rand::TryRngCore::try_fill_bytes)
    /// returns `Err`). This is treated as a fatal environment error.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(feature = "rand")]
    /// use secure_gate::{Fixed, RevealSecret};
    ///
    /// # #[cfg(feature = "rand")]
    /// # {
    /// let key: Fixed<[u8; 32]> = Fixed::from_random();
    /// assert_eq!(key.len(), 32);
    /// # }
    /// ```
    #[inline]
    pub fn from_random() -> Self {
        Self::new_with(|arr| {
            OsRng
                .try_fill_bytes(arr)
                .expect("OsRng failure is a program error");
        })
    }

    /// Fills a new `[u8; N]` from `rng` and wraps it.
    ///
    /// Accepts any [`TryCryptoRng`](rand::TryCryptoRng) + [`TryRngCore`](rand::TryRngCore) — for example,
    /// a seeded [`StdRng`](rand::rngs::StdRng) for deterministic tests. Requires the `rand`
    /// feature. Heap-free.
    ///
    /// # Errors
    ///
    /// Returns `R::Error` if [`try_fill_bytes`](rand::TryRngCore::try_fill_bytes) fails.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # #[cfg(feature = "rand")]
    /// # {
    /// use rand::rngs::StdRng;
    /// use rand::SeedableRng;
    /// use secure_gate::Fixed;
    ///
    /// let mut rng = StdRng::from_seed([1u8; 32]);
    /// let key: Fixed<[u8; 16]> = Fixed::from_rng(&mut rng).expect("rng fill");
    /// # }
    /// ```
    #[inline]
    pub fn from_rng<R: TryRngCore + TryCryptoRng>(rng: &mut R) -> Result<Self, R::Error> {
        let mut result = Ok(());
        let this = Self::new_with(|arr| {
            result = rng.try_fill_bytes(arr);
        });
        result.map(|_| this) // on Err, `this` drops → zeroizes any partial fill
    }
}

/// Constant-time equality for `Fixed<T>` — routes through [`expose_secret()`](crate::RevealSecret::expose_secret).
///
/// `==` is **deliberately not implemented** on `Fixed`. Always use `ct_eq`.
///
/// ```rust
/// # #[cfg(feature = "ct-eq")]
/// # {
/// use secure_gate::{Fixed, ConstantTimeEq};
///
/// let a = Fixed::new([1u8; 4]);
/// let b = Fixed::new([1u8; 4]);
/// let c = Fixed::new([2u8; 4]);
/// assert!(a.ct_eq(&b));
/// assert!(!a.ct_eq(&c));
/// # }
/// ```
#[cfg(feature = "ct-eq")]
impl<T: zeroize::Zeroize> crate::ConstantTimeEq for Fixed<T>
where
    T: crate::ConstantTimeEq,
    Self: crate::RevealSecret<Inner = T>,
{
    fn ct_eq(&self, other: &Self) -> bool {
        self.expose_secret().ct_eq(other.expose_secret())
    }
}

/// Always prints `[REDACTED]` — secrets never appear in debug output.
///
/// ```rust
/// use secure_gate::Fixed;
///
/// let key = Fixed::new([0xABu8; 32]);
/// assert_eq!(format!("{:?}", key), "[REDACTED]");
/// ```
impl<T: zeroize::Zeroize> core::fmt::Debug for Fixed<T> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.write_str("[REDACTED]")
    }
}

/// Opt-in cloning — requires `cloneable` feature and [`CloneableSecret`](crate::CloneableSecret)
/// marker on the inner type. Each clone is independently zeroized on drop, but cloning
/// increases the in-memory exposure surface. Use sparingly.
#[cfg(feature = "cloneable")]
impl<T: zeroize::Zeroize + crate::CloneableSecret> Clone for Fixed<T> {
    fn clone(&self) -> Self {
        Self::new(self.inner.clone())
    }
}

/// Opt-in serialization — requires `serde-serialize` feature and
/// [`SerializableSecret`](crate::SerializableSecret) marker on the inner type.
/// Serialization exposes the full secret — audit every impl.
#[cfg(feature = "serde-serialize")]
impl<T: zeroize::Zeroize + crate::SerializableSecret> serde::Serialize for Fixed<T> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        self.inner.serialize(serializer)
    }
}

/// Deserialization uses `Zeroizing`-wrapped temporary buffers — zeroized even on rejection.
#[cfg(feature = "serde-deserialize")]
impl<'de, const N: usize> serde::Deserialize<'de> for Fixed<[u8; N]> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        use core::fmt;
        use serde::de::Visitor;
        struct FixedVisitor<const M: usize>;
        impl<'de, const M: usize> Visitor<'de> for FixedVisitor<M> {
            type Value = Fixed<[u8; M]>;
            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
                write!(formatter, "a byte array of length {}", M)
            }
            fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
            where
                A: serde::de::SeqAccess<'de>,
            {
                let mut vec: zeroize::Zeroizing<alloc::vec::Vec<u8>> =
                    zeroize::Zeroizing::new(alloc::vec::Vec::with_capacity(M));
                while let Some(value) = seq.next_element()? {
                    vec.push(value);
                }
                if vec.len() != M {
                    #[cfg(debug_assertions)]
                    return Err(serde::de::Error::invalid_length(
                        vec.len(),
                        &M.to_string().as_str(),
                    ));
                    #[cfg(not(debug_assertions))]
                    return Err(serde::de::Error::custom("decoded length mismatch"));
                }
                Ok(Fixed::new_with(|arr| arr.copy_from_slice(&vec)))
            }
        }
        deserializer.deserialize_seq(FixedVisitor::<N>)
    }
}

/// Zeroizes the inner value. Called automatically by [`Drop`].
///
/// **Warning:** zeroization does not run for `static` items or under `panic = "abort"`.
impl<T: zeroize::Zeroize> zeroize::Zeroize for Fixed<T> {
    fn zeroize(&mut self) {
        self.inner.zeroize();
    }
}

/// Unconditionally zeroizes the inner value when the wrapper is dropped.
///
/// **Warning:** `Drop` does not run for `static` items or under `panic = "abort"`.
impl<T: zeroize::Zeroize> Drop for Fixed<T> {
    fn drop(&mut self) {
        self.zeroize();
    }
}

/// Marker confirming that `Fixed<T>` always zeroizes on drop.
impl<T: zeroize::Zeroize> zeroize::ZeroizeOnDrop for Fixed<T> {}