-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `secrecy` version is out-of-date and represents another dependency which can be eliminated by using a zeroize-on-drop approach.
- Loading branch information
Showing
15 changed files
with
111 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ jobs: | |
strategy: | ||
matrix: | ||
include: | ||
- rust: 1.56.0 # MSRV | ||
- rust: 1.60.0 # MSRV | ||
- rust: stable | ||
|
||
steps: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
//! ChaCha20Poly1305 AEAD (RFC 8439) | ||
use crate::{algorithm::CHACHA20POLY1305_ALG_ID, error::Error}; | ||
use secrecy::{DebugSecret, ExposeSecret, Secret}; | ||
use std::convert::{TryFrom, TryInto}; | ||
use zeroize::{Zeroize, ZeroizeOnDrop}; | ||
|
||
/// Size of a ChaCha20Poly1305 key in bytes | ||
pub const CHACHA20POLY1305_KEY_SIZE: usize = 32; | ||
|
||
/// ChaCha20Poly1305 encryption key | ||
#[derive(Clone)] | ||
pub struct ChaCha20Poly1305Key(Secret<[u8; CHACHA20POLY1305_KEY_SIZE]>); | ||
pub struct ChaCha20Poly1305Key(Box<[u8; CHACHA20POLY1305_KEY_SIZE]>); | ||
|
||
impl AsRef<[u8; CHACHA20POLY1305_KEY_SIZE]> for ChaCha20Poly1305Key { | ||
fn as_ref(&self) -> &[u8; CHACHA20POLY1305_KEY_SIZE] { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl Drop for ChaCha20Poly1305Key { | ||
fn drop(&mut self) { | ||
self.0.zeroize(); | ||
} | ||
} | ||
|
||
impl TryFrom<&[u8]> for ChaCha20Poly1305Key { | ||
type Error = Error; | ||
|
||
fn try_from(slice: &[u8]) -> Result<Self, Error> { | ||
slice | ||
.try_into() | ||
.map(|bytes| ChaCha20Poly1305Key(Secret::new(bytes))) | ||
.map(|bytes| ChaCha20Poly1305Key(Box::new(bytes))) | ||
.map_err(|_| Error::Length { | ||
actual: slice.len(), | ||
expected: 32, | ||
}) | ||
} | ||
} | ||
|
||
impl DebugSecret for ChaCha20Poly1305Key {} | ||
|
||
impl ExposeSecret<[u8; CHACHA20POLY1305_KEY_SIZE]> for ChaCha20Poly1305Key { | ||
fn expose_secret(&self) -> &[u8; CHACHA20POLY1305_KEY_SIZE] { | ||
self.0.expose_secret() | ||
} | ||
} | ||
impl ZeroizeOnDrop for ChaCha20Poly1305Key {} | ||
|
||
impl_encodable_secret_key!(ChaCha20Poly1305Key, CHACHA20POLY1305_ALG_ID); |
Oops, something went wrong.