Skip to content

Commit f095f12

Browse files
committed
update keys manifest material storage to v3
* awslabs/aws-crypto-tools-test-vector-framework#10
1 parent e0d2953 commit f095f12

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

test_vector_handlers/src/awses_test_vectors/internal/mypy_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
MANIFEST_VERSION = Dict[str, Union[str, int]]
3434

3535
AWS_KMS_KEY_SPEC = Dict[str, Union[bool, str]]
36-
MANUAL_KEY_SPEC = Dict[str, Union[bool, str, int, Iterable[str]]]
36+
MANUAL_KEY_SPEC = Dict[str, Union[bool, str, int]]
3737
KEY_SPEC = Union[AWS_KMS_KEY_SPEC, MANUAL_KEY_SPEC]
3838
KEYS_MANIFEST = Dict[str, Union[MANIFEST_VERSION, Iterable[KEY_SPEC]]]
3939

test_vector_handlers/src/awses_test_vectors/manifests/keys.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# We only actually need these imports when running the mypy checks
4343
pass
4444

45-
SUPPORTED_VERSIONS = (1,)
45+
SUPPORTED_VERSIONS = (3,)
4646
KEY_TYPES = ("symmetric", "private", "public")
4747
KEY_ENCODINGS = ("base64", "pem")
4848
KEY_ALGORITHMS = ("aes", "rsa")
@@ -123,18 +123,14 @@ class ManualKeySpec(KeySpec):
123123
:param str type_name: Key type
124124
:param int bits: Key length in bits
125125
:param str encoding: Encoding used to encode key material
126-
:param material: Raw material encoded, then split into lines separated by ``line_separator``
127-
:type material: list of str
128-
:param str line_separator: Character with which to separate members of ``material``
129-
before decoding (optional: default is empty string)
126+
:param str material: Raw material encoded
130127
"""
131128

132129
algorithm = attr.ib(validator=membership_validator(KEY_ALGORITHMS))
133130
type_name = attr.ib(validator=membership_validator(KEY_TYPES))
134131
bits = attr.ib(validator=attr.validators.instance_of(int))
135132
encoding = attr.ib(validator=membership_validator(KEY_ENCODINGS))
136-
material = attr.ib(validator=iterable_validator(list, six.string_types))
137-
line_separator = attr.ib(default="", validator=attr.validators.instance_of(six.string_types))
133+
material = attr.ib(validator=attr.validators.instance_of(six.string_types))
138134

139135
def __init__(
140136
self,
@@ -145,7 +141,6 @@ def __init__(
145141
bits, # type: int
146142
encoding, # type: str
147143
material, # type: Iterable[str]
148-
line_separator="", # type: Optional[str]
149144
): # noqa=D107
150145
# type: (...) -> None
151146
# Workaround pending resolution of attrs/mypy interaction.
@@ -156,7 +151,6 @@ def __init__(
156151
self.bits = bits
157152
self.encoding = encoding
158153
self.material = material
159-
self.line_separator = line_separator
160154
super(ManualKeySpec, self).__init__(encrypt, decrypt)
161155

162156
@property
@@ -167,7 +161,7 @@ def raw_material(self):
167161
:return: Binary key material
168162
:rtype: bytes
169163
"""
170-
raw_material = self.line_separator.join(self.material).encode(ENCODING)
164+
raw_material = self.material.encode(ENCODING)
171165
if self.encoding == "base64":
172166
return base64.b64decode(raw_material)
173167

@@ -188,7 +182,6 @@ def manifest_spec(self):
188182
"type": self.type_name,
189183
"bits": self.bits,
190184
"encoding": self.encoding,
191-
"line-separator": self.line_separator,
192185
"material": self.material,
193186
}
194187

@@ -211,16 +204,14 @@ def key_from_manifest_spec(key_spec):
211204
algorithm = key_spec["algorithm"] # type: str
212205
bits = key_spec["bits"] # type: int
213206
encoding = key_spec["encoding"] # type: str
214-
line_separator = key_spec.get("line-separator", "") # type: str
215-
material = key_spec["material"] # type: Iterable[str]
207+
material = key_spec["material"] # type: str
216208
return ManualKeySpec(
217209
encrypt=encrypt,
218210
decrypt=decrypt,
219211
type_name=type_name,
220212
algorithm=algorithm,
221213
bits=bits,
222214
encoding=encoding,
223-
line_separator=line_separator,
224215
material=material,
225216
)
226217

@@ -242,7 +233,7 @@ class KeysManifest(object):
242233
@classmethod
243234
def from_manifest_spec(cls, raw_manifest):
244235
# type: (KEYS_MANIFEST) -> KeysManifest
245-
""""""
236+
"""Load from a JSON keys manifest."""
246237
manifest_version = raw_manifest["manifest"] # type: MANIFEST_VERSION
247238
validate_manifest_type(
248239
type_name=cls.type_name, manifest_version=manifest_version, supported_versions=SUPPORTED_VERSIONS

0 commit comments

Comments
 (0)