kmip/services/kmip_client.py
def encrypt(self,
                data,
                unique_identifier=None,
                cryptographic_parameters=None,
                iv_counter_nonce=None,
                credential=None):
        """
        Encrypt data using the specified encryption key and parameters.

        Args:
            data (bytes): The bytes to encrypt. Required.
            unique_identifier (string): The unique ID of the encryption key
                to use. Optional, defaults to None.
            cryptographic_parameters (CryptographicParameters): A structure
                containing various cryptographic settings to be used for the
                encryption. Optional, defaults to None.
            iv_counter_nonce (bytes): The bytes to use for the IV/counter/
                nonce, if needed by the encryption algorithm and/or cipher
                mode. Optional, defaults to None.
            credential (Credential): A credential object containing a set of
                authorization parameters for the operation. Optional, defaults
                to None.

        Returns:
            dict: The results of the encrypt operation, containing the
                following key/value pairs:

                Key                 | Value
                --------------------|-----------------------------------------
                'unique_identifier' | (string) The unique ID of the encryption
                                    | key used to encrypt the data.
                'data'              | (bytes) The encrypted data.
                'iv_counter_nonce'  | (bytes) The IV/counter/nonce used for
                                    | the encryption, if autogenerated.
                'result_status'     | (ResultStatus) An enumeration indicating
                                    | the status of the operation result.
                'result_reason'     | (ResultReason) An enumeration providing
                                    | context for the result status.
                'result_message'    | (string) A message providing additional
                                    | context for the operation result.
        """
        operation = Operation(OperationEnum.ENCRYPT)

        request_payload = payloads.EncryptRequestPayload(
            unique_identifier=unique_identifier,
            data=data,
            cryptographic_parameters=cryptographic_parameters,
            iv_counter_nonce=iv_counter_nonce
        )
        batch_item = messages.RequestBatchItem(
            operation=operation,
            request_payload=request_payload
        )

        request = self._build_request_message(credential, [batch_item])
        response = self._send_and_receive_message(request)
        batch_item = response.batch_items[0]
        payload = batch_item.response_payload

        result = {}

        if payload:
            result['unique_identifier'] = payload.unique_identifier
            result['data'] = payload.data
            result['iv_counter_nonce'] = payload.iv_counter_nonce

        result['result_status'] = batch_item.result_status.value
        try:
            result['result_reason'] = batch_item.result_reason.value
        except Exception:
            result['result_reason'] = batch_item.result_reason
        try:
            result['result_message'] = batch_item.result_message.value
        except Exception:
            result['result_message'] = batch_item.result_message

        return result
def encrypt(self,
                data,
                unique_identifier=None,
                cryptographic_parameters=None,
                iv_counter_nonce=None,
                credential=None):
        """
        Encrypt data using the specified encryption key and parameters.

        Args:
            data (bytes): The bytes to encrypt. Required.
            unique_identifier (string): The unique ID of the encryption key
                to use. Optional, defaults to None.
            cryptographic_parameters (CryptographicParameters): A structure
                containing various cryptographic settings to be used for the
                encryption. Optional, defaults to None.
            iv_counter_nonce (bytes): The bytes to use for the IV/counter/
                nonce, if needed by the encryption algorithm and/or cipher
                mode. Optional, defaults to None.
            credential (Credential): A credential object containing a set of
                authorization parameters for the operation. Optional, defaults
                to None.

        Returns:
            dict: The results of the encrypt operation, containing the
                following key/value pairs:

                Key                 | Value
                --------------------|-----------------------------------------
                'unique_identifier' | (string) The unique ID of the encryption
                                    | key used to encrypt the data.
                'data'              | (bytes) The encrypted data.
                'iv_counter_nonce'  | (bytes) The IV/counter/nonce used for
                                    | the encryption, if autogenerated.
                'result_status'     | (ResultStatus) An enumeration indicating
                                    | the status of the operation result.
                'result_reason'     | (ResultReason) An enumeration providing
                                    | context for the result status.
                'result_message'    | (string) A message providing additional
                                    | context for the operation result.
        """
        operation = Operation(OperationEnum.ENCRYPT)

        request_payload = payloads.EncryptRequestPayload(
            unique_identifier=unique_identifier,
            data=data,
            cryptographic_parameters=cryptographic_parameters,
            iv_counter_nonce=iv_counter_nonce
        )
        batch_item = messages.RequestBatchItem(
            operation=operation,
            request_payload=request_payload
        )

        request = self._build_request_message(credential, [batch_item])
        response = self._send_and_receive_message(request)
        batch_item = response.batch_items[0]
        payload = batch_item.response_payload

        result = {}

        if payload:
            result['unique_identifier'] = payload.unique_identifier
            result['data'] = payload.data
            result['iv_counter_nonce'] = payload.iv_counter_nonce

        result['result_status'] = batch_item.result_status.value
        try:
            result['result_reason'] = batch_item.result_reason.value
        except Exception:
            result['result_reason'] = batch_item.result_reason
        try:
            result['result_message'] = batch_item.result_message.value
        except Exception:
            result['result_message'] = batch_item.result_message

        return result
Encrypt data using the specified encryption key and parameters.

        Args:
            data (bytes): The bytes to encrypt. Required.
            unique_identifier (string): The unique ID of the encryption key
                to use. Optional, defaults to None.
            cryptographic_parameters (CryptographicParameters): A structure
                containing various cryptographic settings to be used for the
                encryption. Optional, defaults to None.
            iv_counter_nonce (bytes): The bytes to use for the IV/counter/
                nonce, if needed by the encryption algorithm and/or cipher
                mode. Optional, defaults to None.
            credential (Credential): A credential object containing a set of
                authorization parameters for the operation. Optional, defaults
                to None.

        Returns:
            dict: The results of the encrypt operation, containing the
                following key/value pairs:

                Key                 | Value
                --------------------|-----------------------------------------
                'unique_identifier' | (string) The unique ID of the encryption
                                    | key used to encrypt the data.
                'data'              | (bytes) The encrypted data.
                'iv_counter_nonce'  | (bytes) The IV/counter/nonce used for
                                    | the encryption, if autogenerated.
                'result_status'     | (ResultStatus) An enumeration indicating
                                    | the status of the operation result.
                'result_reason'     | (ResultReason) An enumeration providing
                                    | context for the result status.
                'result_message'    | (string) A message providing additional
                                    | context for the operation result.