kmip/core/enums.py
def is_attribute(tag, kmip_version=None):
    """
    A utility function that checks if the tag is a valid attribute tag.

    Args:
        tag (enum): A Tags enumeration that may or may not correspond to a
            KMIP attribute type.
        kmip_version (enum): The KMIPVersion enumeration that should be used
            when checking if the tag is a valid attribute tag. Optional,
            defaults to None. If None, the tag is compared with all possible
            attribute tags across all KMIP versions. Otherwise, only the
            attribute tags for a specific KMIP version are checked.

    Returns:
        True: if the tag is a valid attribute tag
        False: otherwise
    """
    kmip_1_0_attribute_tags = [
        Tags.UNIQUE_IDENTIFIER,
        Tags.NAME,
        Tags.OBJECT_TYPE,
        Tags.CRYPTOGRAPHIC_ALGORITHM,
        Tags.CRYPTOGRAPHIC_LENGTH,
        Tags.CRYPTOGRAPHIC_PARAMETERS,
        Tags.CRYPTOGRAPHIC_DOMAIN_PARAMETERS,
        Tags.CERTIFICATE_TYPE,
        Tags.CERTIFICATE_IDENTIFIER,
        Tags.CERTIFICATE_SUBJECT,
        Tags.CERTIFICATE_ISSUER,
        Tags.DIGEST,
        Tags.OPERATION_POLICY_NAME,
        Tags.CRYPTOGRAPHIC_USAGE_MASK,
        Tags.LEASE_TIME,
        Tags.USAGE_LIMITS,
        Tags.STATE,
        Tags.INITIAL_DATE,
        Tags.ACTIVATION_DATE,
        Tags.PROCESS_START_DATE,
        Tags.PROTECT_STOP_DATE,
        Tags.DEACTIVATION_DATE,
        Tags.DESTROY_DATE,
        Tags.COMPROMISE_OCCURRENCE_DATE,
        Tags.COMPROMISE_DATE,
        Tags.REVOCATION_REASON,
        Tags.ARCHIVE_DATE,
        Tags.OBJECT_GROUP,
        Tags.LINK,
        Tags.APPLICATION_SPECIFIC_INFORMATION,
        Tags.CONTACT_INFORMATION,
        Tags.LAST_CHANGE_DATE,
        Tags.CUSTOM_ATTRIBUTE
    ]
    kmip_1_1_attribute_tags = copy.deepcopy(kmip_1_0_attribute_tags) + [
        Tags.CERTIFICATE_LENGTH,
        Tags.X_509_CERTIFICATE_IDENTIFIER,
        Tags.X_509_CERTIFICATE_SUBJECT,
        Tags.X_509_CERTIFICATE_ISSUER,
        Tags.DIGITAL_SIGNATURE_ALGORITHM,
        Tags.FRESH
    ]
    kmip_1_2_attribute_tags = copy.deepcopy(kmip_1_1_attribute_tags) + [
        Tags.ALTERNATIVE_NAME,
        Tags.KEY_VALUE_PRESENT,
        Tags.KEY_VALUE_LOCATION,
        Tags.ORIGINAL_CREATION_DATE
    ]
    kmip_1_3_attribute_tags = copy.deepcopy(kmip_1_2_attribute_tags) + [
        Tags.RANDOM_NUMBER_GENERATOR
    ]
    kmip_1_4_attribute_tags = copy.deepcopy(kmip_1_3_attribute_tags) + [
        Tags.PKCS12_FRIENDLY_NAME,
        Tags.DESCRIPTION,
        Tags.COMMENT,
        Tags.SENSITIVE,
        Tags.ALWAYS_SENSITIVE,
        Tags.EXTRACTABLE,
        Tags.NEVER_EXTRACTABLE
    ]
    kmip_2_0_attribute_tags = copy.deepcopy(kmip_1_4_attribute_tags) + [
        Tags.CERTIFICATE_SUBJECT_CN,
        Tags.CERTIFICATE_SUBJECT_O,
        Tags.CERTIFICATE_SUBJECT_OU,
        Tags.CERTIFICATE_SUBJECT_EMAIL,
        Tags.CERTIFICATE_SUBJECT_C,
        Tags.CERTIFICATE_SUBJECT_ST,
        Tags.CERTIFICATE_SUBJECT_L,
        Tags.CERTIFICATE_SUBJECT_UID,
        Tags.CERTIFICATE_SUBJECT_SERIAL_NUMBER,
        Tags.CERTIFICATE_SUBJECT_TITLE,
        Tags.CERTIFICATE_SUBJECT_DC,
        Tags.CERTIFICATE_SUBJECT_DN_QUALIFIER,
        Tags.CERTIFICATE_ISSUER_CN,
        Tags.CERTIFICATE_ISSUER_O,
        Tags.CERTIFICATE_ISSUER_OU,
        Tags.CERTIFICATE_ISSUER_EMAIL,
        Tags.CERTIFICATE_ISSUER_C,
        Tags.CERTIFICATE_ISSUER_ST,
        Tags.CERTIFICATE_ISSUER_L,
        Tags.CERTIFICATE_ISSUER_UID,
        Tags.CERTIFICATE_ISSUER_SERIAL_NUMBER,
        Tags.CERTIFICATE_ISSUER_TITLE,
        Tags.CERTIFICATE_ISSUER_DC,
        Tags.CERTIFICATE_ISSUER_DN_QUALIFIER,
        Tags.KEY_FORMAT_TYPE,
        Tags.NIST_KEY_TYPE,
        Tags.OPAQUE_DATA_TYPE,
        Tags.PROTECTION_LEVEL,
        Tags.PROTECTION_PERIOD,
        Tags.PROTECTION_STORAGE_MASK,
        Tags.QUANTUM_SAFE,
        Tags.SHORT_UNIQUE_IDENTIFIER,
        Tags.ATTRIBUTE
    ]
    kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_IDENTIFIER)
    kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_SUBJECT)
    kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_ISSUER)
    kmip_2_0_attribute_tags.remove(Tags.OPERATION_POLICY_NAME)
    kmip_2_0_attribute_tags.remove(Tags.CUSTOM_ATTRIBUTE)

    if kmip_version == KMIPVersion.KMIP_1_0:
        return tag in kmip_1_0_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_1_1:
        return tag in kmip_1_1_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_1_2:
        return tag in kmip_1_2_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_1_3:
        return tag in kmip_1_3_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_1_4:
        return tag in kmip_1_4_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_2_0:
        return tag in kmip_2_0_attribute_tags
    else:
        all_attribute_tags = set(
            kmip_1_0_attribute_tags +
            kmip_1_1_attribute_tags +
            kmip_1_2_attribute_tags +
            kmip_1_3_attribute_tags +
            kmip_1_4_attribute_tags +
            kmip_2_0_attribute_tags
        )
        return tag in all_attribute_tags
