@@ -51,7 +51,10 @@ class RawEncryptionMaterials(EncryptionMaterials):
51
51
"""
52
52
53
53
_signing_key = attr .ib (validator = attr .validators .instance_of (DelegatedKey ))
54
- _encryption_key = attr .ib (validator = attr .validators .instance_of (DelegatedKey ))
54
+ _encryption_key = attr .ib (
55
+ validator = attr .validators .optional (attr .validators .instance_of (DelegatedKey )),
56
+ default = None
57
+ )
55
58
_material_description = attr .ib (
56
59
validator = dictionary_validator (six .string_types , six .string_types ),
57
60
converter = copy .deepcopy ,
@@ -60,7 +63,7 @@ class RawEncryptionMaterials(EncryptionMaterials):
60
63
61
64
def __attrs_post_init__ (self ):
62
65
"""Verify that the encryption key is allowed be used for raw materials."""
63
- if not self ._encryption_key .allowed_for_raw_materials :
66
+ if self . _encryption_key is not None and not self ._encryption_key .allowed_for_raw_materials :
64
67
raise ValueError ('Encryption key type "{}" does not allow use with RawEncryptionMaterials' .format (
65
68
type (self ._encryption_key )
66
69
))
@@ -93,6 +96,9 @@ def encryption_key(self):
93
96
:returns: Encryption key
94
97
:rtype: dynamodb_encryption_sdk.delegated_keys.DelegatedKey
95
98
"""
99
+ if self ._encryption_key is None :
100
+ raise AttributeError ('No encryption key available' )
101
+
96
102
return self ._encryption_key
97
103
98
104
@@ -113,7 +119,10 @@ class RawDecryptionMaterials(DecryptionMaterials):
113
119
"""
114
120
115
121
_verification_key = attr .ib (validator = attr .validators .instance_of (DelegatedKey ))
116
- _decryption_key = attr .ib (validator = attr .validators .instance_of (DelegatedKey ))
122
+ _decryption_key = attr .ib (
123
+ validator = attr .validators .optional (attr .validators .instance_of (DelegatedKey )),
124
+ default = None
125
+ )
117
126
_material_description = attr .ib (
118
127
validator = dictionary_validator (six .string_types , six .string_types ),
119
128
converter = copy .deepcopy ,
@@ -122,7 +131,7 @@ class RawDecryptionMaterials(DecryptionMaterials):
122
131
123
132
def __attrs_post_init__ (self ):
124
133
"""Verify that the encryption key is allowed be used for raw materials."""
125
- if not self ._decryption_key .allowed_for_raw_materials :
134
+ if self . _decryption_key is not None and not self ._decryption_key .allowed_for_raw_materials :
126
135
raise ValueError ('Decryption key type "{}" does not allow use with RawDecryptionMaterials' .format (
127
136
type (self ._decryption_key )
128
137
))
@@ -155,4 +164,7 @@ def decryption_key(self):
155
164
:returns: Decryption key
156
165
:rtype: dynamodb_encryption_sdk.delegated_keys.DelegatedKey
157
166
"""
167
+ if self ._decryption_key is None :
168
+ raise AttributeError ('No decryption key available' )
169
+
158
170
return self ._decryption_key
0 commit comments