Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hybrid-array: Impl Zeroize for Array #984

Merged
merged 5 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
{
}
tarcieri marked this conversation as resolved.
Show resolved Hide resolved

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