def is_attribute(tag, kmip_version=None):
    """
    A utility function that checks if the tag is a valid attribute tag.

    Args:
        tag (enum): A Tags enumeration that may or may not correspond to a
            KMIP attribute type.
        kmip_version (enum): The KMIPVersion enumeration that should be used
            when checking if the tag is a valid attribute tag. Optional,
            defaults to None. If None, the tag is compared with all possible
            attribute tags across all KMIP versions. Otherwise, only the
            attribute tags for a specific KMIP version are checked.

    Returns:
        True: if the tag is a valid attribute tag
        False: otherwise
    """
    kmip_1_0_attribute_tags = [
        Tags.UNIQUE_IDENTIFIER,
        Tags.NAME,
        Tags.OBJECT_TYPE,
        Tags.CRYPTOGRAPHIC_ALGORITHM,
        Tags.CRYPTOGRAPHIC_LENGTH,
        Tags.CRYPTOGRAPHIC_PARAMETERS,
        Tags.CRYPTOGRAPHIC_DOMAIN_PARAMETERS,
        Tags.CERTIFICATE_TYPE,
        Tags.CERTIFICATE_IDENTIFIER,
        Tags.CERTIFICATE_SUBJECT,
        Tags.CERTIFICATE_ISSUER,
        Tags.DIGEST,
        Tags.OPERATION_POLICY_NAME,
        Tags.CRYPTOGRAPHIC_USAGE_MASK,
        Tags.LEASE_TIME,
        Tags.USAGE_LIMITS,
        Tags.STATE,
        Tags.INITIAL_DATE,
        Tags.ACTIVATION_DATE,
        Tags.PROCESS_START_DATE,
        Tags.PROTECT_STOP_DATE,
        Tags.DEACTIVATION_DATE,
        Tags.DESTROY_DATE,
        Tags.COMPROMISE_OCCURRENCE_DATE,
        Tags.COMPROMISE_DATE,
        Tags.REVOCATION_REASON,
        Tags.ARCHIVE_DATE,
        Tags.OBJECT_GROUP,
        Tags.LINK,
        Tags.APPLICATION_SPECIFIC_INFORMATION,
        Tags.CONTACT_INFORMATION,
        Tags.LAST_CHANGE_DATE,
        Tags.CUSTOM_ATTRIBUTE
    ]
    kmip_1_1_attribute_tags = copy.deepcopy(kmip_1_0_attribute_tags) + [
        Tags.CERTIFICATE_LENGTH,
        Tags.X_509_CERTIFICATE_IDENTIFIER,
        Tags.X_509_CERTIFICATE_SUBJECT,
        Tags.X_509_CERTIFICATE_ISSUER,
        Tags.DIGITAL_SIGNATURE_ALGORITHM,
        Tags.FRESH
    ]
    kmip_1_2_attribute_tags = copy.deepcopy(kmip_1_1_attribute_tags) + [
        Tags.ALTERNATIVE_NAME,
        Tags.KEY_VALUE_PRESENT,
        Tags.KEY_VALUE_LOCATION,
        Tags.ORIGINAL_CREATION_DATE
    ]
    kmip_1_3_attribute_tags = copy.deepcopy(kmip_1_2_attribute_tags) + [
        Tags.RANDOM_NUMBER_GENERATOR
    ]
    kmip_1_4_attribute_tags = copy.deepcopy(kmip_1_3_attribute_tags) + [
        Tags.PKCS12_FRIENDLY_NAME,
        Tags.DESCRIPTION,
        Tags.COMMENT,
        Tags.SENSITIVE,
        Tags.ALWAYS_SENSITIVE,
        Tags.EXTRACTABLE,
        Tags.NEVER_EXTRACTABLE
    ]
    kmip_2_0_attribute_tags = copy.deepcopy(kmip_1_4_attribute_tags) + [
        Tags.CERTIFICATE_SUBJECT_CN,
        Tags.CERTIFICATE_SUBJECT_O,
        Tags.CERTIFICATE_SUBJECT_OU,
        Tags.CERTIFICATE_SUBJECT_EMAIL,
        Tags.CERTIFICATE_SUBJECT_C,
        Tags.CERTIFICATE_SUBJECT_ST,
        Tags.CERTIFICATE_SUBJECT_L,
        Tags.CERTIFICATE_SUBJECT_UID,
        Tags.CERTIFICATE_SUBJECT_SERIAL_NUMBER,
        Tags.CERTIFICATE_SUBJECT_TITLE,
        Tags.CERTIFICATE_SUBJECT_DC,
        Tags.CERTIFICATE_SUBJECT_DN_QUALIFIER,
        Tags.CERTIFICATE_ISSUER_CN,
        Tags.CERTIFICATE_ISSUER_O,
        Tags.CERTIFICATE_ISSUER_OU,
        Tags.CERTIFICATE_ISSUER_EMAIL,
        Tags.CERTIFICATE_ISSUER_C,
        Tags.CERTIFICATE_ISSUER_ST,
        Tags.CERTIFICATE_ISSUER_L,
        Tags.CERTIFICATE_ISSUER_UID,
        Tags.CERTIFICATE_ISSUER_SERIAL_NUMBER,
        Tags.CERTIFICATE_ISSUER_TITLE,
        Tags.CERTIFICATE_ISSUER_DC,
        Tags.CERTIFICATE_ISSUER_DN_QUALIFIER,
        Tags.KEY_FORMAT_TYPE,
        Tags.NIST_KEY_TYPE,
        Tags.OPAQUE_DATA_TYPE,
        Tags.PROTECTION_LEVEL,
        Tags.PROTECTION_PERIOD,
        Tags.PROTECTION_STORAGE_MASK,
        Tags.QUANTUM_SAFE,
        Tags.SHORT_UNIQUE_IDENTIFIER,
        Tags.ATTRIBUTE
    ]
    kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_IDENTIFIER)
    kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_SUBJECT)
    kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_ISSUER)
    kmip_2_0_attribute_tags.remove(Tags.OPERATION_POLICY_NAME)
    kmip_2_0_attribute_tags.remove(Tags.CUSTOM_ATTRIBUTE)

    if kmip_version == KMIPVersion.KMIP_1_0:
        return tag in kmip_1_0_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_1_1:
        return tag in kmip_1_1_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_1_2:
        return tag in kmip_1_2_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_1_3:
        return tag in kmip_1_3_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_1_4:
        return tag in kmip_1_4_attribute_tags
    elif kmip_version == KMIPVersion.KMIP_2_0:
        return tag in kmip_2_0_attribute_tags
    else:
        all_attribute_tags = set(
            kmip_1_0_attribute_tags +
            kmip_1_1_attribute_tags +
            kmip_1_2_attribute_tags +
            kmip_1_3_attribute_tags +
            kmip_1_4_attribute_tags +
            kmip_2_0_attribute_tags
        )
        return tag in all_attribute_tags
