Skip to content

Commit

Permalink
hybrid-array: Impl Zeroize/ZeroizeOnDrop for Array (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
rozbb committed Nov 19, 2023
1 parent b685246 commit 3ed8852
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions hybrid-array/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Pending

* Implement `Zeroize` for `Array<T: Zeroize, U>`, and `ZeroizeOnDrop` for `Array<T: ZeroizeOnDrop, U>`

## 0.1.0 (2022-05-07)
- Initial release
4 changes: 4 additions & 0 deletions hybrid-array/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ rust-version = "1.65"

[dependencies]
typenum = "1.17"
zeroize = { version = "1.7", path = "../zeroize", optional = true }

[features]
default = []
6 changes: 6 additions & 0 deletions hybrid-array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ possible with the stable implementation of const generics:
Internally the crate is built on const generics and provides traits which make
it possible to convert between const generic types and `typenum` types.

## Features

This crate exposes the following feature flags. The default is NO features.

* `zeroize` - Implements [`Zeroize`](https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html) for `Array<T: Zeroize, U>`

## License

Licensed under either of:
Expand Down
22 changes: 22 additions & 0 deletions hybrid-array/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
use super::{Array, ArrayOps, ArraySize, IntoArray};

#[cfg(feature = "zeroize")]
use zeroize::{Zeroize, ZeroizeOnDrop};

#[cfg(feature = "zeroize")]
impl<T, U> Zeroize for Array<T, U>
where
T: Zeroize,
U: ArraySize,
{
fn zeroize(&mut self) {
self.0.as_mut().iter_mut().zeroize()
}
}

#[cfg(feature = "zeroize")]
impl<T, U> ZeroizeOnDrop for Array<T, U>
where
T: ZeroizeOnDrop,
U: ArraySize,
{
}

macro_rules! impl_array_size {
($($len:expr => $ty:ident),+) => {
$(
Expand Down

0 comments on commit 3ed8852

Please sign in to comment.