def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the CreateKeyPair request payload to a buffer. Args: output_buffer (stream): A data buffer in which to encode object data, supporting a write method. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 1.0. """ local_buffer = utils.BytearrayStream() if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._common_template_attribute is not None: self._common_template_attribute.write( local_buffer, kmip_version=kmip_version) else: if self._common_template_attribute is not None: attributes = objects.convert_template_attribute_to_attributes( self._common_template_attribute) attributes.write(local_buffer, kmip_version=kmip_version) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._private_key_template_attribute is not None: self._private_key_template_attribute.write( local_buffer, kmip_version=kmip_version) else: if self._private_key_template_attribute is not None: attributes = objects.convert_template_attribute_to_attributes( self._private_key_template_attribute) attributes.write(local_buffer, kmip_version=kmip_version) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._public_key_template_attribute is not None: self._public_key_template_attribute.write( local_buffer, kmip_version=kmip_version) else: if self._public_key_template_attribute is not None: attributes = objects.convert_template_attribute_to_attributes( self._public_key_template_attribute) attributes.write(local_buffer, kmip_version=kmip_version) if kmip_version >= enums.KMIPVersion.KMIP_2_0: if self._common_protection_storage_masks: self._common_protection_storage_masks.write( local_buffer, kmip_version=kmip_version) if self._private_protection_storage_masks: self._private_protection_storage_masks.write( local_buffer, kmip_version=kmip_version) if self._public_protection_storage_masks: self._public_protection_storage_masks.write( local_buffer, kmip_version=kmip_version) self.length = local_buffer.length() super(CreateKeyPairRequestPayload, self).write(output_buffer, kmip_version=kmip_version) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Create request payload to a buffer. Args: output_buffer (stream): A data buffer in which to encode object data, supporting a write method. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 1.0. Raises: InvalidField: Raised if the object type attribute or template attribute is not defined. """ local_buffer = utils.BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Create request payload is missing the object type field.") if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._template_attribute: self._template_attribute.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Create request payload is missing the template " "attribute field.") else: # NOTE (ph) For now, leave attributes natively in TemplateAttribute # form and just convert to the KMIP 2.0 Attributes form as needed # for encoding/decoding purposes. Changing the payload to require # the new Attributes structure will trigger a bunch of second-order # effects across the client and server codebases that is beyond # the scope of updating the Create payloads to support KMIP 2.0. if self._template_attribute: attributes = objects.convert_template_attribute_to_attributes( self._template_attribute) attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Create request payload is missing the template " "attribute field.") if kmip_version >= enums.KMIPVersion.KMIP_2_0: if self._protection_storage_masks: self._protection_storage_masks.write(local_buffer, kmip_version=kmip_version) self.length = local_buffer.length() super(CreateRequestPayload, self).write(output_buffer, kmip_version=kmip_version) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the GetAttributes response payload to a stream. Args: output_buffer (stream): A data stream in which to encode object data, supporting a write method; usually a BytearrayStream object. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 1.0. """ local_buffer = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The GetAttributes response payload is missing the unique " "identifier field." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: for attribute in self._attributes: attribute.write(local_buffer, kmip_version=kmip_version) else: if self._attributes: # TODO (ph) Add a new utility to avoid using TemplateAttributes template_attribute = objects.TemplateAttribute( attributes=self.attributes ) attributes = objects.convert_template_attribute_to_attributes( template_attribute ) attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The GetAttributes response payload is missing the " "attributes list." ) self.length = local_buffer.length() super(GetAttributesResponsePayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Locate request payload to a buffer. Args: output_buffer (stream): A data buffer in which to encode object data, supporting a write method. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 1.0. """ local_buffer = utils.BytearrayStream() if self._maximum_items: self._maximum_items.write(local_buffer, kmip_version=kmip_version) if self._offset_items: self._offset_items.write(local_buffer, kmip_version=kmip_version) if self._storage_status_mask: self._storage_status_mask.write(local_buffer, kmip_version=kmip_version) if self._object_group_member: self._object_group_member.write(local_buffer, kmip_version=kmip_version) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._attributes: for attribute in self.attributes: attribute.write(local_buffer, kmip_version=kmip_version) else: if self._attributes: # TODO (ph) Add a new utility to avoid using TemplateAttributes template_attribute = objects.TemplateAttribute( attributes=self.attributes) attributes = objects.convert_template_attribute_to_attributes( template_attribute) attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Locate request payload is missing the attributes " "list.") self.length = local_buffer.length() super(LocateRequestPayload, self).write(output_buffer, kmip_version=kmip_version) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the DeriveKey request payload to a stream. Args: output_buffer (stream): A data stream in which to encode object data, supporting a write method; usually a BytearrayStream object. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 1.0. Raises: ValueError: Raised if the data attribute is not defined. """ local_buffer = utils.BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the object type " "field." ) if self._unique_identifiers: for unique_identifier in self._unique_identifiers: unique_identifier.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the unique " "identifiers field." ) if self._derivation_method: self._derivation_method.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the derivation " "method field." ) if self._derivation_parameters: self._derivation_parameters.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the derivation " "parameters field." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._template_attribute: self._template_attribute.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the template " "attribute field." ) else: if self._template_attribute: attrs = objects.convert_template_attribute_to_attributes( self._template_attribute ) attrs.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the template " "attribute field." ) self.length = local_buffer.length() super(DeriveKeyRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)