-
Notifications
You must be signed in to change notification settings - Fork 12
Address PR comments in #74 #77
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,5 @@ | ||
| use alloc::boxed::Box; | ||
| use alloc::string::String; | ||
| use alloc::vec::Vec; | ||
|
|
||
| use ferveo::api::{encrypt, Ciphertext, DkgPublicKey, SecretBox}; | ||
| use ferveo::Error; | ||
|
|
@@ -13,7 +12,7 @@ use crate::versioning::{ | |
| }; | ||
|
|
||
| /// Authenticated data for encrypted data. | ||
| #[derive(Debug, Serialize, Deserialize, Clone)] | ||
| #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] | ||
| pub struct AuthenticatedData { | ||
| /// The public key for the encrypted data | ||
| pub public_key: DkgPublicKey, | ||
|
|
@@ -22,6 +21,8 @@ pub struct AuthenticatedData { | |
| pub conditions: Option<Conditions>, | ||
| } | ||
|
|
||
| impl Eq for AuthenticatedData {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it work if you just add it to the list in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite. We'd also need to |
||
|
|
||
| impl AuthenticatedData { | ||
| /// Creates a new access control policy. | ||
| pub fn new(public_key: &DkgPublicKey, conditions: Option<&Conditions>) -> Self { | ||
|
|
@@ -32,24 +33,20 @@ impl AuthenticatedData { | |
| } | ||
|
|
||
| /// Return the aad. | ||
| pub fn aad(&self) -> Box<[u8]> { | ||
| let public_key_bytes = self.public_key.to_bytes().unwrap(); | ||
| let condition_bytes = self.conditions.as_ref().unwrap().as_ref().as_bytes(); | ||
| let mut result = Vec::with_capacity(public_key_bytes.len() + condition_bytes.len()); | ||
| result.extend(public_key_bytes); | ||
| result.extend(condition_bytes); | ||
| result.into_boxed_slice() | ||
| pub fn aad(&self) -> Result<Box<[u8]>, Error> { | ||
| Ok([ | ||
| self.public_key.to_bytes()?.to_vec(), | ||
| self.conditions | ||
| .as_ref() | ||
| .map(|c| c.as_ref().as_bytes()) | ||
| .unwrap_or_default() | ||
| .to_vec(), | ||
| ] | ||
| .concat() | ||
| .into_boxed_slice()) | ||
| } | ||
| } | ||
|
|
||
| impl PartialEq for AuthenticatedData { | ||
| fn eq(&self, other: &Self) -> bool { | ||
| self.public_key == other.public_key && self.conditions == other.conditions | ||
| } | ||
| } | ||
|
|
||
| impl Eq for AuthenticatedData {} | ||
|
|
||
| impl<'a> ProtocolObjectInner<'a> for AuthenticatedData { | ||
| fn version() -> (u16, u16) { | ||
| (1, 0) | ||
|
|
@@ -83,7 +80,7 @@ pub fn encrypt_for_dkg( | |
| let auth_data = AuthenticatedData::new(public_key, conditions); | ||
| let ciphertext = encrypt( | ||
| SecretBox::new(data.to_vec()), | ||
| auth_data.aad().as_ref(), | ||
| auth_data.aad()?.as_ref(), | ||
| public_key, | ||
| )?; | ||
| Ok((ciphertext, auth_data)) | ||
|
|
@@ -110,7 +107,7 @@ impl AccessControlPolicy { | |
| } | ||
|
|
||
| /// Return the aad. | ||
| pub fn aad(&self) -> Box<[u8]> { | ||
| pub fn aad(&self) -> Result<Box<[u8]>, Error> { | ||
| self.auth_data.aad() | ||
| } | ||
|
|
||
|
|
@@ -167,7 +164,7 @@ mod tests { | |
| // check aad for auth data; expected to be dkg public key + conditions | ||
| let mut expected_aad = dkg_pk.to_bytes().unwrap().to_vec(); | ||
| expected_aad.extend(conditions.as_ref().as_bytes()); | ||
| let auth_data_aad = auth_data.aad(); | ||
| let auth_data_aad = auth_data.aad().unwrap(); | ||
| assert_eq!(expected_aad.into_boxed_slice(), auth_data_aad); | ||
|
|
||
| assert_eq!(auth_data.public_key, dkg_pk); | ||
|
|
@@ -193,7 +190,7 @@ mod tests { | |
| let acp = AccessControlPolicy::new(&auth_data, authorization); | ||
|
|
||
| // check that aad for auth_data and acp are the same | ||
| assert_eq!(auth_data.aad(), acp.aad()); | ||
| assert_eq!(auth_data.aad().unwrap(), acp.aad().unwrap()); | ||
|
|
||
| // mimic serialization/deserialization over the wire | ||
| let serialized_acp = acp.to_bytes(); | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piotr-roslaniec Let's be careful changing old PRE code unless necessary.
Is it that
into_iter()no longer works, or iszip(...)just best practice?