Esempio n. 1
0
    def _get(self,
             unique_identifier=None,
             key_format_type=None,
             key_compression_type=None,
             key_wrapping_specification=None,
             credential=None):
        operation = Operation(OperationEnum.GET)

        uuid = None
        kft = None
        kct = None
        kws = None

        if unique_identifier is not None:
            uuid = attr.UniqueIdentifier(unique_identifier)
        if key_format_type is not None:
            kft = get.GetRequestPayload.KeyFormatType(key_format_type.value)
        if key_compression_type is not None:
            kct = key_compression_type
            kct = get.GetRequestPayload.KeyCompressionType(kct)
        if key_wrapping_specification is not None:
            kws = objects.KeyWrappingSpecification(key_wrapping_specification)

        req_pl = get.GetRequestPayload(unique_identifier=uuid,
                                       key_format_type=kft,
                                       key_compression_type=kct,
                                       key_wrapping_specification=kws)

        batch_item = messages.RequestBatchItem(operation=operation,
                                               request_payload=req_pl)
        message = self._build_request_message(credential, [batch_item])
        self._send_message(message)
        message = messages.ResponseMessage()
        data = self._receive_message()
        message.read(data)
        batch_items = message.batch_items
        batch_item = batch_items[0]
        payload = batch_item.response_payload

        if payload is None:
            payload_unique_identifier = None
            payload_object_type = None
            payload_secret = None
        else:
            payload_unique_identifier = payload.unique_identifier
            payload_object_type = payload.object_type
            payload_secret = payload.secret

        result = GetResult(batch_item.result_status,
                           batch_item.result_reason,
                           batch_item.result_message,
                           payload_object_type,
                           payload_unique_identifier,
                           payload_secret)
        return result
Esempio n. 2
0
    def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the Get request payload and decode it into its
        constituent parts.

        Args:
            input_stream (stream): A data stream containing encoded object
                data, supporting a read method; usually a BytearrayStream
                object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 1.0.
        """
        super(GetRequestPayload, self).read(input_stream,
                                            kmip_version=kmip_version)
        local_stream = utils.BytearrayStream(input_stream.read(self.length))

        if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
            self._unique_identifier = primitives.TextString(
                tag=enums.Tags.UNIQUE_IDENTIFIER)
            self._unique_identifier.read(local_stream,
                                         kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.KEY_FORMAT_TYPE, local_stream):
            self._key_format_type = primitives.Enumeration(
                enum=enums.KeyFormatType, tag=enums.Tags.KEY_FORMAT_TYPE)
            self._key_format_type.read(local_stream, kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.KEY_COMPRESSION_TYPE, local_stream):
            self._key_compression_type = primitives.Enumeration(
                enum=enums.KeyCompressionType,
                tag=enums.Tags.KEY_COMPRESSION_TYPE)
            self._key_compression_type.read(local_stream,
                                            kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.KEY_WRAPPING_SPECIFICATION,
                            local_stream):
            self._key_wrapping_specification = \
                objects.KeyWrappingSpecification()
            self._key_wrapping_specification.read(local_stream,
                                                  kmip_version=kmip_version)

        self.is_oversized(local_stream)