class RequestHeader(Struct): def __init__(self, protocol_version=None, maximum_response_size=None, asynchronous_indicator=None, authentication=None, batch_error_cont_option=None, batch_order_option=None, time_stamp=None, batch_count=None): super(RequestHeader, self).__init__(tag=Tags.REQUEST_HEADER) self.protocol_version = protocol_version self.maximum_response_size = maximum_response_size self.asynchronous_indicator = asynchronous_indicator self.authentication = authentication self.batch_error_cont_option = batch_error_cont_option self.batch_order_option = batch_order_option self.time_stamp = time_stamp self.batch_count = batch_count def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): super(RequestHeader, self).read( istream, kmip_version=kmip_version ) tstream = BytearrayStream(istream.read(self.length)) self.protocol_version = contents.ProtocolVersion() self.protocol_version.read(tstream, kmip_version=kmip_version) kmip_version = contents.protocol_version_to_kmip_version( self.protocol_version ) # Read the maximum response size if it is present if self.is_tag_next(Tags.MAXIMUM_RESPONSE_SIZE, tstream): self.maximum_response_size = contents.MaximumResponseSize() self.maximum_response_size.read(tstream, kmip_version=kmip_version) # Read the asynchronous indicator if it is present if self.is_tag_next(Tags.ASYNCHRONOUS_INDICATOR, tstream): self.asynchronous_indicator = contents.AsynchronousIndicator() self.asynchronous_indicator.read( tstream, kmip_version=kmip_version ) # Read the authentication if it is present if self.is_tag_next(Tags.AUTHENTICATION, tstream): self.authentication = contents.Authentication() self.authentication.read(tstream, kmip_version=kmip_version) # Read the batch error continuation option if it is present if self.is_tag_next(Tags.BATCH_ERROR_CONTINUATION_OPTION, tstream): self.batch_error_cont_option = BatchErrorContinuationOption() self.batch_error_cont_option.read( tstream, kmip_version=kmip_version ) # Read the batch order option if it is present if self.is_tag_next(Tags.BATCH_ORDER_OPTION, tstream): self.batch_order_option = contents.BatchOrderOption() self.batch_order_option.read(tstream, kmip_version=kmip_version) # Read the time stamp if it is present if self.is_tag_next(Tags.TIME_STAMP, tstream): self.time_stamp = contents.TimeStamp() self.time_stamp.read(tstream, kmip_version=kmip_version) self.batch_count = contents.BatchCount() self.batch_count.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream) def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): tstream = BytearrayStream() # Write the contents of a request header to the stream self.protocol_version.write(tstream, kmip_version=kmip_version) if self.maximum_response_size is not None: self.maximum_response_size.write( tstream, kmip_version=kmip_version ) if self.asynchronous_indicator is not None: self.asynchronous_indicator.write( tstream, kmip_version=kmip_version ) if self.authentication is not None: self.authentication.write(tstream, kmip_version=kmip_version) if self.batch_error_cont_option is not None: self.batch_error_cont_option.write( tstream, kmip_version=kmip_version ) if self.batch_order_option is not None: self.batch_order_option.write(tstream, kmip_version=kmip_version) if self.time_stamp is not None: self.time_stamp.write(tstream, kmip_version=kmip_version) self.batch_count.write(tstream, kmip_version=kmip_version) # Write the length and value of the request header self.length = tstream.length() super(RequestHeader, self).write( ostream, kmip_version=kmip_version ) ostream.write(tstream.buffer)
class RequestHeader(Struct): def __init__(self, protocol_version=None, maximum_response_size=None, asynchronous_indicator=None, authentication=None, batch_error_cont_option=None, batch_order_option=None, time_stamp=None, batch_count=None): super(self.__class__, self).__init__(tag=Tags.REQUEST_HEADER) self.protocol_version = protocol_version self.maximum_response_size = maximum_response_size self.asynchronous_indicator = asynchronous_indicator self.authentication = authentication self.batch_error_cont_option = batch_error_cont_option self.batch_order_option = batch_order_option self.time_stamp = time_stamp self.batch_count = batch_count def read(self, istream): super(self.__class__, self).read(istream) tstream = BytearrayStream(istream.read(self.length)) self.protocol_version = contents.ProtocolVersion() self.protocol_version.read(tstream) # Read the maximum response size if it is present if self.is_tag_next(Tags.MAXIMUM_RESPONSE_SIZE, tstream): self.maximum_response_size = contents.MaximumResponseSize() self.maximum_response_size.read(tstream) # Read the asynchronous indicator if it is present if self.is_tag_next(Tags.ASYNCHRONOUS_INDICATOR, tstream): self.asynchronous_indicator = contents.AsynchronousIndicator() self.asynchronous_indicator.read(tstream) # Read the authentication if it is present if self.is_tag_next(Tags.AUTHENTICATION, tstream): self.authentication = contents.Authentication() self.authentication.read(tstream) # Read the batch error continuation option if it is present if self.is_tag_next(Tags.BATCH_ERROR_CONTINUATION_OPTION, tstream): self.batch_error_cont_option = BatchErrorContinuationOption() self.batch_error_cont_option.read(tstream) # Read the batch order option if it is present if self.is_tag_next(Tags.BATCH_ORDER_OPTION, tstream): self.batch_order_option = contents.BatchOrderOption() self.batch_order_option.read(tstream) # Read the time stamp if it is present if self.is_tag_next(Tags.TIME_STAMP, tstream): self.time_stamp = contents.TimeStamp() self.time_stamp.read(tstream) self.batch_count = contents.BatchCount() self.batch_count.read(tstream) self.is_oversized(tstream) def write(self, ostream): tstream = BytearrayStream() # Write the contents of a request header to the stream self.protocol_version.write(tstream) if self.maximum_response_size is not None: self.maximum_response_size.write(tstream) if self.asynchronous_indicator is not None: self.asynchronous_indicator.write(tstream) if self.authentication is not None: self.authentication.write(tstream) if self.batch_error_cont_option is not None: self.batch_error_cont_option.write(tstream) if self.batch_order_option is not None: self.batch_order_option.write(tstream) if self.time_stamp is not None: self.time_stamp.write(tstream) self.batch_count.write(tstream) # Write the length and value of the request header self.length = tstream.length() super(self.__class__, self).write(ostream) ostream.write(tstream.buffer)