-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from andrewwhitehead/more-keys
0.2.0-pre.4 updates
- Loading branch information
Showing
22 changed files
with
760 additions
and
228 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 |
---|---|---|
|
@@ -3,7 +3,7 @@ members = ["askar-crypto"] | |
|
||
[package] | ||
name = "aries-askar" | ||
version = "0.2.0-pre.3" | ||
version = "0.2.0-pre.4" | ||
authors = ["Hyperledger Aries Contributors <[email protected]>"] | ||
edition = "2018" | ||
description = "Hyperledger Aries Askar secure storage" | ||
|
@@ -38,7 +38,7 @@ pg_test = ["postgres"] | |
hex-literal = "0.3" | ||
|
||
[dependencies] | ||
askar-crypto = { version = "0.2.0-pre.3", path = "./askar-crypto", features = ["argon2", "std"] } | ||
askar-crypto = { version = "0.2.0-pre.4", path = "./askar-crypto", features = ["argon2", "std"] } | ||
async-mutex = "1.4" | ||
async-stream = "0.3" | ||
bs58 = "0.4" | ||
|
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,6 +1,6 @@ | ||
[package] | ||
name = "askar-crypto" | ||
version = "0.2.0-pre.3" | ||
version = "0.2.0-pre.4" | ||
authors = ["Hyperledger Aries Contributors <[email protected]>"] | ||
edition = "2018" | ||
description = "Hyperledger Aries Askar cryptography" | ||
|
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
pub use crate::crypto::buffer::SecretBytes; | ||
|
||
/// The result of an AEAD encryption operation | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct Encrypted { | ||
pub(crate) buffer: SecretBytes, | ||
pub(crate) tag_pos: usize, | ||
pub(crate) nonce_pos: usize, | ||
} | ||
|
||
impl Encrypted { | ||
pub(crate) fn new(buffer: SecretBytes, tag_pos: usize, nonce_pos: usize) -> Self { | ||
Self { | ||
buffer, | ||
tag_pos, | ||
nonce_pos, | ||
} | ||
} | ||
|
||
/// Convert the ciphertext and tag into a Vec<u8> | ||
pub fn into_vec(self) -> Vec<u8> { | ||
self.buffer.into_vec() | ||
} | ||
|
||
/// Access the ciphertext | ||
pub fn ciphertext(&self) -> &[u8] { | ||
&self.buffer[0..(self.tag_pos)] | ||
} | ||
|
||
/// Access the nonce | ||
pub fn nonce(&self) -> &[u8] { | ||
&self.buffer[(self.nonce_pos)..] | ||
} | ||
|
||
/// Access the authentication tag | ||
pub fn tag(&self) -> &[u8] { | ||
&self.buffer[(self.tag_pos)..(self.nonce_pos)] | ||
} | ||
} | ||
|
||
impl AsRef<[u8]> for Encrypted { | ||
fn as_ref(&self) -> &[u8] { | ||
self.buffer.as_ref() | ||
} | ||
} | ||
|
||
impl From<Encrypted> for SecretBytes { | ||
fn from(e: Encrypted) -> Self { | ||
e.buffer | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
/// The payload for an AEAD decryption operation | ||
pub struct ToDecrypt<'d> { | ||
/// The ciphertext to decrypt | ||
pub ciphertext: &'d [u8], | ||
/// The separated AEAD tag, if any | ||
pub tag: &'d [u8], | ||
} | ||
|
||
impl<'d> ToDecrypt<'d> { | ||
/// Accessor for the combined length | ||
#[inline] | ||
pub fn len(&self) -> usize { | ||
self.ciphertext.len() + self.tag.len() | ||
} | ||
|
||
pub(crate) fn into_secret(self) -> SecretBytes { | ||
if self.tag.is_empty() { | ||
SecretBytes::from_slice(self.ciphertext) | ||
} else { | ||
let mut buf = SecretBytes::with_capacity(self.len()); | ||
buf.extend_from_slice(self.ciphertext); | ||
buf.extend_from_slice(self.tag); | ||
buf | ||
} | ||
} | ||
} | ||
|
||
impl<'d> From<&'d [u8]> for ToDecrypt<'d> { | ||
fn from(ciphertext: &'d [u8]) -> Self { | ||
Self { | ||
ciphertext, | ||
tag: &[], | ||
} | ||
} | ||
} | ||
|
||
impl<'d> From<(&'d [u8], &'d [u8])> for ToDecrypt<'d> { | ||
fn from(split: (&'d [u8], &'d [u8])) -> Self { | ||
Self { | ||
ciphertext: split.0, | ||
tag: split.1, | ||
} | ||
} | ||
} | ||
|
||
impl<'d> From<&'d Encrypted> for ToDecrypt<'d> { | ||
fn from(enc: &'d Encrypted) -> Self { | ||
Self { | ||
ciphertext: enc.ciphertext(), | ||
tag: enc.tag(), | ||
} | ||
} | ||
} |
Oops, something went wrong.