kmip/services/server/crypto/engine.py
def wrap_key(self,
                 key_material,
                 wrapping_method,
                 key_wrap_algorithm,
                 encryption_key):
        """
        Args:
            key_material (bytes): The bytes of the key to wrap. Required.
            wrapping_method (WrappingMethod): A WrappingMethod enumeration
                specifying what wrapping technique to use to wrap the key
                material. Required.
            key_wrap_algorithm (BlockCipherMode): A BlockCipherMode
                enumeration specifying the key wrapping algorithm to use to
                wrap the key material. Required.
            encryption_key (bytes): The bytes of the encryption key to use
                to encrypt the key material. Required.

        Returns:
            bytes: the bytes of the wrapped key

        Raises:
            CryptographicFailure: Raised when an error occurs during key
                wrapping.
            InvalidField: Raised when an unsupported wrapping or encryption
                algorithm is specified.

        Example:
            >>> engine = CryptographyEngine()
            >>> result = engine.wrap_key(
            ...     key_material=(
            ...         b'\x00\x11\x22\x33\x44\x55\x66\x77'
            ...         b'\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF'
            ...     )
            ...     wrapping_method=enums.WrappingMethod.ENCRYPT,
            ...     key_wrap_algorithm=enums.BlockCipherMode.NIST_KEY_WRAP,
            ...     encryption_key=(
            ...         b'\x00\x01\x02\x03\x04\x05\x06\x07'
            ...         b'\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F'
            ...     )
            ... )
            >>> result
            b'\x1f\xa6\x8b\n\x81\x12\xb4G\xae\xf3K\xd8\xfbZ{\x82\x9d>\x86#q
            \xd2\xcf\xe5'
        """
        if wrapping_method == enums.WrappingMethod.ENCRYPT:
            if key_wrap_algorithm == enums.BlockCipherMode.NIST_KEY_WRAP:
                try:
                    wrapped_key = keywrap.aes_key_wrap(
                        encryption_key,
                        key_material,
                        default_backend()
                    )
                    return wrapped_key
                except Exception as e:
                    raise exceptions.CryptographicFailure(str(e))
            else:
                raise exceptions.InvalidField(
                    "Encryption algorithm '{0}' is not a supported key "
                    "wrapping algorithm.".format(key_wrap_algorithm)
                )
        else:
            raise exceptions.InvalidField(
                "Wrapping method '{0}' is not a supported key wrapping "
                "method.".format(wrapping_method)
            )
def wrap_key(self,
                 key_material,
                 wrapping_method,
                 key_wrap_algorithm,
                 encryption_key):
        """
        Args:
            key_material (bytes): The bytes of the key to wrap. Required.
            wrapping_method (WrappingMethod): A WrappingMethod enumeration
                specifying what wrapping technique to use to wrap the key
                material. Required.
            key_wrap_algorithm (BlockCipherMode): A BlockCipherMode
                enumeration specifying the key wrapping algorithm to use to
                wrap the key material. Required.
            encryption_key (bytes): The bytes of the encryption key to use
                to encrypt the key material. Required.

        Returns:
            bytes: the bytes of the wrapped key

        Raises:
            CryptographicFailure: Raised when an error occurs during key
                wrapping.
            InvalidField: Raised when an unsupported wrapping or encryption
                algorithm is specified.

        Example:
            >>> engine = CryptographyEngine()
            >>> result = engine.wrap_key(
            ...     key_material=(
            ...         b'\x00\x11\x22\x33\x44\x55\x66\x77'
            ...         b'\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF'
            ...     )
            ...     wrapping_method=enums.WrappingMethod.ENCRYPT,
            ...     key_wrap_algorithm=enums.BlockCipherMode.NIST_KEY_WRAP,
            ...     encryption_key=(
            ...         b'\x00\x01\x02\x03\x04\x05\x06\x07'
            ...         b'\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F'
            ...     )
            ... )
            >>> result
            b'\x1f\xa6\x8b\n\x81\x12\xb4G\xae\xf3K\xd8\xfbZ{\x82\x9d>\x86#q
            \xd2\xcf\xe5'
        """
        if wrapping_method == enums.WrappingMethod.ENCRYPT:
            if key_wrap_algorithm == enums.BlockCipherMode.NIST_KEY_WRAP:
                try:
                    wrapped_key = keywrap.aes_key_wrap(
                        encryption_key,
                        key_material,
                        default_backend()
                    )
                    return wrapped_key
                except Exception as e:
                    raise exceptions.CryptographicFailure(str(e))
            else:
                raise exceptions.InvalidField(
                    "Encryption algorithm '{0}' is not a supported key "
                    "wrapping algorithm.".format(key_wrap_algorithm)
                )
        else:
            raise exceptions.InvalidField(
                "Wrapping method '{0}' is not a supported key wrapping "
                "method.".format(wrapping_method)
            )
def wrap_key ( self , key_material , wrapping_method , key_wrap_algorithm , encryption_key ) : if wrapping_method == enums . WrappingMethod . ENCRYPT : if key_wrap_algorithm == enums . BlockCipherMode . NIST_KEY_WRAP : try : wrapped_key = keywrap . aes_key_wrap ( encryption_key , key_material , default_backend ( ) ) return wrapped_key except Exception as e : raise exceptions . CryptographicFailure ( str ( e ) ) else : raise exceptions . InvalidField ( "Encryption algorithm '{0}' is not a supported key " "wrapping algorithm." . format ( key_wrap_algorithm ) ) else : raise exceptions . InvalidField ( "Wrapping method '{0}' is not a supported key wrapping " "method." . format ( wrapping_method ) )
Args:
            key_material (bytes): The bytes of the key to wrap. Required.
            wrapping_method (WrappingMethod): A WrappingMethod enumeration
                specifying what wrapping technique to use to wrap the key
                material. Required.
            key_wrap_algorithm (BlockCipherMode): A BlockCipherMode
                enumeration specifying the key wrapping algorithm to use to
                wrap the key material. Required.
            encryption_key (bytes): The bytes of the encryption key to use
                to encrypt the key material. Required.

        Returns:
            bytes: the bytes of the wrapped key

        Raises:
            CryptographicFailure: Raised when an error occurs during key
                wrapping.
            InvalidField: Raised when an unsupported wrapping or encryption
                algorithm is specified.

        Example:
            >>> engine = CryptographyEngine()
            >>> result = engine.wrap_key(
            ...     key_material=(
            ...         b'\x00\x11\x22\x33\x44\x55\x66\x77'
            ...         b'\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF'
            ...     )
            ...     wrapping_method=enums.WrappingMethod.ENCRYPT,
            ...     key_wrap_algorithm=enums.BlockCipherMode.NIST_KEY_WRAP,
            ...     encryption_key=(
            ...         b'\x00\x01\x02\x03\x04\x05\x06\x07'
            ...         b'\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F'
            ...     )
            ... )
            >>> result
            b'\x1f\xa6\x8b\n\x81\x12\xb4G\xae\xf3K\xd8\xfbZ{\x82\x9d>\x86#q
            \xd2\xcf\xe5'
Args : key_material ( bytes ) : The bytes of the key to wrap . Required . wrapping_method ( WrappingMethod ) : A WrappingMethod enumeration specifying what wrapping technique to use to wrap the key material . Required . key_wrap_algorithm ( BlockCipherMode ) : A BlockCipherMode enumeration specifying the key wrapping algorithm to use to wrap the key material . Required . encryption_key ( bytes ) : The bytes of the encryption key to use to encrypt the key material . Required .