Merge pull request #354 from OpenKMIP/feat/rename-certificate-type

Rename the CertificateTypeEnum enum to CertificateType
This commit is contained in:
Peter Hamilton 2017-10-24 09:42:03 -04:00 committed by GitHub
commit c7711c78c7
13 changed files with 42 additions and 44 deletions

View File

@ -17,7 +17,6 @@ import six
from kmip.core import enums from kmip.core import enums
from kmip.core.enums import CertificateTypeEnum
from kmip.core.enums import HashingAlgorithm as HashingAlgorithmEnum from kmip.core.enums import HashingAlgorithm as HashingAlgorithmEnum
from kmip.core.enums import KeyFormatType as KeyFormatTypeEnum from kmip.core.enums import KeyFormatType as KeyFormatTypeEnum
from kmip.core.enums import Tags from kmip.core.enums import Tags
@ -781,17 +780,17 @@ class CertificateType(Enumeration):
information. information.
""" """
def __init__(self, value=CertificateTypeEnum.X_509): def __init__(self, value=enums.CertificateType.X_509):
""" """
Construct a CertificateType object. Construct a CertificateType object.
Args: Args:
value (CertificateTypeEnum): A CertificateTypeEnum enumeration value (CertificateType): A CertificateType enumeration
value, (e.g., CertificateTypeEnum.PGP). Optional, defaults to value, (e.g., CertificateType.PGP). Optional, defaults to
CertificateTypeEnum.X_509. CertificateType.X_509.
""" """
super(CertificateType, self).__init__( super(CertificateType, self).__init__(
enums.CertificateTypeEnum, value, Tags.CERTIFICATE_TYPE) enums.CertificateType, value, Tags.CERTIFICATE_TYPE)
class DigestValue(ByteString): class DigestValue(ByteString):

View File

@ -137,7 +137,7 @@ class CertificateRequestType(enum.Enum):
PGP = 0x00000004 # DEPRECATED PGP = 0x00000004 # DEPRECATED
class CertificateTypeEnum(enum.Enum): class CertificateType(enum.Enum):
X_509 = 0x00000001 X_509 = 0x00000001
PGP = 0x00000002 # Deprecated as of KMIP 1.4 PGP = 0x00000002 # Deprecated as of KMIP 1.4

View File

@ -52,7 +52,7 @@ class Certificate(Struct):
Construct a Certificate object. Construct a Certificate object.
Args: Args:
certificate_type (CertificateTypeEnum): The type of the certificate_type (CertificateType): The type of the
certificate. Optional, defaults to None. certificate. Optional, defaults to None.
certificate_value (bytes): The bytes of the certificate. Optional, certificate_value (bytes): The bytes of the certificate. Optional,
defaults to None. defaults to None.

View File

@ -22,7 +22,7 @@ from kmip.core.attributes import CryptographicAlgorithm
from kmip.core.attributes import CryptographicLength from kmip.core.attributes import CryptographicLength
from kmip.core.enums import AttributeType from kmip.core.enums import AttributeType
from kmip.core.enums import CertificateTypeEnum from kmip.core.enums import CertificateType
from kmip.core.enums import CryptographicAlgorithm as CryptoAlgorithmEnum from kmip.core.enums import CryptographicAlgorithm as CryptoAlgorithmEnum
from kmip.core.enums import CryptographicUsageMask from kmip.core.enums import CryptographicUsageMask
from kmip.core.enums import ObjectType from kmip.core.enums import ObjectType
@ -302,7 +302,7 @@ def build_object(logger, object_type, key_format_type):
if object_type == ObjectType.CERTIFICATE: if object_type == ObjectType.CERTIFICATE:
value = build_secret_value(logger, object_type) value = build_secret_value(logger, object_type)
return Certificate( return Certificate(
certificate_type=CertificateTypeEnum.X_509, certificate_type=CertificateType.X_509,
certificate_value=value) certificate_value=value)
else: else:
return build_key(logger, object_type, key_format_type) return build_key(logger, object_type, key_format_type)

View File

@ -75,7 +75,7 @@ class ObjectFactory:
certificate_type = cert.certificate_type.value certificate_type = cert.certificate_type.value
value = cert.certificate_value.value value = cert.certificate_value.value
if certificate_type == enums.CertificateTypeEnum.X_509: if certificate_type == enums.CertificateType.X_509:
return pobjects.X509Certificate(value) return pobjects.X509Certificate(value)
else: else:
raise TypeError("core certificate type not supported") raise TypeError("core certificate type not supported")

