def generate()

in src/dynamodb_encryption_sdk/delegated_keys/jce.py [0:0]


    def generate(cls, algorithm, key_length=None):
        # type: (Text, Optional[int]) -> JceNameLocalDelegatedKey
        """Generate an instance of this :class:`DelegatedKey` using the specified algorithm
        and key length.

        :param str algorithm: Text description of algorithm to be used
        :param int key_length: Size in bits of key to generate
        :returns: Generated delegated key
        :rtype: DelegatedKey
        """
        # Normalize to allow generating both encryption and signing keys
        algorithm_lookup = algorithm.upper()
        if "HMAC" in algorithm_lookup or algorithm_lookup in ("AES", "AESWRAP"):
            algorithm_lookup = "SYMMETRIC"
        elif "RSA" in algorithm_lookup:
            algorithm_lookup = "RSA"

        try:
            key_generator = _ALGORITHM_GENERATE_MAP[algorithm_lookup]
        except KeyError:
            raise ValueError("Unknown algorithm: {}".format(algorithm))

        key, key_type, key_encoding = key_generator(key_length)
        return cls(key=key, algorithm=algorithm, key_type=key_type, key_encoding=key_encoding)