Skip to content

Commit 3ed8852

Browse files
authored
hybrid-array: Impl Zeroize/ZeroizeOnDrop for Array (#984)
1 parent b685246 commit 3ed8852

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hybrid-array/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Pending
9+
10+
* Implement `Zeroize` for `Array<T: Zeroize, U>`, and `ZeroizeOnDrop` for `Array<T: ZeroizeOnDrop, U>`
11+
812
## 0.1.0 (2022-05-07)
913
- Initial release

hybrid-array/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ rust-version = "1.65"
1818

1919
[dependencies]
2020
typenum = "1.17"
21+
zeroize = { version = "1.7", path = "../zeroize", optional = true }
22+
23+
[features]
24+
default = []

hybrid-array/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ possible with the stable implementation of const generics:
2525
Internally the crate is built on const generics and provides traits which make
2626
it possible to convert between const generic types and `typenum` types.
2727

28+
## Features
29+
30+
This crate exposes the following feature flags. The default is NO features.
31+
32+
* `zeroize` - Implements [`Zeroize`](https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html) for `Array<T: Zeroize, U>`
33+
2834
## License
2935

3036
Licensed under either of:

hybrid-array/src/impls.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
use super::{Array, ArrayOps, ArraySize, IntoArray};
22

3+
#[cfg(feature = "zeroize")]
4+
use zeroize::{Zeroize, ZeroizeOnDrop};
5+
6+
#[cfg(feature = "zeroize")]
7+
impl<T, U> Zeroize for Array<T, U>
8+
where
9+
T: Zeroize,
10+
U: ArraySize,
11+
{
12+
fn zeroize(&mut self) {
13+
self.0.as_mut().iter_mut().zeroize()
14+
}
15+
}
16+
17+
#[cfg(feature = "zeroize")]
18+
impl<T, U> ZeroizeOnDrop for Array<T, U>
19+
where
20+
T: ZeroizeOnDrop,
21+
U: ArraySize,
22+
{
23+
}
24+
325
macro_rules! impl_array_size {
426
($($len:expr => $ty:ident),+) => {
527
$(

0 commit comments

Comments
 (0)