mirror of https://github.com/OpenKMIP/PyKMIP.git
Adding additional cryptographic base classes
This change adds two additional abstract base classes for the Pie ManagedObject object hierarchy: CryptographicObject and Key. Test suites are provided for each base class, using a dummy subclass of each for testing. The object test suite package structure is also modified to collect all ManagedObject subclass tests in one package.
This commit is contained in:
parent
ac6a9edec7
commit
a90e0f0b98
|
@ -22,7 +22,7 @@ from six import add_metaclass
|
|||
@add_metaclass(ABCMeta)
|
||||
class ManagedObject:
|
||||
"""
|
||||
The abstract base object of the simplified KMIP object hierarchy.
|
||||
The abstract base class of the simplified KMIP object hierarchy.
|
||||
|
||||
A ManagedObject is a core KMIP object that is the subject of key
|
||||
management operations. It contains various attributes that are common to
|
||||
|
@ -98,3 +98,81 @@ class ManagedObject:
|
|||
@abstractmethod
|
||||
def __ne__(self, other):
|
||||
pass
|
||||
|
||||
|
||||
class CryptographicObject(ManagedObject):
|
||||
"""
|
||||
The abstract base class of all ManagedObjects related to cryptography.
|
||||
|
||||
A CryptographicObject is a core KMIP object that is the subject of key
|
||||
management operations. It contains various attributes that are common to
|
||||
all types of CryptographicObjects, including keys and certificates.
|
||||
|
||||
For more information, see Section 2.2 of the KMIP 1.1 specification.
|
||||
|
||||
Attributes:
|
||||
cryptographic_usage_masks: A list of usage mask enumerations
|
||||
describing how the CryptographicObject will be used.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
"""
|
||||
Create a CryptographicObject.
|
||||
"""
|
||||
|
||||
super(CryptographicObject, self).__init__()
|
||||
|
||||
self.crpytographic_usage_masks = list()
|
||||
|
||||
# All remaining attributes are not considered part of the public API
|
||||
# and are subject to change.
|
||||
self._digests = list()
|
||||
|
||||
# The following attributes are placeholders for attributes that are
|
||||
# unsupported by kmip.core
|
||||
self._activation_date = None
|
||||
self._compromise_date = None
|
||||
self._compromise_occurrence_date = None
|
||||
self._deactivation_date = None
|
||||
self._destroy_date = None
|
||||
self._fresh = None
|
||||
self._lease_time = None
|
||||
self._links = list()
|
||||
self._revocation_reason = None
|
||||
self._state = None
|
||||
|
||||
|
||||
class Key(CryptographicObject):
|
||||
"""
|
||||
The abstract base class of all ManagedObjects that are cryptographic keys.
|
||||
|
||||
A Key is a core KMIP object that is the subject of key management
|
||||
operations. It contains various attributes that are common to all types of
|
||||
Keys, including symmetric and asymmetric keys.
|
||||
|
||||
For more information, see Section 2.2 of the KMIP 1.1 specification.
|
||||
|
||||
Attributes:
|
||||
cryptographic_algorithm: A CryptographicAlgorithm enumeration defining
|
||||
the algorithm the key should be used with.
|
||||
cryptographic_length: An int defining the length of the key in bits.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, value=None, algorithm=None, length=None):
|
||||
"""
|
||||
Create a Key object.
|
||||
"""
|
||||
super(Key, self).__init__()
|
||||
|
||||
self.cryptographic_algorithm = None
|
||||
self.cryptographic_length = None
|
||||
|
||||
# All remaining attributes are not considered part of the public API
|
||||
# and are subject to change.
|
||||
self._cryptographic_parameters = list()
|
||||
|
||||
# The following attributes are placeholders for attributes that are
|
||||
# unsupported by kmip.core
|
||||
self._usage_limits = None
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
# Copyright (c) 2015 The Johns Hopkins University/Applied Physics Laboratory
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
|
@ -0,0 +1,93 @@
|
|||
# Copyright (c) 2015 The Johns Hopkins University/Applied Physics Laboratory
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from testtools import TestCase
|
||||
|
||||
from kmip.pie.objects import CryptographicObject
|
||||
|
||||
|
||||
class DummyCryptographicObject(CryptographicObject):
|
||||
"""
|
||||
A dummy CryptographicObject subclass for testing purposes.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Create a DummyCryptographicObject
|
||||
"""
|
||||
super(DummyCryptographicObject, self).__init__()
|
||||
|
||||
def __repr__(self):
|
||||
return ''
|
||||
|
||||
def __str__(self):
|
||||
return ''
|
||||
|
||||
def __eq__(self, other):
|
||||
return True
|
||||
|
||||
def __ne__(self, other):
|
||||
return False
|
||||
|
||||
|
||||
class TestCryptographicObject(TestCase):
|
||||
"""
|
||||
Test suite for CryptographicObject.
|
||||
|
||||
Since CryptographicObject is an ABC abstract class, all tests are run
|
||||
against a dummy subclass defined above, DummyCryptographicObject.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestCryptographicObject, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCryptographicObject, self).tearDown()
|
||||
|
||||
def test_init(self):
|
||||
"""
|
||||
Test that a complete subclass of CryptographicObject can be
|
||||
instantiated.
|
||||
"""
|
||||
DummyCryptographicObject()
|
||||
|
||||
def test_repr(self):
|
||||
"""
|
||||
Test that repr can be applied to a CryptographicObject.
|
||||
"""
|
||||
dummy = DummyCryptographicObject()
|
||||
repr(dummy)
|
||||
|
||||
def test_str(self):
|
||||
"""
|
||||
Test that str can be applied to a CryptographicObject.
|
||||
"""
|
||||
dummy = DummyCryptographicObject()
|
||||
str(dummy)
|
||||
|
||||
def test_eq(self):
|
||||
"""
|
||||
Test that equality can be applied to a CryptographicObject.
|
||||
"""
|
||||
dummy = DummyCryptographicObject()
|
||||
self.assertTrue(dummy == dummy)
|
||||
|
||||
def test_ne(self):
|
||||
"""
|
||||
Test that inequality can be applied to a CryptographicObject.
|
||||
"""
|
||||
dummy = DummyCryptographicObject()
|
||||
self.assertFalse(dummy != dummy)
|
|
@ -0,0 +1,93 @@
|
|||
# Copyright (c) 2015 The Johns Hopkins University/Applied Physics Laboratory
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from testtools import TestCase
|
||||
|
||||
from kmip.pie.objects import Key
|
||||
|
||||
|
||||
class DummyKey(Key):
|
||||
"""
|
||||
A dummy Key subclass for testing purposes.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Create a DummyKey
|
||||
"""
|
||||
super(DummyKey, self).__init__()
|
||||
|
||||
def __repr__(self):
|
||||
return ''
|
||||
|
||||
def __str__(self):
|
||||
return ''
|
||||
|
||||
def __eq__(self, other):
|
||||
return True
|
||||
|
||||
def __ne__(self, other):
|
||||
return False
|
||||
|
||||
|
||||
class TestKey(TestCase):
|
||||
"""
|
||||
Test suite for Key.
|
||||
|
||||
Since Key is an ABC abstract class, all tests are run against a dummy
|
||||
subclass defined above, DummyKey.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestKey, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestKey, self).tearDown()
|
||||
|
||||
def test_init(self):
|
||||
"""
|
||||
Test that a complete subclass of Key can be
|
||||
instantiated.
|
||||
"""
|
||||
DummyKey()
|
||||
|
||||
def test_repr(self):
|
||||
"""
|
||||
Test that repr can be applied to a Key.
|
||||
"""
|
||||
dummy = DummyKey()
|
||||
repr(dummy)
|
||||
|
||||
def test_str(self):
|
||||
"""
|
||||
Test that str can be applied to a Key.
|
||||
"""
|
||||
dummy = DummyKey()
|
||||
str(dummy)
|
||||
|
||||
def test_eq(self):
|
||||
"""
|
||||
Test that equality can be applied to a Key.
|
||||
"""
|
||||
dummy = DummyKey()
|
||||
self.assertTrue(dummy == dummy)
|
||||
|
||||
def test_ne(self):
|
||||
"""
|
||||
Test that inequality can be applied to a Key.
|
||||
"""
|
||||
dummy = DummyKey()
|
||||
self.assertFalse(dummy != dummy)
|
Loading…
Reference in New Issue