|
16 | 16 | _LOGGER = logging.getLogger(__name__) |
17 | 17 |
|
18 | 18 |
|
| 19 | +def _validate_encryption_context_entry(key, value): |
| 20 | + max_entry_length = aws_encryption_sdk.internal.defaults.MAX_BYTE_ARRAY_SIZE |
| 21 | + if len(key) > max_entry_length: |
| 22 | + raise SerializationError("The encryption context contains a key that is too large.") |
| 23 | + if len(value) > max_entry_length: |
| 24 | + raise SerializationError("The encryption context contains a value that is too large.") |
| 25 | + |
| 26 | + |
19 | 27 | def assemble_content_aad(message_id, aad_content_string, seq_num, length): |
20 | 28 | """Assembles the Body AAD string for a message body structure. |
21 | 29 |
|
@@ -71,12 +79,8 @@ def serialize_encryption_context(encryption_context): |
71 | 79 | "Cannot encode dictionary key or value using {}.".format(aws_encryption_sdk.internal.defaults.ENCODING) |
72 | 80 | ) |
73 | 81 |
|
74 | | - max_value_length = aws_encryption_sdk.internal.defaults.MAX_BYTE_ARRAY_SIZE |
75 | 82 | for key, value in sorted(encryption_context_list, key=lambda x: x[0]): |
76 | | - if len(key) > max_value_length: |
77 | | - raise SerializationError("The encryption context contains a key that is too large.") |
78 | | - if len(value) > max_value_length: |
79 | | - raise SerializationError("The encryption context contains a value that is too large.") |
| 83 | + _validate_encryption_context_entry(key, value) |
80 | 84 | serialized_context.extend( |
81 | 85 | struct.pack( |
82 | 86 | ">H{key_size}sH{value_size}s".format(key_size=len(key), value_size=len(value)), |
|
0 commit comments