def algorithm_suite_from_string_id(string_id): # type: (str) -> AlgorithmSuite """Locate an :class:`AlgorithmSuite` by the hex string encoding of the algorithm ID. :param string_id: Hex ID string of algorithm suite :return: Correct algorithm suite for ``string_id`` :rtype: AlgorithmSuite """ bytes_id = unhexlify(string_id) (numeric_id, ) = struct.unpack(">H", bytes_id) return AlgorithmSuite.get_by_id(numeric_id)
def _verified_algorithm_from_id(algorithm_id): # type: (int) -> AlgorithmSuite """Load a message :class:`AlgorithmSuite` for the specified algorithm suite ID. :param int algorithm_id: Algorithm suite ID :return: Algorithm suite :rtype: AlgorithmSuite :raises UnknownIdentityError: if unknown algorithm ID is received :raises NotSupportedError: if unsupported algorithm ID is received """ try: algorithm_suite = AlgorithmSuite.get_by_id(algorithm_id) except KeyError as error: raise UnknownIdentityError("Unknown algorithm {}".format(algorithm_id), error) if not algorithm_suite.allowed: raise NotSupportedError("Unsupported algorithm: {}".format(algorithm_suite)) return algorithm_suite