View File

@ -1072,7 +1072,7 @@ class Certificate(CryptographicObject):
ForeignKey('crypto_objects.uid'), ForeignKey('crypto_objects.uid'),
primary_key=True) primary_key=True)
certificate_type = Column( certificate_type = Column(
'certificate_type', sql.EnumType(enums.CertificateTypeEnum)) 'certificate_type', sql.EnumType(enums.CertificateType))
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': 'Certificate' 'polymorphic_identity': 'Certificate'
@ -1129,8 +1129,8 @@ class Certificate(CryptographicObject):
if not isinstance(self.value, bytes): if not isinstance(self.value, bytes):
raise TypeError("certificate value must be bytes") raise TypeError("certificate value must be bytes")
elif not isinstance(self.certificate_type, elif not isinstance(self.certificate_type,
enums.CertificateTypeEnum): enums.CertificateType):
raise TypeError("certificate type must be a CertificateTypeEnum " raise TypeError("certificate type must be a CertificateType "
"enumeration") "enumeration")
mask_count = len(self.cryptographic_usage_masks) mask_count = len(self.cryptographic_usage_masks)
@ -1192,7 +1192,7 @@ class X509Certificate(Certificate):
name(string): The string name of the certificate. name(string): The string name of the certificate.
""" """
super(X509Certificate, self).__init__( super(X509Certificate, self).__init__(
enums.CertificateTypeEnum.X_509, value, masks, name) enums.CertificateType.X_509, value, masks, name)
# All remaining attributes are not considered part of the public API # All remaining attributes are not considered part of the public API
# and are subject to change. # and are subject to change.

View File