def is_attribute ( tag , kmip_version = None ) : kmip_1_0_attribute_tags = [ Tags . UNIQUE_IDENTIFIER , Tags . NAME , Tags . OBJECT_TYPE , Tags . CRYPTOGRAPHIC_ALGORITHM , Tags . CRYPTOGRAPHIC_LENGTH , Tags . CRYPTOGRAPHIC_PARAMETERS , Tags . CRYPTOGRAPHIC_DOMAIN_PARAMETERS , Tags . CERTIFICATE_TYPE , Tags . CERTIFICATE_IDENTIFIER , Tags . CERTIFICATE_SUBJECT , Tags . CERTIFICATE_ISSUER , Tags . DIGEST , Tags . OPERATION_POLICY_NAME , Tags . CRYPTOGRAPHIC_USAGE_MASK , Tags . LEASE_TIME , Tags . USAGE_LIMITS , Tags . STATE , Tags . INITIAL_DATE , Tags . ACTIVATION_DATE , Tags . PROCESS_START_DATE , Tags . PROTECT_STOP_DATE , Tags . DEACTIVATION_DATE , Tags . DESTROY_DATE , Tags . COMPROMISE_OCCURRENCE_DATE , Tags . COMPROMISE_DATE , Tags . REVOCATION_REASON , Tags . ARCHIVE_DATE , Tags . OBJECT_GROUP , Tags . LINK , Tags . APPLICATION_SPECIFIC_INFORMATION , Tags . CONTACT_INFORMATION , Tags . LAST_CHANGE_DATE , Tags . CUSTOM_ATTRIBUTE ] kmip_1_1_attribute_tags = copy . deepcopy ( kmip_1_0_attribute_tags ) + [ Tags . CERTIFICATE_LENGTH , Tags . X_509_CERTIFICATE_IDENTIFIER , Tags . X_509_CERTIFICATE_SUBJECT , Tags . X_509_CERTIFICATE_ISSUER , Tags . DIGITAL_SIGNATURE_ALGORITHM , Tags . FRESH ] kmip_1_2_attribute_tags = copy . deepcopy ( kmip_1_1_attribute_tags ) + [ Tags . ALTERNATIVE_NAME , Tags . KEY_VALUE_PRESENT , Tags . KEY_VALUE_LOCATION , Tags . ORIGINAL_CREATION_DATE ] kmip_1_3_attribute_tags = copy . deepcopy ( kmip_1_2_attribute_tags ) + [ Tags . RANDOM_NUMBER_GENERATOR ] kmip_1_4_attribute_tags = copy . deepcopy ( kmip_1_3_attribute_tags ) + [ Tags . PKCS12_FRIENDLY_NAME , Tags . DESCRIPTION , Tags . COMMENT , Tags . SENSITIVE , Tags . ALWAYS_SENSITIVE , Tags . EXTRACTABLE , Tags . NEVER_EXTRACTABLE ] kmip_2_0_attribute_tags = copy . deepcopy ( kmip_1_4_attribute_tags ) + [ Tags . CERTIFICATE_SUBJECT_CN , Tags . CERTIFICATE_SUBJECT_O , Tags . CERTIFICATE_SUBJECT_OU , Tags . CERTIFICATE_SUBJECT_EMAIL , Tags . CERTIFICATE_SUBJECT_C , Tags . CERTIFICATE_SUBJECT_ST , Tags . CERTIFICATE_SUBJECT_L , Tags . CERTIFICATE_SUBJECT_UID , Tags . CERTIFICATE_SUBJECT_SERIAL_NUMBER , Tags . CERTIFICATE_SUBJECT_TITLE , Tags . CERTIFICATE_SUBJECT_DC , Tags . CERTIFICATE_SUBJECT_DN_QUALIFIER , Tags . CERTIFICATE_ISSUER_CN , Tags . CERTIFICATE_ISSUER_O , Tags . CERTIFICATE_ISSUER_OU , Tags . CERTIFICATE_ISSUER_EMAIL , Tags . CERTIFICATE_ISSUER_C , Tags . CERTIFICATE_ISSUER_ST , Tags . CERTIFICATE_ISSUER_L , Tags . CERTIFICATE_ISSUER_UID , Tags . CERTIFICATE_ISSUER_SERIAL_NUMBER , Tags . CERTIFICATE_ISSUER_TITLE , Tags . CERTIFICATE_ISSUER_DC , Tags . CERTIFICATE_ISSUER_DN_QUALIFIER , Tags . KEY_FORMAT_TYPE , Tags . NIST_KEY_TYPE , Tags . OPAQUE_DATA_TYPE , Tags . PROTECTION_LEVEL , Tags . PROTECTION_PERIOD , Tags . PROTECTION_STORAGE_MASK , Tags . QUANTUM_SAFE , Tags . SHORT_UNIQUE_IDENTIFIER , Tags . ATTRIBUTE ] kmip_2_0_attribute_tags . remove ( Tags . CERTIFICATE_IDENTIFIER ) kmip_2_0_attribute_tags . remove ( Tags . CERTIFICATE_SUBJECT ) kmip_2_0_attribute_tags . remove ( Tags . CERTIFICATE_ISSUER ) kmip_2_0_attribute_tags . remove ( Tags . OPERATION_POLICY_NAME ) kmip_2_0_attribute_tags . remove ( Tags . CUSTOM_ATTRIBUTE ) if kmip_version == KMIPVersion . KMIP_1_0 : return tag in kmip_1_0_attribute_tags elif kmip_version == KMIPVersion . KMIP_1_1 : return tag in kmip_1_1_attribute_tags elif kmip_version == KMIPVersion . KMIP_1_2 : return tag in kmip_1_2_attribute_tags elif kmip_version == KMIPVersion . KMIP_1_3 : return tag in kmip_1_3_attribute_tags elif kmip_version == KMIPVersion . KMIP_1_4 : return tag in kmip_1_4_attribute_tags elif kmip_version == KMIPVersion . KMIP_2_0 : return tag in kmip_2_0_attribute_tags else : all_attribute_tags = set ( kmip_1_0_attribute_tags + kmip_1_1_attribute_tags + kmip_1_2_attribute_tags + kmip_1_3_attribute_tags + kmip_1_4_attribute_tags + kmip_2_0_attribute_tags ) return tag in all_attribute_tags
A utility function that checks if the tag is a valid attribute tag.

    Args:
        tag (enum): A Tags enumeration that may or may not correspond to a
            KMIP attribute type.
        kmip_version (enum): The KMIPVersion enumeration that should be used
            when checking if the tag is a valid attribute tag. Optional,
            defaults to None. If None, the tag is compared with all possible
            attribute tags across all KMIP versions. Otherwise, only the
            attribute tags for a specific KMIP version are checked.

    Returns:
        True: if the tag is a valid attribute tag
        False: otherwise
A utility function that checks if the tag is a valid attribute tag .