Beispiel #1
0
    def test_str(self):
        """
        Test that str can be applied to an Attribute object.
        """
        attribute = objects.Attribute(
            attribute_name=objects.Attribute.AttributeName('test-name'),
            attribute_index=objects.Attribute.AttributeIndex(0),
            attribute_value=attributes.CustomAttribute('test-value'))

        self.assertEqual(
            str({
                'attribute_name': 'test-name',
                'attribute_index': '0',
                'attribute_value': 'test-value'
            }), str(attribute))
Beispiel #2
0
    def test_repr(self):
        """
        Test that repr can be applied to an Attribute object.
        """
        attribute = objects.Attribute(
            attribute_name=objects.Attribute.AttributeName('test-name'),
            attribute_index=objects.Attribute.AttributeIndex(0),
            attribute_value=attributes.CustomAttribute('test-value'))

        self.assertEqual(
            "Attribute("
            "attribute_name=AttributeName(value='test-name'), "
            "attribute_index=AttributeIndex(value=0), "
            "attribute_value=CustomAttribute(value='test-value'))",
            repr(attribute))
Beispiel #3
0
 def create_attribute_value(self, name, value):
     # Switch on the name of the attribute
     if name is enums.AttributeType.UNIQUE_IDENTIFIER:
         return attributes.UniqueIdentifier(value)
     elif name is enums.AttributeType.NAME:
         return self._create_name(value)
     elif name is enums.AttributeType.OBJECT_TYPE:
         return attributes.ObjectType(value)
     elif name is enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM:
         return attributes.CryptographicAlgorithm(value)
     elif name is enums.AttributeType.CRYPTOGRAPHIC_LENGTH:
         return self._create_cryptographic_length(value)
     elif name is enums.AttributeType.CRYPTOGRAPHIC_PARAMETERS:
         return self._create_cryptographic_parameters(value)
     elif name is enums.AttributeType.CRYPTOGRAPHIC_DOMAIN_PARAMETERS:
         raise NotImplementedError()
     elif name is enums.AttributeType.CERTIFICATE_TYPE:
         raise NotImplementedError()
     elif name is enums.AttributeType.CERTIFICATE_LENGTH:
         return primitives.Integer(value, enums.Tags.CERTIFICATE_LENGTH)
     elif name is enums.AttributeType.X_509_CERTIFICATE_IDENTIFIER:
         raise NotImplementedError()
     elif name is enums.AttributeType.X_509_CERTIFICATE_SUBJECT:
         raise NotImplementedError()
     elif name is enums.AttributeType.X_509_CERTIFICATE_ISSUER:
         raise NotImplementedError()
     elif name is enums.AttributeType.CERTIFICATE_IDENTIFIER:
         raise NotImplementedError()
     elif name is enums.AttributeType.CERTIFICATE_SUBJECT:
         raise NotImplementedError()
     elif name is enums.AttributeType.CERTIFICATE_ISSUER:
         raise NotImplementedError()
     elif name is enums.AttributeType.DIGITAL_SIGNATURE_ALGORITHM:
         raise NotImplementedError()
     elif name is enums.AttributeType.DIGEST:
         return attributes.Digest()
     elif name is enums.AttributeType.OPERATION_POLICY_NAME:
         return attributes.OperationPolicyName(value)
     elif name is enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK:
         return self._create_cryptographic_usage_mask(value)
     elif name is enums.AttributeType.LEASE_TIME:
         return primitives.Interval(value, enums.Tags.LEASE_TIME)
     elif name is enums.AttributeType.USAGE_LIMITS:
         raise NotImplementedError()
     elif name is enums.AttributeType.STATE:
         return attributes.State(value)
     elif name is enums.AttributeType.INITIAL_DATE:
         return primitives.DateTime(value, enums.Tags.INITIAL_DATE)
     elif name is enums.AttributeType.ACTIVATION_DATE:
         return primitives.DateTime(value, enums.Tags.ACTIVATION_DATE)
     elif name is enums.AttributeType.PROCESS_START_DATE:
         return primitives.DateTime(value, enums.Tags.PROCESS_START_DATE)
     elif name is enums.AttributeType.PROTECT_STOP_DATE:
         return primitives.DateTime(value, enums.Tags.PROTECT_STOP_DATE)
     elif name is enums.AttributeType.DEACTIVATION_DATE:
         return primitives.DateTime(value, enums.Tags.DEACTIVATION_DATE)
     elif name is enums.AttributeType.DESTROY_DATE:
         return primitives.DateTime(value, enums.Tags.DESTROY_DATE)
     elif name is enums.AttributeType.COMPROMISE_OCCURRENCE_DATE:
         return primitives.DateTime(value,
                                    enums.Tags.COMPROMISE_OCCURRENCE_DATE)
     elif name is enums.AttributeType.COMPROMISE_DATE:
         return primitives.DateTime(value, enums.Tags.COMPROMISE_DATE)
     elif name is enums.AttributeType.REVOCATION_REASON:
         raise NotImplementedError()
     elif name is enums.AttributeType.ARCHIVE_DATE:
         return primitives.DateTime(value, enums.Tags.ARCHIVE_DATE)
     elif name is enums.AttributeType.OBJECT_GROUP:
         return self._create_object_group(value)
     elif name is enums.AttributeType.FRESH:
         return primitives.Boolean(value, enums.Tags.FRESH)
     elif name is enums.AttributeType.LINK:
         raise NotImplementedError()
     elif name is enums.AttributeType.APPLICATION_SPECIFIC_INFORMATION:
         return self._create_application_specific_information(value)
     elif name is enums.AttributeType.CONTACT_INFORMATION:
         return self._create_contact_information(value)
     elif name is enums.AttributeType.LAST_CHANGE_DATE:
         return primitives.DateTime(value, enums.Tags.LAST_CHANGE_DATE)
     elif name is enums.AttributeType.CUSTOM_ATTRIBUTE:
         return attributes.CustomAttribute(value)
     else:
         if not isinstance(name, str):
             raise ValueError('Unrecognized attribute type: '
                              '{0}'.format(name))
         elif name.startswith('x-'):
             # Custom attribute indicated
             return attributes.CustomAttribute(value)