def from_file(cls, input_file): # type: (IO) -> MessageEncryptionManifest """Load frome a file containing a full message encrypt manifest. :param file input_file: File object for file containing JSON manifest :return: Loaded manifest :rtype: MessageEncryptionManifest """ raw_manifest = json.load(input_file) validate_manifest_type(type_name=cls.type_name, manifest_version=raw_manifest["manifest"], supported_versions=SUPPORTED_VERSIONS) parent_dir = os.path.abspath(os.path.dirname(input_file.name)) reader = file_reader(parent_dir) raw_keys_manifest = json.loads( reader(raw_manifest["keys"]).decode(ENCODING)) keys = KeysManifest.from_manifest_spec(raw_keys_manifest) plaintexts = cls._generate_plaintexts(raw_manifest["plaintexts"]) tests = {} for name, scenario in raw_manifest["tests"].items(): try: tests[name] = MessageEncryptionTestScenario.from_scenario( scenario=scenario, keys=keys, plaintexts=plaintexts) except NotImplementedError: continue return cls(version=raw_manifest["manifest"]["version"], keys=keys, plaintexts=plaintexts, tests=tests)
def from_file(cls, input_file): # type: (IO) -> MessageDecryptionManifest """Load from a file containing a full message decrypt manifest. :param file input_file: File object for file containing JSON manifest :return: Loaded manifest :rtype: MessageDecryptionManifest """ raw_manifest = json.load(input_file) validate_manifest_type(type_name=cls.type_name, manifest_version=raw_manifest["manifest"], supported_versions=SUPPORTED_VERSIONS) parent_dir = os.path.abspath(os.path.dirname(input_file.name)) root_reader = file_reader(parent_dir) version = raw_manifest["manifest"]["version"] # type: int keys_uri = raw_manifest["keys"] # type: str raw_keys_manifest = json.loads(root_reader(keys_uri).decode(ENCODING)) keys = KeysManifest.from_manifest_spec(raw_keys_manifest) client_name = raw_manifest["client"]["name"] # type: str client_version = raw_manifest["client"]["version"] # type: str raw_scenarios = raw_manifest[ "tests"] # type: Dict[str, DECRYPT_SCENARIO_SPEC] test_scenarios = { name: MessageDecryptionTestScenario.from_scenario( scenario=scenario, plaintext_reader=root_reader, ciphertext_reader=root_reader, keys=keys) for name, scenario in raw_scenarios.items() } return cls( keys_uri=keys_uri, keys=keys, test_scenarios=test_scenarios, version=version, client_name=client_name, client_version=client_version, )