2
0
mirror of https://github.com/openkmip/pykmip synced 2025-12-15 15:53:36 +00:00

Add Attribute class unit tests

This pull request:

- Adds the comparison operators to the following classes:

 -- Attribute.AttributeName class

- Fixes bug in the "_create_cryptographic_parameters" function when "None" type parameters are used

- Adds read, write, and comparator unit tests for the Attribute class in the /kmip/core/objects.py file

Signed-off-by: Hadi Esiely <hadi.esiely-barrera@jhuapl.edu>
This commit is contained in:
Hadi Esiely
2016-03-01 10:53:29 -05:00
parent 79696e3ef5
commit a7c41c758b
5 changed files with 235 additions and 19 deletions

View File

@@ -206,7 +206,6 @@ class CryptographicParameters(Struct):
enums.BlockCipherMode, value, Tags.BLOCK_CIPHER_MODE)
class PaddingMethod(Enumeration):
def __init__(self, value=None):
super(CryptographicParameters.PaddingMethod, self).__init__(
enums.PaddingMethod, value, Tags.PADDING_METHOD)
@@ -274,8 +273,49 @@ class CryptographicParameters(Struct):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
if self.block_cipher_mode is not None:
if not isinstance(self.block_cipher_mode, self.BlockCipherMode):
msg = "Invalid block cipher mode"
msg += "; expected {0}, received {1}".format(
self.BlockCipherMode, self.block_cipher_mode)
raise TypeError(msg)
if self.padding_method is not None:
if not isinstance(self.padding_method, self.PaddingMethod):
msg = "Invalid padding method"
msg += "; expected {0}, received {1}".format(
self.PaddingMethod, self.padding_method)
raise TypeError(msg)
if self.hashing_algorithm is not None:
if not isinstance(self.hashing_algorithm, HashingAlgorithm):
msg = "Invalid hashing algorithm"
msg += "; expected {0}, received {1}".format(
HashingAlgorithm, self.hashing_algorithm)
raise TypeError(msg)
if self.key_role_type is not None:
if not isinstance(self.key_role_type, self.KeyRoleType):
msg = "Invalid key role type"
msg += "; expected {0}, received {1}".format(
self.KeyRoleType, self.key_role_type)
raise TypeError(msg)
def __eq__(self, other):
if isinstance(other, CryptographicParameters):
if self.block_cipher_mode != other.block_cipher_mode:
return False
elif self.key_role_type != other.key_role_type:
return False
elif self.hashing_algorithm != other.hashing_algorithm:
return False
elif self.padding_method != other.padding_method:
return False
else:
return True
def __ne__(self, other):
if isinstance(other, CryptographicParameters):
return not self == other
else:
return NotImplemented
class CertificateType(Enumeration):