-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfake_zeroize.rs
48 lines (37 loc) · 1.01 KB
/
fake_zeroize.rs
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
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! When the zeroize crate is not used (`secret` feature is not enabled), this
//! implements the required zeroize trait in a non-secret way
#![cfg(not(feature = "secret"))]
use core::ops::{Deref, DerefMut};
pub trait Zeroize {
fn zeroize(&mut self);
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Zeroizing<T>(T);
impl<T> From<T> for Zeroizing<T> {
fn from(value: T) -> Self {
Self(value)
}
}
impl<T> Deref for Zeroizing<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> DerefMut for Zeroizing<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl<T: AsRef<U>, U: ?Sized> AsRef<U> for Zeroizing<T> {
fn as_ref(&self) -> &U {
self.0.as_ref()
}
}
impl<T: AsMut<U>, U: ?Sized> AsMut<U> for Zeroizing<T> {
fn as_mut(&mut self) -> &mut U {
self.0.as_mut()
}
}