@ -24,7 +24,7 @@ from kmip.core.enums import AttributeType
from kmip.core.enums import CryptographicAlgorithm as CryptoAlgorithmEnum from kmip.core.enums import CryptographicAlgorithm as CryptoAlgorithmEnum
from kmip.core.enums import CryptographicUsageMask from kmip.core.enums import CryptographicUsageMask
from kmip.core.enums import KeyFormatType as KeyFormatTypeEnum from kmip.core.enums import KeyFormatType as KeyFormatTypeEnum
from kmip.core.enums import CertificateTypeEnum from kmip.core.enums import CertificateType
from kmip.core.enums import NameType from kmip.core.enums import NameType
from kmip.core.enums import ObjectType from kmip.core.enums import ObjectType
from kmip.core.enums import OpaqueDataType from kmip.core.enums import OpaqueDataType
@ -838,7 +838,7 @@ class TestIntegration(TestCase):
cert_template_attribute = TemplateAttribute( cert_template_attribute = TemplateAttribute(
attributes=cert_attributes) attributes=cert_attributes)
cert_format_type = CertificateTypeEnum.X_509 cert_format_type = CertificateType.X_509
cert_data = ( cert_data = (
b'\x30\x82\x03\x12\x30\x82\x01\xFA\xA0\x03\x02\x01\x02\x02\x01\x01' b'\x30\x82\x03\x12\x30\x82\x01\xFA\xA0\x03\x02\x01\x02\x02\x01\x01'

View File

@ -26,7 +26,6 @@ from kmip.core.attributes import Name
from kmip.core.attributes import OperationPolicyName from kmip.core.attributes import OperationPolicyName
from kmip.core import enums from kmip.core import enums
from kmip.core.enums import CertificateTypeEnum
from kmip.core.enums import HashingAlgorithm as HashingAlgorithmEnum from kmip.core.enums import HashingAlgorithm as HashingAlgorithmEnum
from kmip.core.enums import NameType from kmip.core.enums import NameType
@ -310,10 +309,10 @@ class TestCertificateType(TestCase):
super(TestCertificateType, self).tearDown() super(TestCertificateType, self).tearDown()
def _test_init(self, value): def _test_init(self, value):
if (isinstance(value, CertificateTypeEnum)) or (value is None): if (isinstance(value, enums.CertificateType)) or (value is None):
if value is None: if value is None:
certificate_type = CertificateType() certificate_type = CertificateType()
value = CertificateTypeEnum.X_509 value = enums.CertificateType.X_509
else: else:
certificate_type = CertificateType(value) certificate_type = CertificateType(value)
@ -335,7 +334,7 @@ class TestCertificateType(TestCase):
Test that a CertificateType object can be constructed with valid byte Test that a CertificateType object can be constructed with valid byte
data. data.
""" """
self._test_init(CertificateTypeEnum.PGP) self._test_init(enums.CertificateType.PGP)
class TestDigestValue(TestCase): class TestDigestValue(TestCase):

View File

@ -16,7 +16,7 @@
from testtools import TestCase from testtools import TestCase
from kmip.core.attributes import CertificateType from kmip.core.attributes import CertificateType
from kmip.core.enums import CertificateTypeEnum from kmip.core import enums
from kmip.core.misc import CertificateValue from kmip.core.misc import CertificateValue
from kmip.core.secrets import Certificate from kmip.core.secrets import Certificate
from kmip.core.utils import BytearrayStream from kmip.core.utils import BytearrayStream
@ -31,7 +31,7 @@ class TestCertificate(TestCase):
super(TestCertificate, self).setUp() super(TestCertificate, self).setUp()
self.certificate_type_a = None self.certificate_type_a = None
self.certificate_type_b = CertificateTypeEnum.X_509 self.certificate_type_b = enums.CertificateType.X_509
# Encodings obtained from Section 13.2 of KMIP 1.1 Test Cases document. # Encodings obtained from Section 13.2 of KMIP 1.1 Test Cases document.
self.certificate_value_a = None self.certificate_value_a = None

View File

@ -171,7 +171,7 @@ class TestCertificate(testtools.TestCase):
""" """
Test that direct instantiation of a Certificate fails. Test that direct instantiation of a Certificate fails.
""" """
args = (enums.CertificateTypeEnum.X_509, self.bytes_a) args = (enums.CertificateType.X_509, self.bytes_a)
self.assertRaises(TypeError, objects.Certificate, *args) self.assertRaises(TypeError, objects.Certificate, *args)
def test_init(self): def test_init(self):
@ -179,10 +179,10 @@ class TestCertificate(testtools.TestCase):
Test that a complete subclass of Certificate can be instantiated. Test that a complete subclass of Certificate can be instantiated.
""" """
certificate = DummyCertificate( certificate = DummyCertificate(
enums.CertificateTypeEnum.X_509, self.bytes_a) enums.CertificateType.X_509, self.bytes_a)
self.assertEqual( self.assertEqual(
certificate.certificate_type, enums.CertificateTypeEnum.X_509) certificate.certificate_type, enums.CertificateType.X_509)
self.assertEqual(certificate.value, self.bytes_a) self.assertEqual(certificate.value, self.bytes_a)
self.assertEqual(certificate.cryptographic_usage_masks, list()) self.assertEqual(certificate.cryptographic_usage_masks, list())
self.assertEqual(certificate.names, ['Certificate']) self.assertEqual(certificate.names, ['Certificate'])
@ -193,14 +193,14 @@ class TestCertificate(testtools.TestCase):
all arguments. all arguments.
""" """
cert = DummyCertificate( cert = DummyCertificate(
enums.CertificateTypeEnum.X_509, enums.CertificateType.X_509,
self.bytes_a, self.bytes_a,
masks=[enums.CryptographicUsageMask.ENCRYPT, masks=[enums.CryptographicUsageMask.ENCRYPT,
enums.CryptographicUsageMask.VERIFY], enums.CryptographicUsageMask.VERIFY],
name='Test Certificate') name='Test Certificate')
self.assertEqual( self.assertEqual(
cert.certificate_type, enums.CertificateTypeEnum.X_509) cert.certificate_type, enums.CertificateType.X_509)
self.assertEqual(cert.value, self.bytes_a) self.assertEqual(cert.value, self.bytes_a)
self.assertEqual(cert.cryptographic_usage_masks, self.assertEqual(cert.cryptographic_usage_masks,
[enums.CryptographicUsageMask.ENCRYPT, [enums.CryptographicUsageMask.ENCRYPT,
@ -213,7 +213,7 @@ class TestCertificate(testtools.TestCase):
of Certificate. of Certificate.
""" """
expected = enums.ObjectType.CERTIFICATE expected = enums.ObjectType.CERTIFICATE
cert = DummyCertificate(enums.CertificateTypeEnum.X_509, self.bytes_a) cert = DummyCertificate(enums.CertificateType.X_509, self.bytes_a)
observed = cert.object_type observed = cert.object_type
self.assertEqual(expected, observed) self.assertEqual(expected, observed)
@ -230,7 +230,7 @@ class TestCertificate(testtools.TestCase):
Test that a TypeError is raised when an invalid length value is used Test that a TypeError is raised when an invalid length value is used
to construct a complete subclass of Certificate. to construct a complete subclass of Certificate.
""" """
args = (enums.CertificateTypeEnum.X_509, 0) args = (enums.CertificateType.X_509, 0)
self.assertRaises(TypeError, DummyCertificate, *args) self.assertRaises(TypeError, DummyCertificate, *args)
def test_validate_on_invalid_masks(self): def test_validate_on_invalid_masks(self):
@ -238,7 +238,7 @@ class TestCertificate(testtools.TestCase):
Test that a TypeError is raised when an invalid masks value is used to Test that a TypeError is raised when an invalid masks value is used to
construct a complete subclass of Certificate. construct a complete subclass of Certificate.
""" """
args = (enums.CertificateTypeEnum.X_509, self.bytes_a) args = (enums.CertificateType.X_509, self.bytes_a)
kwargs = {'masks': 'invalid'} kwargs = {'masks': 'invalid'}
self.assertRaises(TypeError, DummyCertificate, *args, **kwargs) self.assertRaises(TypeError, DummyCertificate, *args, **kwargs)
@ -247,7 +247,7 @@ class TestCertificate(testtools.TestCase):
Test that a TypeError is raised when an invalid mask value is used to Test that a TypeError is raised when an invalid mask value is used to
construct a complete subclass of Certificate. construct a complete subclass of Certificate.
""" """
args = (enums.CertificateTypeEnum.X_509, self.bytes_a) args = (enums.CertificateType.X_509, self.bytes_a)
kwargs = {'masks': ['invalid']} kwargs = {'masks': ['invalid']}
self.assertRaises(TypeError, DummyCertificate, *args, **kwargs) self.assertRaises(TypeError, DummyCertificate, *args, **kwargs)
@ -256,7 +256,7 @@ class TestCertificate(testtools.TestCase):
Test that a TypeError is raised when an invalid name value is used to Test that a TypeError is raised when an invalid name value is used to
construct a complete subclass of Certificate. construct a complete subclass of Certificate.
""" """
args = (enums.CertificateTypeEnum.X_509, self.bytes_a) args = (enums.CertificateType.X_509, self.bytes_a)
kwargs = {'name': 0} kwargs = {'name': 0}
self.assertRaises(TypeError, DummyCertificate, *args, **kwargs) self.assertRaises(TypeError, DummyCertificate, *args, **kwargs)
@ -264,14 +264,14 @@ class TestCertificate(testtools.TestCase):
""" """
Test that repr can be applied to a complete subclass of Certificate. Test that repr can be applied to a complete subclass of Certificate.
""" """
dummy = DummyCertificate(enums.CertificateTypeEnum.X_509, self.bytes_a) dummy = DummyCertificate(enums.CertificateType.X_509, self.bytes_a)
repr(dummy) repr(dummy)
def test_str(self): def test_str(self):
""" """
Test that str can be applied to a complete subclass of Certificate. Test that str can be applied to a complete subclass of Certificate.
""" """
dummy = DummyCertificate(enums.CertificateTypeEnum.X_509, self.bytes_a) dummy = DummyCertificate(enums.CertificateType.X_509, self.bytes_a)
str(dummy) str(dummy)
def test_eq(self): def test_eq(self):
@ -279,7 +279,7 @@ class TestCertificate(testtools.TestCase):
Test that equality can be applied to a complete subclass of Test that equality can be applied to a complete subclass of
Certificate. Certificate.
""" """
dummy = DummyCertificate(enums.CertificateTypeEnum.X_509, self.bytes_a) dummy = DummyCertificate(enums.CertificateType.X_509, self.bytes_a)
self.assertTrue(dummy == dummy) self.assertTrue(dummy == dummy)
def test_ne(self): def test_ne(self):
@ -287,5 +287,5 @@ class TestCertificate(testtools.TestCase):
Test that inequality can be applied to a complete subclass of Test that inequality can be applied to a complete subclass of
Certificate. Certificate.
""" """
dummy = DummyCertificate(enums.CertificateTypeEnum.X_509, self.bytes_a) dummy = DummyCertificate(enums.CertificateType.X_509, self.bytes_a)
self.assertFalse(dummy != dummy) self.assertFalse(dummy != dummy)

View File

@ -149,7 +149,7 @@ class TestX509Certificate(testtools.TestCase):
certificate = X509Certificate(self.bytes_a) certificate = X509Certificate(self.bytes_a)
self.assertEqual( self.assertEqual(
certificate.certificate_type, enums.CertificateTypeEnum.X_509) certificate.certificate_type, enums.CertificateType.X_509)
self.assertEqual(certificate.value, self.bytes_a) self.assertEqual(certificate.value, self.bytes_a)
self.assertEqual(certificate.cryptographic_usage_masks, list()) self.assertEqual(certificate.cryptographic_usage_masks, list())
self.assertEqual(certificate.names, ['X.509 Certificate']) self.assertEqual(certificate.names, ['X.509 Certificate'])
@ -166,7 +166,7 @@ class TestX509Certificate(testtools.TestCase):
name='Test X.509 Certificate') name='Test X.509 Certificate')
self.assertEqual( self.assertEqual(
cert.certificate_type, enums.CertificateTypeEnum.X_509) cert.certificate_type, enums.CertificateType.X_509)
self.assertEqual(cert.value, self.bytes_a) self.assertEqual(cert.value, self.bytes_a)
self.assertEqual(cert.cryptographic_usage_masks, self.assertEqual(cert.cryptographic_usage_masks,
[enums.CryptographicUsageMask.ENCRYPT, [enums.CryptographicUsageMask.ENCRYPT,
@ -223,7 +223,7 @@ class TestX509Certificate(testtools.TestCase):
""" """
cert = X509Certificate(self.bytes_a) cert = X509Certificate(self.bytes_a)
args = "certificate_type={0}, value={1}".format( args = "certificate_type={0}, value={1}".format(
enums.CertificateTypeEnum.X_509, binascii.hexlify(self.bytes_a)) enums.CertificateType.X_509, binascii.hexlify(self.bytes_a))
expected = "X509Certificate({0})".format(args) expected = "X509Certificate({0})".format(args)
observed = repr(cert) observed = repr(cert)
self.assertEqual(expected, observed) self.assertEqual(expected, observed)

View File

@ -341,7 +341,7 @@ class TestObjectFactory(testtools.TestCase):
Test that a core certificate can be converted into a Pie certificate. Test that a core certificate can be converted into a Pie certificate.
""" """
core_cert = secrets.Certificate( core_cert = secrets.Certificate(
enums.CertificateTypeEnum.X_509, self.certificate_bytes) enums.CertificateType.X_509, self.certificate_bytes)
pie_cert = self.factory.convert(core_cert) pie_cert = self.factory.convert(core_cert)
self.assertIsInstance(pie_cert, pobjects.X509Certificate) self.assertIsInstance(pie_cert, pobjects.X509Certificate)
@ -526,7 +526,7 @@ class TestObjectFactory(testtools.TestCase):
unsupported certificate type. unsupported certificate type.
""" """
core_cert = secrets.Certificate( core_cert = secrets.Certificate(
enums.CertificateTypeEnum.PGP, self.certificate_bytes) enums.CertificateType.PGP, self.certificate_bytes)
args = (core_cert, ) args = (core_cert, )
self.assertRaises( self.assertRaises(
TypeError, self.factory._build_pie_certificate, *args) TypeError, self.factory._build_pie_certificate, *args)

View File

@ -1074,7 +1074,7 @@ class TestKmipEngine(testtools.TestCase):
core_object.certificate_value.value core_object.certificate_value.value
) )
self.assertEqual( self.assertEqual(
enums.CertificateTypeEnum.X_509, enums.CertificateType.X_509,
core_object.certificate_type.value core_object.certificate_type.value
) )
@ -1592,7 +1592,7 @@ class TestKmipEngine(testtools.TestCase):
certificate, certificate,
'Certificate Type' 'Certificate Type'
) )
self.assertEqual(enums.CertificateTypeEnum.X_509, result) self.assertEqual(enums.CertificateType.X_509, result)
result = e._get_attribute_from_managed_object( result = e._get_attribute_from_managed_object(
certificate, certificate,