diff --git a/Cargo.lock b/Cargo.lock index cfb5c001..e16b42ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,6 +85,7 @@ name = "hybrid-array" version = "0.2.0-pre.5" dependencies = [ "typenum", + "zeroize 1.7.0", ] [[package]] diff --git a/hybrid-array/CHANGELOG.md b/hybrid-array/CHANGELOG.md index 2dac4530..1bb9a9c4 100644 --- a/hybrid-array/CHANGELOG.md +++ b/hybrid-array/CHANGELOG.md @@ -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`, and `ZeroizeOnDrop` for `Array` + ## 0.1.0 (2022-05-07) - Initial release diff --git a/hybrid-array/Cargo.toml b/hybrid-array/Cargo.toml index 9d17e836..040e66ab 100644 --- a/hybrid-array/Cargo.toml +++ b/hybrid-array/Cargo.toml @@ -18,3 +18,7 @@ rust-version = "1.65" [dependencies] typenum = "1.17" +zeroize = { version = "1.7", path = "../zeroize", optional = true } + +[features] +default = [] diff --git a/hybrid-array/README.md b/hybrid-array/README.md index 86093c1c..3a77592e 100644 --- a/hybrid-array/README.md +++ b/hybrid-array/README.md @@ -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` + ## License Licensed under either of: diff --git a/hybrid-array/src/impls.rs b/hybrid-array/src/impls.rs index 72cf3e31..bad5640a 100644 --- a/hybrid-array/src/impls.rs +++ b/hybrid-array/src/impls.rs @@ -1,5 +1,27 @@ use super::{Array, ArrayOps, ArraySize, IntoArray}; +#[cfg(feature = "zeroize")] +use zeroize::{Zeroize, ZeroizeOnDrop}; + +#[cfg(feature = "zeroize")] +impl Zeroize for Array +where + T: Zeroize, + U: ArraySize, +{ + fn zeroize(&mut self) { + self.0.as_mut().iter_mut().zeroize() + } +} + +#[cfg(feature = "zeroize")] +impl ZeroizeOnDrop for Array +where + T: ZeroizeOnDrop, + U: ArraySize, +{ +} + macro_rules! impl_array_size { ($($len:expr => $ty:ident),+) => { $(