|
| 1 | +# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +"""Command to generate AWS Encryption SDK full message decryption vectors.""" |
| 14 | +import argparse |
| 15 | + |
| 16 | +from awses_test_vectors.manifests.full_message.decrypt_generation import MessageDecryptionGenerationManifest |
| 17 | + |
| 18 | +try: # Python 3.5.0 and 3.5.1 have incompatible typing modules |
| 19 | + from typing import Iterable, Optional # noqa pylint: disable=unused-import |
| 20 | +except ImportError: # pragma: no cover |
| 21 | + # We only actually need these imports when running the mypy checks |
| 22 | + pass |
| 23 | + |
| 24 | + |
| 25 | +def cli(args=None): |
| 26 | + # type: (Optional[Iterable[str]]) -> None |
| 27 | + """CLI entry point for generating AWS Encryption SDK Decrypt Message manifests.""" |
| 28 | + parser = argparse.ArgumentParser( |
| 29 | + description="Build a decrypt manifest from keys and decrypt generation manifests" |
| 30 | + ) |
| 31 | + parser.add_argument("--output", required=True, help="Directory in which to store results") |
| 32 | + parser.add_argument( |
| 33 | + "--input", required=True, type=argparse.FileType("r"), help="Existing full message decrypt generation manifest" |
| 34 | + ) |
| 35 | + parser.add_argument( |
| 36 | + "--human", |
| 37 | + required=False, |
| 38 | + default=None, |
| 39 | + action="store_const", |
| 40 | + const=4, |
| 41 | + dest="json_indent", |
| 42 | + help="Output human-readable JSON", |
| 43 | + ) |
| 44 | + |
| 45 | + parsed = parser.parse_args(args) |
| 46 | + |
| 47 | + encrypt_manifest = MessageDecryptionGenerationManifest.from_file(parsed.input) |
| 48 | + |
| 49 | + encrypt_manifest.run_and_write_to_dir(target_directory=parsed.output, json_indent=parsed.json_indent) |
0 commit comments