def read(self, istream): """ Read the data encoding the GetAttributeList response payload and decode it into its constituent parts. Args: istream (stream): A data stream containing encoded object data, supporting a read method; usually a BytearrayStream object. """ super(GetAttributeListResponsePayload, self).read(istream) tstream = utils.BytearrayStream(istream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, tstream): uid = primitives.TextString(tag=enums.Tags.UNIQUE_IDENTIFIER) uid.read(tstream) self.uid = uid.value else: raise exceptions.InvalidKmipEncoding( "expected uid encoding not found") names = list() while (self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, tstream)): name = primitives.TextString(tag=enums.Tags.ATTRIBUTE_NAME) name.read(tstream) names.append(name.value) self.attribute_names = names self.is_oversized(tstream) self.validate()
def test_read(self): """ Test that a GetAttributes request payload can be read from a data stream. """ payload = get_attributes.GetAttributesRequestPayload() self.assertEqual(None, payload._unique_identifier) self.assertEqual(list(), payload._attribute_names) payload.read(self.full_encoding) self.assertEqual(self.unique_identifier, payload.unique_identifier) self.assertEqual( primitives.TextString( value=self.unique_identifier, tag=enums.Tags.UNIQUE_IDENTIFIER ), payload._unique_identifier ) self.assertEqual( set(self.attribute_names), set(payload.attribute_names) ) for attribute_name in self.attribute_names: self.assertIn( primitives.TextString( value=attribute_name, tag=enums.Tags.ATTRIBUTE_NAME ), payload._attribute_names )
def read(self, istream): """ Read the data encoding the GetAttributes request payload and decode it into its constituent parts. Args: istream (stream): A data stream containing encoded object data, supporting a read method; usually a BytearrayStream object. """ super(GetAttributesRequestPayload, self).read(istream) tstream = utils.BytearrayStream(istream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, tstream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER) self._unique_identifier.read(tstream) else: self._unique_identifier = None names = list() while self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, tstream): name = primitives.TextString(tag=enums.Tags.ATTRIBUTE_NAME) name.read(tstream) names.append(name) self._attribute_names = names self.is_oversized(tstream)
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the GetAttributes request payload and decode it into its constituent parts. Args: istream (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(GetAttributesRequestPayload, self).read(istream, kmip_version=kmip_version) tstream = utils.BytearrayStream(istream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, tstream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER) self._unique_identifier.read(tstream, kmip_version=kmip_version) else: self._unique_identifier = None names = list() while self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, tstream): name = primitives.TextString(tag=enums.Tags.ATTRIBUTE_NAME) name.read(tstream, kmip_version=kmip_version) names.append(name) self._attribute_names = names self.is_oversized(tstream)
def test_attribute_names_with_duplicates(self): """ Test that duplicate attribute names are silently removed when setting the attribute_names attribute of a GetAttributeList response payload. """ payload = payloads.GetAttributeListResponsePayload() self.assertEqual(list(), payload.attribute_names) self.assertEqual(list(), payload._attribute_names) payload.attribute_names = [ 'test-attribute-name-1', 'test-attribute-name-1', 'test-attribute-name-2' ] self.assertEqual(2, len(payload.attribute_names)) self.assertEqual(2, len(payload._attribute_names)) self.assertIn('test-attribute-name-1', payload.attribute_names) self.assertIn('test-attribute-name-2', payload.attribute_names) self.assertIn( primitives.TextString(value='test-attribute-name-1', tag=enums.Tags.ATTRIBUTE_NAME), payload._attribute_names) self.assertIn( primitives.TextString(value='test-attribute-name-2', tag=enums.Tags.ATTRIBUTE_NAME), payload._attribute_names)
def test_comparison(self): """ Test that the equality/inequality operators return True/False when comparing two ModifyAttribute response payloads with the same data. """ a = payloads.ModifyAttributeResponsePayload() b = payloads.ModifyAttributeResponsePayload() self.assertTrue(a == b) self.assertTrue(b == a) self.assertFalse(a != b) self.assertFalse(b != a) a = payloads.ModifyAttributeResponsePayload( unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959", attribute=objects.Attribute( attribute_name=objects.Attribute.AttributeName("x-attribute1"), attribute_value=primitives.TextString( value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE))) b = payloads.ModifyAttributeResponsePayload( unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959", attribute=objects.Attribute( attribute_name=objects.Attribute.AttributeName("x-attribute1"), attribute_value=primitives.TextString( value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE))) self.assertTrue(a == b) self.assertTrue(b == a) self.assertFalse(a != b) self.assertFalse(b != a)
def test_attribute_names(self): """ Test that the attribute_names attribute of a GetAttributeList response payload can be properly set and retrieved. """ payload = payloads.GetAttributeListResponsePayload() self.assertEqual(list(), payload.attribute_names) self.assertEqual(list(), payload._attribute_names) payload.attribute_names = [ 'test-attribute-name-1', 'test-attribute-name-2' ] self.assertEqual(2, len(payload.attribute_names)) self.assertEqual(2, len(payload._attribute_names)) self.assertIn('test-attribute-name-1', payload.attribute_names) self.assertIn('test-attribute-name-2', payload.attribute_names) self.assertIn( primitives.TextString(value='test-attribute-name-1', tag=enums.Tags.ATTRIBUTE_NAME), payload._attribute_names) self.assertIn( primitives.TextString(value='test-attribute-name-2', tag=enums.Tags.ATTRIBUTE_NAME), payload._attribute_names)
def read(self, istream): """ Read the data encoding the GetAttributes response payload and decode it into its constituent parts. Args: istream (stream): A data stream containing encoded object data, supporting a read method; usually a BytearrayStream object. """ super(GetAttributesResponsePayload, self).read(istream) tstream = utils.BytearrayStream(istream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, tstream): unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER) unique_identifier.read(tstream) self.unique_identifier = unique_identifier.value else: raise exceptions.InvalidKmipEncoding( "expected GetAttributes response unique identifier not found") self._attributes = list() while self.is_tag_next(enums.Tags.ATTRIBUTE, tstream): attribute = objects.Attribute() attribute.read(tstream) self._attributes.append(attribute) self.is_oversized(tstream)
def read(self, input_stream): """ Read the data encoding the GetUsageAllocation 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(GetUsageAllocationRequestPayload, self).read(input_stream) 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) if self.is_tag_next(enums.Tags.USAGE_LIMITS_COUNT, local_stream): self._usage_limits_count = primitives.LongInteger( tag=enums.Tags.USAGE_LIMITS_COUNT) self._usage_limits_count.read(local_stream) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Rekey 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(RekeyRequestPayload, 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.OFFSET, local_stream): self._offset = primitives.Interval(tag=enums.Tags.OFFSET) self._offset.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_stream): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read(local_stream, kmip_version=kmip_version) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Decrypt 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(DecryptRequestPayload, 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.CRYPTOGRAPHIC_PARAMETERS, local_stream): self._cryptographic_parameters = \ attributes.CryptographicParameters() self._cryptographic_parameters.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.DATA, local_stream): self._data = primitives.ByteString(tag=enums.Tags.DATA) self._data.read(local_stream, kmip_version=kmip_version) else: raise ValueError("invalid payload missing the data attribute") if self.is_tag_next(enums.Tags.IV_COUNTER_NONCE, local_stream): self._iv_counter_nonce = primitives.ByteString( tag=enums.Tags.IV_COUNTER_NONCE) self._iv_counter_nonce.read(local_stream, kmip_version=kmip_version) if kmip_version >= enums.KMIPVersion.KMIP_1_4: if self.is_tag_next( enums.Tags.AUTHENTICATED_ENCRYPTION_ADDITIONAL_DATA, local_stream): self._auth_additional_data = primitives.ByteString( tag=enums.Tags.AUTHENTICATED_ENCRYPTION_ADDITIONAL_DATA) self._auth_additional_data.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.AUTHENTICATED_ENCRYPTION_TAG, local_stream): self._auth_tag = primitives.ByteString( tag=enums.Tags.AUTHENTICATED_ENCRYPTION_TAG) self._auth_tag.read(local_stream, kmip_version=kmip_version) self.is_oversized(local_stream)
def read(self, input_stream): """ Read the data encoding the Check response 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(CheckResponsePayload, self).read(input_stream) 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) if self.is_tag_next(enums.Tags.USAGE_LIMITS_COUNT, local_stream): self._usage_limits_count = primitives.LongInteger( tag=enums.Tags.USAGE_LIMITS_COUNT) self._usage_limits_count.read(local_stream) if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_USAGE_MASK, local_stream): self._cryptographic_usage_mask = primitives.Integer( tag=enums.Tags.CRYPTOGRAPHIC_USAGE_MASK) self._cryptographic_usage_mask.read(local_stream) if self.is_tag_next(enums.Tags.LEASE_TIME, local_stream): self._lease_time = primitives.Interval(tag=enums.Tags.LEASE_TIME) self._lease_time.read(local_stream) self.is_oversized(local_stream)
def read(self, input_stream): """ Read the data encoding the Decrypt response 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. Raises: ValueError: Raised if the unique_identifier or data attributes are missing from the encoded payload. """ super(DecryptResponsePayload, self).read(input_stream) 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) else: raise ValueError( "invalid payload missing the unique identifier attribute") if self.is_tag_next(enums.Tags.DATA, local_stream): self._data = primitives.ByteString(tag=enums.Tags.DATA) self._data.read(local_stream) else: raise ValueError("invalid payload missing the data attribute") self.is_oversized(local_stream)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the GetAttributeList request payload and decode it into its constituent parts. Args: input_buffer (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(GetAttributeListRequestPayload, self).read(input_buffer, kmip_version=kmip_version) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER) self._unique_identifier.read(local_buffer, kmip_version=kmip_version) else: self._unique_identifier = None self.is_oversized(local_buffer)
def read(self, input_stream): """ Read the data encoding the Rekey 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. """ super(RekeyRequestPayload, self).read(input_stream) 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) if self.is_tag_next(enums.Tags.OFFSET, local_stream): self._offset = primitives.Interval(tag=enums.Tags.OFFSET) self._offset.read(local_stream) if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_stream): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read(local_stream) self.is_oversized(local_stream)
def read(self, input_stream): """ Read the data encoding the ObtainLease response 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(ObtainLeaseResponsePayload, self).read(input_stream) 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) if self.is_tag_next(enums.Tags.LEASE_TIME, local_stream): self._lease_time = primitives.Interval(tag=enums.Tags.LEASE_TIME) self._lease_time.read(local_stream) if self.is_tag_next(enums.Tags.LAST_CHANGE_DATE, local_stream): self._last_change_date = primitives.DateTime( tag=enums.Tags.LAST_CHANGE_DATE) self._last_change_date.read(local_stream) self.is_oversized(local_stream)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Locate response payload and decode it into its constituent parts. Args: input_buffer (stream): A data buffer containing encoded object data, supporting a read method. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be decoded. Optional, defaults to KMIP 1.0. """ super(LocateResponsePayload, self).read(input_buffer, kmip_version=kmip_version) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.LOCATED_ITEMS, local_buffer): self._located_items = primitives.Integer( tag=enums.Tags.LOCATED_ITEMS) self._located_items.read(local_buffer, kmip_version=kmip_version) self._unique_identifiers = [] while self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer): unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER) unique_identifier.read(local_buffer, kmip_version=kmip_version) self._unique_identifiers.append(unique_identifier) self.is_oversized(local_buffer)
def read(self, input_stream): """ Read the data encoding the DeriveKey response 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(DeriveKeyResponsePayload, self).read(input_stream) 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) else: raise ValueError("invalid payload missing unique identifier") if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_stream): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read(local_stream) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Archive 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(ArchiveRequestPayload, 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) self.is_oversized(local_stream)
def test_read_with_no_unique_identifier(self): """ Test that a GetAttributes request payload with no ID can be read from a data stream. """ payload = get_attributes.GetAttributesRequestPayload() self.assertEqual(None, payload._unique_identifier) self.assertEqual(list(), payload._attribute_names) payload.read(self.encoding_sans_unique_identifier) self.assertEqual(None, payload.unique_identifier) self.assertEqual(None, payload._unique_identifier) self.assertEqual( set(self.attribute_names), set(payload.attribute_names) ) for attribute_name in self.attribute_names: self.assertIn( primitives.TextString( value=attribute_name, tag=enums.Tags.ATTRIBUTE_NAME ), payload._attribute_names )
def test_init(self): value = 'Hello World' ts = primitives.TextString(value) self.assertIsInstance( ts.value, str, self.bad_type.format('value', str, type(ts.value))) self.assertEqual(value, ts.value, self.bad_value.format('value', value, ts.value))
def private_key_unique_identifier(self, value): if value is None: self._private_key_unique_identifier = None elif isinstance(value, six.string_types): self._private_key_unique_identifier = primitives.TextString( value=value, tag=enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER) else: raise TypeError("Private key unique identifier must be a string.")
def attribute_name(self, value): if value is None: self._attribute_name = None elif isinstance(value, six.string_types): self._attribute_name = primitives.TextString( value=value, tag=enums.Tags.ATTRIBUTE_NAME) else: raise TypeError("The attribute name must be a string.")
def test_comparison(self): """ Test that the equality/inequality operators return True/False when comparing two ModifyAttribute request payloads with the same data. """ a = payloads.ModifyAttributeRequestPayload() b = payloads.ModifyAttributeRequestPayload() self.assertTrue(a == b) self.assertTrue(b == a) self.assertFalse(a != b) self.assertFalse(b != a) a = payloads.ModifyAttributeRequestPayload( unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959", attribute=objects.Attribute( attribute_name=objects.Attribute.AttributeName("x-attribute1"), attribute_value=primitives.TextString( value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)), current_attribute=objects.CurrentAttribute( attribute=primitives.Enumeration( enums.CryptographicAlgorithm, enums.CryptographicAlgorithm. AES, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)), new_attribute=objects.NewAttribute( attribute=primitives.Enumeration( enums.CryptographicAlgorithm, enums.CryptographicAlgorithm. RSA, enums.Tags.CRYPTOGRAPHIC_ALGORITHM))) b = payloads.ModifyAttributeRequestPayload( unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959", attribute=objects.Attribute( attribute_name=objects.Attribute.AttributeName("x-attribute1"), attribute_value=primitives.TextString( value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)), current_attribute=objects.CurrentAttribute( attribute=primitives.Enumeration( enums.CryptographicAlgorithm, enums.CryptographicAlgorithm. AES, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)), new_attribute=objects.NewAttribute( attribute=primitives.Enumeration( enums.CryptographicAlgorithm, enums.CryptographicAlgorithm. RSA, enums.Tags.CRYPTOGRAPHIC_ALGORITHM))) self.assertTrue(a == b) self.assertTrue(b == a) self.assertFalse(a != b) self.assertFalse(b != a)
def vendor_identification(self, value): if value is None: self._vendor_identification = None elif isinstance(value, six.string_types): self._vendor_identification = primitives.TextString( value=value, tag=enums.Tags.VENDOR_IDENTIFICATION) else: raise TypeError("The vendor identification must be a string.")
def uid(self, value): if value is None: self._uid = None elif isinstance(value, six.string_types): self._uid = primitives.TextString(value=value, tag=enums.Tags.UNIQUE_IDENTIFIER) else: raise TypeError("uid must be a string")
def unique_identifier(self, value): if value is None: self._unique_identifier = None elif isinstance(value, six.string_types): self._unique_identifier = primitives.TextString( value=value, tag=enums.Tags.UNIQUE_IDENTIFIER) else: raise TypeError("Unique identifier must be a string.")
def test_read_on_invalid_padding(self): encoding = ( b'\x42\x00\x00\x07\x00\x00\x00\x0B\x48\x65\x6C\x6C\x6F\x20\x57' b'\x6F\x72\x6C\x64\xff\xff\xff\xff\xff') self.stream = utils.BytearrayStream(encoding) ts = primitives.TextString() self.assertRaises(exceptions.ReadValueError, ts.read, self.stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the SignatureVerify 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(SignatureVerifyRequestPayload, 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.CRYPTOGRAPHIC_PARAMETERS, local_stream): self._cryptographic_parameters = \ attributes.CryptographicParameters() self._cryptographic_parameters.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.DATA, local_stream): self._data = primitives.ByteString(tag=enums.Tags.DATA) self._data.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.DIGESTED_DATA, local_stream): self._digested_data = primitives.ByteString( tag=enums.Tags.DIGESTED_DATA) self._digested_data.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.SIGNATURE_DATA, local_stream): self._signature_data = primitives.ByteString( tag=enums.Tags.SIGNATURE_DATA) self._signature_data.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.CORRELATION_VALUE, local_stream): self._correlation_value = primitives.ByteString( tag=enums.Tags.CORRELATION_VALUE) self._correlation_value.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.INIT_INDICATOR, local_stream): self._init_indicator = primitives.Boolean( tag=enums.Tags.INIT_INDICATOR) self._init_indicator.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.FINAL_INDICATOR, local_stream): self._final_indicator = primitives.Boolean( tag=enums.Tags.FINAL_INDICATOR) self._final_indicator.read(local_stream, kmip_version=kmip_version) self.is_oversized(local_stream)
def test_comparison_on_different_attributes(self): """ Test that the equality/inequality operators return False/True when comparing two ModifyAttribute request payloads with different attributes. """ a = payloads.ModifyAttributeRequestPayload(attribute=objects.Attribute( attribute_name=objects.Attribute.AttributeName("x-attribute1"), attribute_value=primitives.TextString( value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE))) b = payloads.ModifyAttributeRequestPayload(attribute=objects.Attribute( attribute_name=objects.Attribute.AttributeName("x-attribute2"), attribute_value=primitives.TextString( value="ModifiedValue2", tag=enums.Tags.ATTRIBUTE_VALUE))) self.assertFalse(a == b) self.assertFalse(b == a) self.assertTrue(a != b) self.assertTrue(b != a)