mirror of https://github.com/OpenKMIP/PyKMIP.git
Adding CryptographicParameters construction to attribute values
This commit is contained in:
parent
a7e2084385
commit
63e55e3a06
|
@ -20,6 +20,7 @@ from kmip.core.attributes import ContactInformation
|
|||
from kmip.core.attributes import CryptographicAlgorithm
|
||||
from kmip.core.attributes import CryptographicLength
|
||||
from kmip.core.attributes import CryptographicUsageMask
|
||||
from kmip.core.attributes import CryptographicParameters
|
||||
from kmip.core.attributes import CustomAttribute
|
||||
from kmip.core.attributes import Digest
|
||||
from kmip.core.attributes import Name
|
||||
|
@ -27,6 +28,7 @@ from kmip.core.attributes import ObjectGroup
|
|||
from kmip.core.attributes import UniqueIdentifier
|
||||
from kmip.core.attributes import ObjectType
|
||||
from kmip.core.attributes import OperationPolicyName
|
||||
from kmip.core.attributes import HashingAlgorithm
|
||||
|
||||
from kmip.core import utils
|
||||
|
||||
|
@ -151,7 +153,31 @@ class AttributeValueFactory(object):
|
|||
return CryptographicLength(length)
|
||||
|
||||
def _create_cryptographic_parameters(self, params):
|
||||
raise NotImplementedError()
|
||||
block_cipher_mode = None
|
||||
if 'block_cipher_mode' in params:
|
||||
block_cipher_mode = CryptographicParameters.BlockCipherMode(
|
||||
params.get('block_cipher_mode'))
|
||||
|
||||
padding_method = None
|
||||
if 'padding_method' in params:
|
||||
padding_method = CryptographicParameters.PaddingMethod(
|
||||
params.get('padding_method'))
|
||||
|
||||
key_role_type = None
|
||||
if 'key_role_type' in params:
|
||||
key_role_type = CryptographicParameters.KeyRoleType(
|
||||
params.get('key_role_type'))
|
||||
|
||||
hashing_algorithm = None
|
||||
if 'hashing_algorithm' in params:
|
||||
hashing_algorithm = HashingAlgorithm(
|
||||
params.get("hashing_algorithm"))
|
||||
|
||||
return CryptographicParameters(
|
||||
block_cipher_mode=block_cipher_mode,
|
||||
padding_method=padding_method,
|
||||
hashing_algorithm=hashing_algorithm,
|
||||
key_role_type=key_role_type)
|
||||
|
||||
def _create_cryptographic_domain_parameters(self, params):
|
||||
raise NotImplementedError()
|
||||
|
|
|
@ -16,7 +16,15 @@
|
|||
from testtools import TestCase
|
||||
|
||||
from kmip.core.enums import AttributeType
|
||||
from kmip.core.enums import BlockCipherMode
|
||||
from kmip.core.enums import HashingAlgorithm
|
||||
from kmip.core.enums import PaddingMethod
|
||||
from kmip.core.enums import KeyRoleType
|
||||
|
||||
from kmip.core import attributes
|
||||
from kmip.core.attributes import CryptographicParameters
|
||||
from kmip.core.attributes import OperationPolicyName
|
||||
|
||||
from kmip.core.factories.attribute_values import AttributeValueFactory
|
||||
|
||||
|
||||
|
@ -60,3 +68,67 @@ class TestAttributeValueFactory(TestCase):
|
|||
|
||||
def test_create_operation_policy_name_on_none(self):
|
||||
self._test_create_operation_policy_name(None)
|
||||
|
||||
def _test_cryptograpic_parameters(self, obj, block_cipher_mode,
|
||||
padding_method, key_role_type,
|
||||
hashing_algorithm):
|
||||
msg = "expected {0}, received {1}"
|
||||
self.assertIsInstance(obj, CryptographicParameters, msg.format(
|
||||
CryptographicParameters, obj.__class__))
|
||||
|
||||
self.assertEqual(block_cipher_mode, obj.block_cipher_mode, msg.format(
|
||||
block_cipher_mode, obj.block_cipher_mode))
|
||||
|
||||
self.assertEqual(padding_method, obj.padding_method, msg.format(
|
||||
padding_method, obj.padding_method))
|
||||
|
||||
self.assertEqual(key_role_type, obj.key_role_type, msg.format(
|
||||
key_role_type, obj.hashing_algorithm))
|
||||
|
||||
self.assertEqual(hashing_algorithm, obj.hashing_algorithm, msg.format(
|
||||
hashing_algorithm, obj.hashing_algorithm))
|
||||
|
||||
def test_create_cryptograpic_parameters_none(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{})
|
||||
self._test_cryptograpic_parameters(cp, None, None, None, None)
|
||||
|
||||
def test_create_cryptograpic_parameters_block_cipher_mode(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{'block_cipher_mode': BlockCipherMode.NIST_KEY_WRAP})
|
||||
|
||||
self._test_cryptograpic_parameters(
|
||||
cp, CryptographicParameters.BlockCipherMode(
|
||||
BlockCipherMode.NIST_KEY_WRAP),
|
||||
None, None, None)
|
||||
|
||||
def test_create_cryptograpic_parameters_padding_method(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{'padding_method': PaddingMethod.ANSI_X9_23})
|
||||
|
||||
# noqa - E128 continuation line under-indented for visual indent
|
||||
self._test_cryptograpic_parameters(cp, None,
|
||||
CryptographicParameters.PaddingMethod(PaddingMethod.ANSI_X9_23),
|
||||
None, None) # noqa
|
||||
|
||||
def test_create_cryptograpic_parameters_key_role_type(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{'key_role_type': KeyRoleType.KEK})
|
||||
|
||||
# noqa - E128 continuation line under-indented for visual indent
|
||||
self._test_cryptograpic_parameters(cp, None, None,
|
||||
CryptographicParameters.KeyRoleType(KeyRoleType.KEK),
|
||||
None) # noqa
|
||||
|
||||
def test_create_cryptograpic_parameters_hashing_algorithm(self):
|
||||
cp = self.factory.create_attribute_value(
|
||||
AttributeType.CRYPTOGRAPHIC_PARAMETERS,
|
||||
{'hashing_algorithm': HashingAlgorithm.SHA_512})
|
||||
|
||||
# noqa - E128 continuation line under-indented for visual indent
|
||||
self._test_cryptograpic_parameters(cp, None, None, None,
|
||||
attributes.HashingAlgorithm(HashingAlgorithm.SHA_512)) # noqa
|
||||
|
|
Loading…
Reference in New Issue