-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Storage] Add argument to perf tests to use client-side encryption (#…
- Loading branch information
1 parent
b6e1f51
commit 0301417
Showing
3 changed files
with
44 additions
and
4 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
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
34 changes: 34 additions & 0 deletions
34
sdk/storage/azure-storage-blob/tests/perfstress_tests/key_wrapper.py
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,34 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import os | ||
|
||
from cryptography.hazmat.backends import default_backend | ||
from cryptography.hazmat.primitives.keywrap import aes_key_wrap, aes_key_unwrap | ||
|
||
|
||
class KeyWrapper: | ||
def __init__(self, kid='local:key1'): | ||
self.kek = os.urandom(32) | ||
self.backend = default_backend() | ||
self.kid = kid | ||
|
||
def wrap_key(self, key, algorithm='A256KW'): | ||
if algorithm == 'A256KW': | ||
return aes_key_wrap(self.kek, key, self.backend) | ||
|
||
raise ValueError("Unknown key wrap algorithm.") | ||
|
||
def unwrap_key(self, key, algorithm): | ||
if algorithm == 'A256KW': | ||
return aes_key_unwrap(self.kek, key, self.backend) | ||
|
||
raise ValueError("Unknown key wrap algorithm.") | ||
|
||
def get_key_wrap_algorithm(self): | ||
return 'A256KW' | ||
|
||
def get_kid(self): | ||
return self.kid |