-
Notifications
You must be signed in to change notification settings - Fork 251
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
add customer encryption key for upload and download blob request #1304
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f009ba9
add customer encryption key for upload and download blob request
Leavrth c18fbdd
use vec::IntoIter to expand the scope
Leavrth 01999b4
Apply suggestions from code review
demoray cb6f7d1
Update sdk/storage_blobs/src/options/encryption_key.rs
demoray 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 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,59 @@ | ||
use azure_core::headers::{self, AsHeaders, HeaderName, HeaderValue}; | ||
|
||
const DEFAULT_ENCRYPTION_ALGORITHM: &'static str = "AES256"; | ||
demoray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#[derive(Clone, Debug)] | ||
pub struct CPKInfo { | ||
encryption_key: String, | ||
encryption_key_sha256: String, | ||
|
||
// only support AES256 | ||
encryption_algorithm: Option<String>, | ||
} | ||
|
||
impl CPKInfo { | ||
pub fn new(key: String, key_sha256: String, algorithm: Option<String>) -> Self { | ||
Self { | ||
encryption_key: key, | ||
encryption_key_sha256: key_sha256, | ||
|
||
encryption_algorithm: algorithm, | ||
} | ||
} | ||
} | ||
|
||
impl From<(String, String)> for CPKInfo { | ||
fn from(s: (String, String)) -> Self { | ||
Self::new(s.0, s.1, None) | ||
} | ||
} | ||
|
||
impl From<(String, String, String)> for CPKInfo { | ||
fn from(s: (String, String, String)) -> Self { | ||
Self::new(s.0, s.1, Some(s.2)) | ||
} | ||
} | ||
|
||
impl AsHeaders for CPKInfo { | ||
type Iter = std::vec::IntoIter<(HeaderName, HeaderValue)>; | ||
|
||
fn as_headers(&self) -> Self::Iter { | ||
let algorithm = self | ||
.encryption_algorithm | ||
.as_deref() | ||
.unwrap_or(DEFAULT_ENCRYPTION_ALGORITHM) | ||
.to_owned(); | ||
let headers = vec![ | ||
(headers::ENCRYPTION_ALGORITHM, algorithm.into()), | ||
( | ||
headers::ENCRYPTION_KEY, | ||
self.encryption_key.to_owned().into(), | ||
), | ||
( | ||
headers::ENCRYPTION_KEY_SHA256, | ||
self.encryption_key_sha256.to_owned().into(), | ||
), | ||
]; | ||
headers.into_iter() | ||
} | ||
} |
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
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.
Can you discuss this choice, instead of using
This is made possible by the following:
azure-sdk-for-rust/sdk/core/src/headers/mod.rs
Lines 25 to 27 in be63d1e
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.
Thank you for your review.
The struct
CPKInfo
contains 3 headers:EncryptionKey
,EncryptionKeySha256
andEncryptionAlgorithm
. That's because once theEncryptionKey
is specified, the other 2 headers must be provided. (from azure-sdk-for-go)The
this.encryption_key
is wrapped byOption
, for which I find there has been an implement:The T has a trait bound
Header
, which has the functionname
andvalue
. But the traitHeader
can not be implemented byCPKInfo
. So I cannot directly useheaders.add(this.encryption_key);
.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.
@demoray PTAL
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.
Maybe we can just specify the
AsHeaders::Iter
to expand the scope. See the code as followes: