|
13 | 13 | """Unit test suite for aws_encryption_sdk.structures"""
|
14 | 14 | import pytest
|
15 | 15 |
|
16 |
| -from aws_encryption_sdk.identifiers import Algorithm, ContentType, ObjectType, SerializationVersion |
17 |
| -from aws_encryption_sdk.structures import DataKey, EncryptedDataKey, MasterKeyInfo, MessageHeader, RawDataKey |
| 16 | +from aws_encryption_sdk.identifiers import Algorithm, ContentType, KeyringTraceFlag, ObjectType, SerializationVersion |
| 17 | +from aws_encryption_sdk.structures import ( |
| 18 | + CryptoResult, |
| 19 | + DataKey, |
| 20 | + EncryptedDataKey, |
| 21 | + KeyringTrace, |
| 22 | + MasterKeyInfo, |
| 23 | + MessageHeader, |
| 24 | + RawDataKey, |
| 25 | +) |
18 | 26 |
|
19 | 27 | from .unit_test_utils import all_invalid_kwargs, all_valid_kwargs
|
20 | 28 |
|
|
57 | 65 | key_provider=MasterKeyInfo(provider_id="asjnoa", key_info=b"aosjfoaiwej"), encrypted_data_key=b"aisofiawjef"
|
58 | 66 | )
|
59 | 67 | ],
|
| 68 | + KeyringTrace: [ |
| 69 | + dict( |
| 70 | + wrapping_key=MasterKeyInfo(provider_id="foo", key_info=b"bar"), |
| 71 | + flags={KeyringTraceFlag.WRAPPING_KEY_ENCRYPTED_DATA_KEY}, |
| 72 | + ) |
| 73 | + ], |
| 74 | + CryptoResult: [ |
| 75 | + dict( |
| 76 | + result=b"super secret stuff", |
| 77 | + header=MessageHeader( |
| 78 | + version=SerializationVersion.V1, |
| 79 | + type=ObjectType.CUSTOMER_AE_DATA, |
| 80 | + algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, |
| 81 | + message_id=b"aosiejfoaiwej", |
| 82 | + encryption_context={}, |
| 83 | + encrypted_data_keys=set([]), |
| 84 | + content_type=ContentType.FRAMED_DATA, |
| 85 | + content_aad_length=32456, |
| 86 | + header_iv_length=32456, |
| 87 | + frame_length=234567, |
| 88 | + ), |
| 89 | + keyring_trace=( |
| 90 | + KeyringTrace( |
| 91 | + wrapping_key=MasterKeyInfo(provider_id="foo", key_info=b"bar"), |
| 92 | + flags={KeyringTraceFlag.WRAPPING_KEY_ENCRYPTED_DATA_KEY}, |
| 93 | + ), |
| 94 | + ), |
| 95 | + ) |
| 96 | + ], |
60 | 97 | }
|
61 | 98 |
|
62 | 99 |
|
@@ -134,3 +171,27 @@ def test_raw_and_encrypted_data_key_from_data_key_fail(data_key_class):
|
134 | 171 | data_key_class.from_data_key(b"ahjseofij")
|
135 | 172 |
|
136 | 173 | excinfo.match(r"data_key must be type DataKey not *")
|
| 174 | + |
| 175 | + |
| 176 | +@pytest.fixture |
| 177 | +def ex_result(): |
| 178 | + return CryptoResult(**VALID_KWARGS[CryptoResult][0]) |
| 179 | + |
| 180 | + |
| 181 | +def test_cryptoresult_len(ex_result): |
| 182 | + assert len(ex_result) == 2 |
| 183 | + |
| 184 | + |
| 185 | +def test_cryptoresult_unpack(ex_result): |
| 186 | + data, header = ex_result |
| 187 | + |
| 188 | + assert data is ex_result.result |
| 189 | + assert header is ex_result.header |
| 190 | + |
| 191 | + |
| 192 | +def test_cryptoresult_getitem(ex_result): |
| 193 | + data = ex_result[0] |
| 194 | + header = ex_result[1] |
| 195 | + |
| 196 | + assert data is ex_result.result |
| 197 | + assert header is ex_result.header |
0 commit comments