2
0
mirror of https://github.com/openkmip/pykmip synced 2025-12-20 02:03:31 +00:00

Add KMIP 2.0-style attribute handling

This change adds a new Attributes object to the object hierarchy,
which replaces TemplateAttributes in KMIP 2.0. The old attribute
components, like the AttributeName and AttributeIndex, are no
longer used and are instead replaced with the KMIP TTLV tag for
the attributes in question. This brings the attribute encoding
process in line with the rest of the KMIP specification.

To support this change, additional attribute and enumeration
utility functions have been added to simply attribute building
and attribute/enumeration validity checking. New test cases
covering this new functionality are also included.
This commit is contained in:
Peter Hamilton
2019-02-20 14:07:23 -05:00
committed by Peter Hamilton
parent e986488ebe
commit bc3e81b577
6 changed files with 1373 additions and 6 deletions

View File

@@ -110,6 +110,90 @@ class AttributeValueFactory(object):
# Custom attribute indicated
return attributes.CustomAttribute(value)
def create_attribute_value_by_enum(self, enum, value):
# Switch on the name of the attribute
if enum is enums.Tags.UNIQUE_IDENTIFIER:
return attributes.UniqueIdentifier(value)
elif enum is enums.Tags.NAME:
return self._create_name(value)
elif enum is enums.Tags.OBJECT_TYPE:
return attributes.ObjectType(value)
elif enum is enums.Tags.CRYPTOGRAPHIC_ALGORITHM:
return attributes.CryptographicAlgorithm(value)
elif enum is enums.Tags.CRYPTOGRAPHIC_LENGTH:
return self._create_cryptographic_length(value)
elif enum is enums.Tags.CRYPTOGRAPHIC_PARAMETERS:
return self._create_cryptographic_parameters(value)
elif enum is enums.Tags.CRYPTOGRAPHIC_DOMAIN_PARAMETERS:
raise NotImplementedError()
elif enum is enums.Tags.CERTIFICATE_TYPE:
raise NotImplementedError()
elif enum is enums.Tags.CERTIFICATE_LENGTH:
return primitives.Integer(value, enums.Tags.CERTIFICATE_LENGTH)
elif enum is enums.Tags.X_509_CERTIFICATE_IDENTIFIER:
raise NotImplementedError()
elif enum is enums.Tags.X_509_CERTIFICATE_SUBJECT:
raise NotImplementedError()
elif enum is enums.Tags.X_509_CERTIFICATE_ISSUER:
raise NotImplementedError()
elif enum is enums.Tags.CERTIFICATE_IDENTIFIER:
raise NotImplementedError()
elif enum is enums.Tags.CERTIFICATE_SUBJECT:
raise NotImplementedError()
elif enum is enums.Tags.CERTIFICATE_ISSUER:
raise NotImplementedError()
elif enum is enums.Tags.DIGITAL_SIGNATURE_ALGORITHM:
raise NotImplementedError()
elif enum is enums.Tags.DIGEST:
return attributes.Digest()
elif enum is enums.Tags.OPERATION_POLICY_NAME:
return attributes.OperationPolicyName(value)
elif enum is enums.Tags.CRYPTOGRAPHIC_USAGE_MASK:
return self._create_cryptographic_usage_mask(value)
elif enum is enums.Tags.LEASE_TIME:
return primitives.Interval(value, enums.Tags.LEASE_TIME)
elif enum is enums.Tags.USAGE_LIMITS:
raise NotImplementedError()
elif enum is enums.Tags.STATE:
return attributes.State(value)
elif enum is enums.Tags.INITIAL_DATE:
return primitives.DateTime(value, enums.Tags.INITIAL_DATE)
elif enum is enums.Tags.ACTIVATION_DATE:
return primitives.DateTime(value, enums.Tags.ACTIVATION_DATE)
elif enum is enums.Tags.PROCESS_START_DATE:
return primitives.DateTime(value, enums.Tags.PROCESS_START_DATE)
elif enum is enums.Tags.PROTECT_STOP_DATE:
return primitives.DateTime(value, enums.Tags.PROTECT_STOP_DATE)
elif enum is enums.Tags.DEACTIVATION_DATE:
return primitives.DateTime(value, enums.Tags.DEACTIVATION_DATE)
elif enum is enums.Tags.DESTROY_DATE:
return primitives.DateTime(value, enums.Tags.DESTROY_DATE)
elif enum is enums.Tags.COMPROMISE_OCCURRENCE_DATE:
return primitives.DateTime(
value, enums.Tags.COMPROMISE_OCCURRENCE_DATE)
elif enum is enums.Tags.COMPROMISE_DATE:
return primitives.DateTime(value, enums.Tags.COMPROMISE_DATE)
elif enum is enums.Tags.REVOCATION_REASON:
raise NotImplementedError()
elif enum is enums.Tags.ARCHIVE_DATE:
return primitives.DateTime(value, enums.Tags.ARCHIVE_DATE)
elif enum is enums.Tags.OBJECT_GROUP:
return self._create_object_group(value)
elif enum is enums.Tags.FRESH:
return primitives.Boolean(value, enums.Tags.FRESH)
elif enum is enums.Tags.LINK:
raise NotImplementedError()
elif enum is enums.Tags.APPLICATION_SPECIFIC_INFORMATION:
return self._create_application_specific_information(value)
elif enum is enums.Tags.CONTACT_INFORMATION:
return self._create_contact_information(value)
elif enum is enums.Tags.LAST_CHANGE_DATE:
return primitives.DateTime(value, enums.Tags.LAST_CHANGE_DATE)
elif enum is enums.Tags.CUSTOM_ATTRIBUTE:
return attributes.CustomAttribute(value)
else:
raise ValueError("Unrecognized attribute type: {}".format(enum))
def _create_name(self, name):
if name is not None:
if isinstance(name, attributes.Name):