Updating support for the Enumeration primitive

This change updates the Enumeration primitive, adding a fresh
implementation and documentation. An updated unit test suite for the
primitive is included. Numerous changes to Enumeration usage across the
library are also included to comply with the updated implementation.
This commit is contained in:
Peter Hamilton 2015-09-29 13:23:44 -04:00
parent 55b35b0353
commit 20dbad5055
36 changed files with 732 additions and 529 deletions

View File

@ -65,10 +65,9 @@ class Name(Struct):
class NameType(Enumeration):
ENUM_TYPE = enums.NameType
def __init__(self, value=None):
super(Name.NameType, self).__init__(value, Tags.NAME_TYPE)
super(Name.NameType, self).__init__(
enums.NameType, value, Tags.NAME_TYPE)
def __init__(self, name_value=None, name_type=None):
super(Name, self).__init__(tag=Tags.NAME)
@ -154,20 +153,17 @@ class Name(Struct):
# 3.3
class ObjectType(Enumeration):
ENUM_TYPE = enums.ObjectType
def __init__(self, value=None):
super(ObjectType, self).__init__(value, Tags.OBJECT_TYPE)
super(ObjectType, self).__init__(
enums.ObjectType, value, Tags.OBJECT_TYPE)
# 3.4
class CryptographicAlgorithm(Enumeration):
ENUM_TYPE = enums.CryptographicAlgorithm
def __init__(self, value=None):
super(CryptographicAlgorithm, self).__init__(
value, Tags.CRYPTOGRAPHIC_ALGORITHM)
enums.CryptographicAlgorithm, value, Tags.CRYPTOGRAPHIC_ALGORITHM)
# 3.5
@ -187,7 +183,6 @@ class HashingAlgorithm(Enumeration):
Object. See Sections 3.17 and 9.1.3.2.16 of the KMIP v1.1 specification
for more information.
"""
ENUM_TYPE = enums.HashingAlgorithm
def __init__(self, value=HashingAlgorithmEnum.SHA_256):
"""
@ -198,31 +193,29 @@ class HashingAlgorithm(Enumeration):
(e.g., HashingAlgorithm.MD5). Optional, defaults to
HashingAlgorithm.SHA_256.
"""
super(HashingAlgorithm, self).__init__(value, Tags.HASHING_ALGORITHM)
super(HashingAlgorithm, self).__init__(
enums.HashingAlgorithm, value, Tags.HASHING_ALGORITHM)
class CryptographicParameters(Struct):
class BlockCipherMode(Enumeration):
ENUM_TYPE = enums.BlockCipherMode
def __init__(self, value=None):
super(CryptographicParameters.BlockCipherMode, self).__init__(
value, Tags.BLOCK_CIPHER_MODE)
enums.BlockCipherMode, value, Tags.BLOCK_CIPHER_MODE)
class PaddingMethod(Enumeration):
ENUM_TYPE = enums.PaddingMethod
def __init__(self, value=None):
super(CryptographicParameters.PaddingMethod, self).__init__(
value, Tags.PADDING_METHOD)
enums.PaddingMethod, value, Tags.PADDING_METHOD)
class KeyRoleType(Enumeration):
ENUM_TYPE = enums.KeyRoleType
def __init__(self, value=None):
super(CryptographicParameters.KeyRoleType, self).__init__(
value, Tags.KEY_ROLE_TYPE)
enums.KeyRoleType, value, Tags.KEY_ROLE_TYPE)
def __init__(self,
block_cipher_mode=None,
@ -293,7 +286,6 @@ class CertificateType(Enumeration):
Object. See Sections 2.2.1 and 3.8 of the KMIP v1.1 specification for more
information.
"""
ENUM_TYPE = enums.CertificateTypeEnum
def __init__(self, value=CertificateTypeEnum.X_509):
"""
@ -304,7 +296,8 @@ class CertificateType(Enumeration):
value, (e.g., CertificateTypeEnum.PGP). Optional, defaults to
CertificateTypeEnum.X_509.
"""
super(CertificateType, self).__init__(value, Tags.CERTIFICATE_TYPE)
super(CertificateType, self).__init__(
enums.CertificateTypeEnum, value, Tags.CERTIFICATE_TYPE)
class DigestValue(ByteString):

View File

@ -16,10 +16,10 @@
# In case of new content, remove the following line to enable flake8 tests
# flake8: noqa
from enum import Enum
import enum
class AttributeType(Enum):
class AttributeType(enum.Enum):
UNIQUE_IDENTIFIER = 'Unique Identifier'
NAME = 'Name'
OBJECT_TYPE = 'Object Type'
@ -61,7 +61,7 @@ class AttributeType(Enum):
CUSTOM_ATTRIBUTE = 'Custom Attribute'
class ConformanceClause(Enum):
class ConformanceClause(enum.Enum):
"""
The specification of KMIP features supported by KMIP clients and servers.
@ -83,7 +83,7 @@ class ConformanceClause(Enum):
STORAGE = 11
class AuthenticationSuite(Enum):
class AuthenticationSuite(enum.Enum):
"""
The type of authentication suite used by KMIP clients and servers.
@ -98,7 +98,7 @@ class AuthenticationSuite(Enum):
# 9.1.1.2
class Types(Enum):
class Types(enum.Enum):
DEFAULT = 0x00
STRUCTURE = 0x01
INTEGER = 0x02
@ -113,7 +113,7 @@ class Types(Enum):
# 9.1.3.1
class Tags(Enum):
class Tags(enum.Enum):
DEFAULT = 0x420000
ACTIVATION_DATE = 0x420001
APPLICATION_DATA = 0x420002
@ -303,13 +303,13 @@ class Tags(Enum):
# 9.1.3.2.1
class CredentialType(Enum):
class CredentialType(enum.Enum):
USERNAME_AND_PASSWORD = 0x00000001
DEVICE = 0x00000002
# 9.1.3.2.2
class KeyCompressionType(Enum):
class KeyCompressionType(enum.Enum):
EC_PUBLIC_KEY_TYPE_UNCOMPRESSED = 0x00000001
EC_PUBLIC_KEY_TYPE_X9_62_COMPRESSED_PRIME = 0x00000002
EC_PUBLIC_KEY_TYPE_X9_62_COMPRESSED_CHAR2 = 0x00000003
@ -317,7 +317,7 @@ class KeyCompressionType(Enum):
# 9.1.3.2.3
class KeyFormatType(Enum):
class KeyFormatType(enum.Enum):
RAW = 0x00000001
OPAQUE = 0x00000002
PKCS_1 = 0x00000003
@ -340,7 +340,7 @@ class KeyFormatType(Enum):
# 9.1.3.2.4
class WrappingMethod(Enum):
class WrappingMethod(enum.Enum):
ENCRYPT = 0x00000001
MAC_SIGN = 0x00000002
ENCRYPT_THEN_MAC_SIGN = 0x00000003
@ -349,7 +349,7 @@ class WrappingMethod(Enum):
# 9.1.3.2.6
class CertificateTypeEnum(Enum):
class CertificateTypeEnum(enum.Enum):
"""
The type of a Certificate Managed Object.
@ -360,32 +360,32 @@ class CertificateTypeEnum(Enum):
# 9.1.3.2.8
class SplitKeyMethod(Enum):
class SplitKeyMethod(enum.Enum):
XOR = 0x00000001
POLYNOMIAL_SHARING_GF = 0x00000002
POLYNOMIAL_SHARING_PRIME_FIELD = 0x00000003
# 9.1.3.2.9
class SecretDataType(Enum):
class SecretDataType(enum.Enum):
PASSWORD = 0x00000001
SEED = 0x00000002
# 9.1.3.2.10
class OpaqueDataType(Enum):
class OpaqueDataType(enum.Enum):
NONE = 0x80000000 # Not defined by the standard, but we need something.
# The standard does say that values starting 0x8xxxxxx
# are considered extensions
# 9.1.3.2.11
class NameType(Enum):
class NameType(enum.Enum):
UNINTERPRETED_TEXT_STRING = 0x00000001
URI = 0x00000002
# 9.1.3.2.12
class ObjectType(Enum):
class ObjectType(enum.Enum):
CERTIFICATE = 0x00000001
SYMMETRIC_KEY = 0x00000002
PUBLIC_KEY = 0x00000003
@ -397,7 +397,7 @@ class ObjectType(Enum):
# 9.1.3.2.13
class CryptographicAlgorithm(Enum):
class CryptographicAlgorithm(enum.Enum):
DES = 0x00000001
TRIPLE_DES = 0x00000002 # '3DES' is invalid syntax
AES = 0x00000003
@ -426,7 +426,7 @@ class CryptographicAlgorithm(Enum):
# 9.1.3.2.14
class BlockCipherMode(Enum):
class BlockCipherMode(enum.Enum):
CBC = 0x00000001
ECB = 0x00000002
PCBC = 0x00000003
@ -447,7 +447,7 @@ class BlockCipherMode(Enum):
# 9.1.3.2.15
class PaddingMethod(Enum):
class PaddingMethod(enum.Enum):
NONE = 0x00000001
OAEP = 0x00000002
PKCS5 = 0x00000003
@ -461,7 +461,7 @@ class PaddingMethod(Enum):
# 9.1.3.2.16
class HashingAlgorithm(Enum):
class HashingAlgorithm(enum.Enum):
MD2 = 0x00000001
MD4 = 0x00000002
MD5 = 0x00000003
@ -476,7 +476,7 @@ class HashingAlgorithm(Enum):
# 9.1.3.2.17
class KeyRoleType(Enum):
class KeyRoleType(enum.Enum):
BDK = 0x00000001
CVK = 0x00000002
DEK = 0x00000003
@ -501,7 +501,7 @@ class KeyRoleType(Enum):
# 9.1.3.2.24
class QueryFunction(Enum):
class QueryFunction(enum.Enum):
QUERY_OPERATIONS = 0x00000001
QUERY_OBJECTS = 0x00000002
QUERY_SERVER_INFORMATION = 0x00000003
@ -510,7 +510,7 @@ class QueryFunction(Enum):
QUERY_EXTENSION_MAP = 0x00000006
# 9.1.3.2.27
class Operation(Enum):
class Operation(enum.Enum):
CREATE = 0x00000001
CREATE_KEY_PAIR = 0x00000002
REGISTER = 0x00000003
@ -544,7 +544,7 @@ class Operation(Enum):
# 9.1.3.2.28
class ResultStatus(Enum):
class ResultStatus(enum.Enum):
SUCCESS = 0x00000000
OPERATION_FAILED = 0x00000001
OPERATION_PENDING = 0x00000002
@ -552,7 +552,7 @@ class ResultStatus(Enum):
# 9.1.3.2.29
class ResultReason(Enum):
class ResultReason(enum.Enum):
ITEM_NOT_FOUND = 0x00000001
RESPONSE_TOO_LARGE = 0x00000002
AUTHENTICATION_NOT_SUCCESSFUL = 0x00000003
@ -575,21 +575,21 @@ class ResultReason(Enum):
# 9.1.3.2.30
class BatchErrorContinuationOption(Enum):
class BatchErrorContinuationOption(enum.Enum):
CONTINUE = 0x00000001
STOP = 0x00000002
UNDO = 0x00000003
# 9.1.3.2.32
class EncodingOption(Enum):
class EncodingOption(enum.Enum):
NO_ENCODING = 0x00000001
TTLV_ENCODING = 0x00000002
# 9.1.3.3
# 9.1.3.3.1
class CryptographicUsageMask(Enum):
class CryptographicUsageMask(enum.Enum):
SIGN = 0x00000001
VERIFY = 0x00000002
ENCRYPT = 0x00000004
@ -612,16 +612,16 @@ class CryptographicUsageMask(Enum):
TRANSLATE_UNWRAP = 0x00080000
# 9.1.3.2.33
class ObjectGroupMember(Enum):
class ObjectGroupMember(enum.Enum):
GROUP_MEMBER_FRESH = 0x00000001
GROUP_MEMBER_DEFAULT = 0x00000002
# 9.1.3.3.2
class StorageStatusMask(Enum):
class StorageStatusMask(enum.Enum):
ONLINE_STORAGE = 0x00000001
ARCHIVAL_STORAGE = 0x00000002
class RevocationReasonCode(Enum):
class RevocationReasonCode(enum.Enum):
UNSPECIFIED = 0x00000001
KEY_COMPROMISE = 0x00000002
CA_COMPROMISE = 0x00000003

View File

@ -13,13 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from kmip.core.enums import BatchErrorContinuationOption
from kmip.core.enums import KeyCompressionType
from kmip.core.enums import Operation
from kmip.core.enums import ResultStatus
from kmip.core.enums import ResultReason
from kmip.core.enums import Tags
from kmip.core import enums
from kmip.core import objects
from kmip.core import utils
@ -38,17 +32,17 @@ class ProtocolVersion(Struct):
class ProtocolVersionMajor(Integer):
def __init__(self, value=None):
super(ProtocolVersion.ProtocolVersionMajor, self).\
__init__(value, Tags.PROTOCOL_VERSION_MAJOR)
__init__(value, enums.Tags.PROTOCOL_VERSION_MAJOR)
class ProtocolVersionMinor(Integer):
def __init__(self, value=None):
super(ProtocolVersion.ProtocolVersionMinor, self).\
__init__(value, Tags.PROTOCOL_VERSION_MINOR)
__init__(value, enums.Tags.PROTOCOL_VERSION_MINOR)
def __init__(self,
protocol_version_major=None,
protocol_version_minor=None):
super(ProtocolVersion, self).__init__(Tags.PROTOCOL_VERSION)
super(ProtocolVersion, self).__init__(enums.Tags.PROTOCOL_VERSION)
if protocol_version_major is None:
self.protocol_version_major = \
@ -139,37 +133,37 @@ class ProtocolVersion(Struct):
# 6.2
class Operation(Enumeration):
ENUM_TYPE = Operation
def __init__(self, value=None):
super(Operation, self).__init__(value, Tags.OPERATION)
super(Operation, self).__init__(
enums.Operation, value, enums.Tags.OPERATION)
# 6.3
class MaximumResponseSize(Integer):
def __init__(self, value=None):
super(MaximumResponseSize, self).\
__init__(value, Tags.MAXIMUM_RESPONSE_SIZE)
__init__(value, enums.Tags.MAXIMUM_RESPONSE_SIZE)
# 6.4
class UniqueBatchItemID(ByteString):
def __init__(self, value=None):
super(UniqueBatchItemID, self)\
.__init__(value, Tags.UNIQUE_BATCH_ITEM_ID)
.__init__(value, enums.Tags.UNIQUE_BATCH_ITEM_ID)
# 6.5
class TimeStamp(DateTime):
def __init__(self, value=None):
super(TimeStamp, self).__init__(value, Tags.TIME_STAMP)
super(TimeStamp, self).__init__(value, enums.Tags.TIME_STAMP)
# 6.6
class Authentication(Struct):
def __init__(self, credential=None):
super(Authentication, self).__init__(Tags.AUTHENTICATION)
super(Authentication, self).__init__(enums.Tags.AUTHENTICATION)
self.credential = credential
def read(self, istream):
@ -202,70 +196,69 @@ class Authentication(Struct):
class AsynchronousIndicator(Boolean):
def __init__(self, value=None):
super(AsynchronousIndicator, self).\
__init__(value, Tags.ASYNCHRONOUS_INDICATOR)
__init__(value, enums.Tags.ASYNCHRONOUS_INDICATOR)
# 6.8
class AsynchronousCorrelationValue(ByteString):
def __init__(self, value=None):
super(AsynchronousCorrelationValue, self).\
__init__(value, Tags.ASYNCHRONOUS_CORRELATION_VALUE)
__init__(value, enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE)
# 6.9
class ResultStatus(Enumeration):
ENUM_TYPE = ResultStatus
def __init__(self, value=None):
super(ResultStatus, self).__init__(value, Tags.RESULT_STATUS)
super(ResultStatus, self).__init__(
enums.ResultStatus, value, enums.Tags.RESULT_STATUS)
# 6.10
class ResultReason(Enumeration):
ENUM_TYPE = ResultReason
def __init__(self, value=None):
super(ResultReason, self).__init__(value, Tags.RESULT_REASON)
super(ResultReason, self).__init__(
enums.ResultReason, value, enums.Tags.RESULT_REASON)
# 6.11
class ResultMessage(TextString):
def __init__(self, value=None):
super(ResultMessage, self).__init__(value, Tags.RESULT_MESSAGE)
super(ResultMessage, self).__init__(value, enums.Tags.RESULT_MESSAGE)
# 6.12
class BatchOrderOption(Boolean):
def __init__(self, value=None):
super(BatchOrderOption, self).\
__init__(value, Tags.BATCH_ORDER_OPTION)
__init__(value, enums.Tags.BATCH_ORDER_OPTION)
# 6.13
class BatchErrorContinuationOption(Enumeration):
ENUM_TYPE = BatchErrorContinuationOption
def __init__(self, value=None):
super(BatchErrorContinuationOption, self).\
__init__(value, Tags.BATCH_ERROR_CONTINUATION_OPTION)
super(BatchErrorContinuationOption, self).__init__(
BatchErrorContinuationOption, value,
enums.Tags.BATCH_ERROR_CONTINUATION_OPTION)
# 6.14
class BatchCount(Integer):
def __init__(self, value=None):
super(BatchCount, self).__init__(value, Tags.BATCH_COUNT)
super(BatchCount, self).__init__(value, enums.Tags.BATCH_COUNT)
# 6.16
class MessageExtension(Struct):
def __init__(self):
super(MessageExtension, self).__init__(Tags.MESSAGE_EXTENSION)
super(MessageExtension, self).__init__(enums.Tags.MESSAGE_EXTENSION)
# 9.1.3.2.2
class KeyCompressionType(Enumeration):
ENUM_TYPE = KeyCompressionType
def __init__(self, value=None):
super(KeyCompressionType, self).\
__init__(value, Tags.KEY_COMPRESSION_TYPE)
super(KeyCompressionType, self).__init__(
enums.KeyCompressionType, value, enums.Tags.KEY_COMPRESSION_TYPE)

View File

@ -200,7 +200,7 @@ class RequestBatchItem(Struct):
# Dynamically create the response payload class that belongs to the
# operation
self.request_payload = self.payload_factory.create(
self.operation.enum)
self.operation.value)
self.request_payload.read(tstream)
# Read the message extension if it is present
@ -290,7 +290,7 @@ class ResponseBatchItem(Struct):
# Dynamically create the response payload class that belongs to the
# operation
expected = self.payload_factory.create(self.operation.enum)
expected = self.payload_factory.create(self.operation.value)
if self.is_tag_next(expected.tag, tstream):
self.response_payload = expected
self.response_payload.read(tstream)

View File

@ -32,19 +32,17 @@ class GetRequestPayload(Struct):
# 9.1.3.2.2
class KeyCompressionType(Enumeration):
ENUM_TYPE = enums.KeyCompressionType
def __init__(self, value=None):
super(GetRequestPayload.KeyCompressionType, self).__init__(
value, Tags.KEY_COMPRESSION_TYPE)
enums.KeyCompressionType, value, Tags.KEY_COMPRESSION_TYPE)
# 9.1.3.2.3
class KeyFormatType(Enumeration):
ENUM_TYPE = enums.KeyFormatType
def __init__(self, value=None):
super(GetRequestPayload.KeyFormatType, self).__init__(
value, Tags.KEY_FORMAT_TYPE)
enums.KeyFormatType, value, Tags.KEY_FORMAT_TYPE)
def __init__(self,
unique_identifier=None,
@ -130,7 +128,7 @@ class GetResponsePayload(Struct):
self.object_type.read(tstream)
self.unique_identifier.read(tstream)
secret_type = self.object_type.enum
secret_type = self.object_type.value
self.secret = self.secret_factory.create(secret_type)
self.secret.read(tstream)

View File

@ -30,11 +30,10 @@ class LocateRequestPayload(Struct):
# 9.1.3.2.33
class ObjectGroupMember(Enumeration):
ENUM_TYPE = enums.ObjectGroupMember
def __init__(self, value=None):
super(LocateRequestPayload.ObjectGroupMember, self).__init__(
value, Tags.OBJECT_GROUP_MEMBER)
enums.ObjectGroupMember, value, Tags.OBJECT_GROUP_MEMBER)
class MaximumItems(Integer):
def __init__(self, value=None):
@ -43,11 +42,10 @@ class LocateRequestPayload(Struct):
# 9.1.3.3.2
class StorageStatusMask(Enumeration):
ENUM_TYPE = enums.StorageStatusMask
def __init__(self, value=None):
super(LocateRequestPayload.StorageStatusMask, self).__init__(
value, Tags.STORAGE_STATUS_MASK)
enums.StorageStatusMask, value, Tags.STORAGE_STATUS_MASK)
def __init__(self, maximum_items=None, storage_status_mask=None,
object_group_member=None, attributes=None):

View File

@ -51,7 +51,7 @@ class RegisterRequestPayload(Struct):
self.object_type.read(tstream)
self.template_attribute.read(tstream)
secret_type = self.object_type.enum
secret_type = self.object_type.value
secret = self.secret_factory.create(secret_type)
if self.is_tag_next(secret.tag, tstream):

View File

@ -76,7 +76,6 @@ class QueryFunction(Enumeration):
KMIP server. See Sections 4.25 and 9.1.3.2.24 of the KMIP 1.1
specification for more information.
"""
ENUM_TYPE = QueryFunctionEnum
def __init__(self, value=None):
"""
@ -87,7 +86,8 @@ class QueryFunction(Enumeration):
(e.g., QueryFunction.QUERY_OPERATIONS). Optional, default to
None.
"""
super(QueryFunction, self).__init__(value, Tags.QUERY_FUNCTION)
super(QueryFunction, self).__init__(
QueryFunctionEnum, value, Tags.QUERY_FUNCTION)
class VendorIdentification(TextString):
@ -216,7 +216,6 @@ class KeyFormatType(Enumeration):
is returned when using the Get operation. See Sections 2.1.3, 2.1.7, 3.17,
4.11, and 9.1.3.2.3 of the KMIP 1.1 specification for more information.
"""
ENUM_TYPE = KeyFormatTypeEnum
def __init__(self, value=KeyFormatTypeEnum.RAW):
"""
@ -227,4 +226,5 @@ class KeyFormatType(Enumeration):
(e.g., KeyFormatType.PKCS_1). Optional, default to
KeyFormatType.RAW.
"""
super(KeyFormatType, self).__init__(value, Tags.KEY_FORMAT_TYPE)
super(KeyFormatType, self).__init__(
KeyFormatTypeEnum, value, Tags.KEY_FORMAT_TYPE)

View File

@ -136,11 +136,9 @@ class Credential(Struct):
class CredentialType(Enumeration):
ENUM_TYPE = CredentialType
def __init__(self, value=None):
super(Credential.CredentialType, self).__init__(
value, Tags.CREDENTIAL_TYPE)
CredentialType, value, Tags.CREDENTIAL_TYPE)
class UsernamePasswordCredential(Struct):
@ -323,9 +321,9 @@ class Credential(Struct):
self.credential_type.read(tstream)
# Use the type to determine what credential value to read
if self.credential_type.enum is CredentialType.USERNAME_AND_PASSWORD:
if self.credential_type.value is CredentialType.USERNAME_AND_PASSWORD:
self.credential_value = self.UsernamePasswordCredential()
elif self.credential_type.enum is CredentialType.DEVICE:
elif self.credential_type.value is CredentialType.DEVICE:
self.credential_value = self.DeviceCredential()
else:
# TODO (peter-hamilton) Use more descriptive error here
@ -354,11 +352,10 @@ class Credential(Struct):
class KeyBlock(Struct):
class KeyCompressionType(Enumeration):
ENUM_TYPE = enums.KeyCompressionType
def __init__(self, value=None):
super(KeyBlock.KeyCompressionType, self).__init__(
value, Tags.KEY_COMPRESSION_TYPE)
enums.KeyCompressionType, value, Tags.KEY_COMPRESSION_TYPE)
def __init__(self,
key_format_type=None,
@ -562,17 +559,17 @@ class KeyValue(Struct):
# 2.1.5
class WrappingMethod(Enumeration):
ENUM_TYPE = enums.WrappingMethod
def __init__(self, value=None):
super(WrappingMethod, self).__init__(value, Tags.WRAPPING_METHOD)
super(WrappingMethod, self).__init__(
enums.WrappingMethod, value, Tags.WRAPPING_METHOD)
class EncodingOption(Enumeration):
ENUM_TYPE = enums.EncodingOption
def __init__(self, value=None):
super(EncodingOption, self).__init__(value, Tags.ENCODING_OPTION)
super(EncodingOption, self).__init__(
enums.EncodingOption, value, Tags.ENCODING_OPTION)
class KeyInformation(Struct):
@ -1182,11 +1179,11 @@ class ExtensionInformation(Struct):
# 3.31, 9.1.3.2.19
class RevocationReasonCode(Enumeration):
ENUM_TYPE = RevocationReasonCodeEnum
def __init__(self, value=RevocationReasonCodeEnum.UNSPECIFIED):
super(RevocationReasonCode, self).__init__(
value=value, tag=Tags.REVOCATION_REASON_CODE)
RevocationReasonCodeEnum, value=value,
tag=Tags.REVOCATION_REASON_CODE)
# 3.31

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import enum as enumeration
import logging
import six
import struct
@ -20,13 +21,10 @@ import sys
import time
from struct import pack, unpack
from enum import Enum
from kmip.core.enums import Types
from kmip.core.enums import Tags
from kmip.core.errors import ErrorStrings
from kmip.core import enums
from kmip.core import errors
from kmip.core import exceptions
from kmip.core import utils
@ -37,7 +35,7 @@ class Base(object):
TYPE_SIZE = 1
LENGTH_SIZE = 4
def __init__(self, tag=Tags.DEFAULT, type=Types.DEFAULT):
def __init__(self, tag=enums.Tags.DEFAULT, type=enums.Types.DEFAULT):
self.tag = tag
self.type = type
self.length = None
@ -54,7 +52,7 @@ class Base(object):
tts = istream.read(self.TAG_SIZE)
tag = unpack('!I', b'\x00' + tts[0:self.TAG_SIZE])[0]
enum_tag = Tags(tag)
enum_tag = enums.Tags(tag)
# Verify that the tag matches for the current object
if enum_tag is not self.tag:
@ -71,7 +69,7 @@ class Base(object):
'{0} bytes'.format(num_bytes))
typ = unpack('!B', tts)[0]
enum_typ = Types(typ)
enum_typ = enums.Types(typ)
if enum_typ is not self.type:
raise errors.ReadValueError(Base.__name__, 'type',
@ -100,10 +98,10 @@ class Base(object):
ostream.write(pack('!I', self.tag.value)[1:])
def write_type(self, ostream):
if type(self.type) is not Types:
if type(self.type) is not enums.Types:
msg = ErrorStrings.BAD_EXP_RECV
raise TypeError(msg.format(Base.__name__, 'type',
Types, type(self.type)))
enums.Types, type(self.type)))
ostream.write(pack('!B', self.type.value))
def write_length(self, ostream):
@ -157,8 +155,8 @@ class Base(object):
class Struct(Base):
def __init__(self, tag=Tags.DEFAULT):
super(Struct, self).__init__(tag, type=Types.STRUCTURE)
def __init__(self, tag=enums.Tags.DEFAULT):
super(Struct, self).__init__(tag, type=enums.Types.STRUCTURE)
# NOTE (peter-hamilton) If seen, should indicate repr needs to be defined
def __repr__(self):
@ -172,8 +170,8 @@ class Integer(Base):
MIN = -2147483648
MAX = 2147483647
def __init__(self, value=None, tag=Tags.DEFAULT, signed=True):
super(Integer, self).__init__(tag, type=Types.INTEGER)
def __init__(self, value=None, tag=enums.Tags.DEFAULT, signed=True):
super(Integer, self).__init__(tag, type=enums.Types.INTEGER)
self.value = value
if self.value is None:
@ -266,7 +264,7 @@ class LongInteger(Base):
MIN = -9223372036854775808
MAX = 9223372036854775807
def __init__(self, value=0, tag=Tags.DEFAULT):
def __init__(self, value=0, tag=enums.Tags.DEFAULT):
"""
Create a LongInteger.
@ -275,7 +273,7 @@ class LongInteger(Base):
tag (Tags): An enumeration defining the tag of the LongInteger.
Optional, defaults to Tags.DEFAULT.
"""
super(LongInteger, self).__init__(tag, type=Types.LONG_INTEGER)
super(LongInteger, self).__init__(tag, type=enums.Types.LONG_INTEGER)
self.value = value
self.length = LongInteger.LENGTH
@ -367,9 +365,10 @@ class BigInteger(Base):
Section 9.1 of the KMIP 1.1 specification.
"""
def __init__(self, value=0, tag=Tags.DEFAULT):
super(BigInteger, self).__init__(tag, type=Types.BIG_INTEGER)
def __init__(self, value=0, tag=enums.Tags.DEFAULT):
super(BigInteger, self).__init__(tag, type=enums.Types.BIG_INTEGER)
self.value = value
self.validate()
def read(self, istream):
@ -486,41 +485,132 @@ class BigInteger(Base):
return NotImplemented
class Enumeration(Integer):
ENUM_TYPE = None
class Enumeration(Base):
"""
An encodeable object representing an enumeration.
An Enumeration is one of the KMIP primitive object types. It is encoded as
an unsigned, big-endian, 32-bit integer. For more information, see Section
9.1 of the KMIP 1.1 specification.
"""
LENGTH = 4
# Bounds for unsigned 32-bit integers
MIN = 0
MAX = 4294967296
def __init__(self, enum, value=None, tag=enums.Tags.DEFAULT):
"""
Create an Enumeration.
Args:
enum (class): The enumeration class of which value is a member
(e.g., Tags). Required.
value (int): The value of the Enumeration, must be an integer
(e.g., Tags.DEFAULT). Optional, defaults to None.
tag (Tags): An enumeration defining the tag of the Enumeration.
Optional, defaults to Tags.DEFAULT.
"""
super(Enumeration, self).__init__(tag, enums.Types.ENUMERATION)
self.value = value
self.enum = enum
self.length = Enumeration.LENGTH
def __init__(self, value=None, tag=Tags.DEFAULT):
self.enum = value
self.validate()
if self.enum is None:
super(Enumeration, self).__init__(None, tag, False)
else:
super(Enumeration, self).__init__(self.enum.value, tag, False)
self.type = Types.ENUMERATION
def read(self, istream):
"""
Read the encoding of the Enumeration from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of an
Enumeration. Usually a BytearrayStream object. Required.
Raises:
InvalidPrimitiveLength: if the Enumeration encoding read in has an
invalid encoded length.
InvalidPaddingBytes: if the Enumeration encoding read in does not
use zeroes for its padding bytes.
"""
super(Enumeration, self).read(istream)
self.enum = self.ENUM_TYPE(self.value)
# Check for a valid length before even trying to parse the value.
if self.length != Enumeration.LENGTH:
raise exceptions.InvalidPrimitiveLength(
"enumeration length must be {0}".format(Enumeration.LENGTH))
# Decode the Enumeration value and the padding bytes.
value = unpack('!I', istream.read(Enumeration.LENGTH))[0]
self.value = self.enum(value)
pad = unpack('!I', istream.read(Enumeration.LENGTH))[0]
# Verify that the padding bytes are zero bytes.
if pad is not 0:
raise exceptions.InvalidPaddingBytes("padding bytes must be zero")
self.validate()
def write(self, ostream):
"""
Write the encoding of the Enumeration to the output stream.
Args:
ostream (stream): A buffer to contain the encoded bytes of an
Enumeration. Usually a BytearrayStream object. Required.
"""
super(Enumeration, self).write(ostream)
ostream.write(pack('!I', self.value.value))
ostream.write(pack('!I', 0))
def validate(self):
self.__validate()
"""
Verify that the value of the Enumeration is valid.
def __validate(self):
if self.enum is not None:
if not isinstance(self.enum, Enum):
raise TypeError("expected {0}, observed {1}".format(
type(self.enum), Enum))
Raises:
TypeError: if the enum is not of type Enum
ValueError: if the value is not of the expected Enum subtype or if
the value cannot be represented by an unsigned 32-bit integer
"""
if not isinstance(self.enum, enumeration.EnumMeta):
raise TypeError(
'enumeration type {0} must be of type EnumMeta'.format(
self.enum))
if self.value is not None:
if not isinstance(self.value, self.enum):
raise TypeError(
'enumeration {0} must be of type {1}'.format(
self.value, self.enum))
if type(self.value.value) not in six.integer_types:
raise TypeError('enumeration value must be an int')
else:
if self.value.value > Enumeration.MAX:
raise ValueError(
'enumeration value greater than accepted max')
elif self.value.value < Enumeration.MIN:
raise ValueError(
'enumeration value less than accepted min')
def __repr__(self):
return "{0}(value={1})".format(type(self).__name__, self.enum)
enum = "enum={0}".format(self.enum.__name__)
value = "value={0}".format(self.value)
tag = "tag={0}".format(self.tag)
return "Enumeration({0}, {1}, {2})".format(enum, value, tag)
def __str__(self):
return "{0}.{1}".format(type(self.enum).__name__, self.enum.name)
return str(self.value)
def __eq__(self, other):
if isinstance(other, Enumeration):
return ((self.enum == other.enum) and (self.value == other.value))
else:
return NotImplemented
def __ne__(self, other):
if isinstance(other, Enumeration):
return not self.__eq__(other)
else:
return NotImplemented
class Boolean(Base):
@ -534,7 +624,7 @@ class Boolean(Base):
"""
LENGTH = 8
def __init__(self, value=True, tag=Tags.DEFAULT):
def __init__(self, value=True, tag=enums.Tags.DEFAULT):
"""
Create a Boolean object.
@ -543,7 +633,7 @@ class Boolean(Base):
tag (Tags): An enumeration defining the tag of the Boolean object.
Optional, defaults to Tags.DEFAULT.
"""
super(Boolean, self).__init__(tag, type=Types.BOOLEAN)
super(Boolean, self).__init__(tag, type=enums.Types.BOOLEAN)
self.logger = logging.getLogger(__name__)
self.value = value
self.length = self.LENGTH
@ -649,8 +739,8 @@ class TextString(Base):
PADDING_SIZE = 8
BYTE_FORMAT = '!c'
def __init__(self, value=None, tag=Tags.DEFAULT):
super(TextString, self).__init__(tag, type=Types.TEXT_STRING)
def __init__(self, value=None, tag=enums.Tags.DEFAULT):
super(TextString, self).__init__(tag, type=enums.Types.TEXT_STRING)
if value is None:
self.value = ''
@ -744,8 +834,8 @@ class ByteString(Base):
PADDING_SIZE = 8
BYTE_FORMAT = '!B'
def __init__(self, value=None, tag=Tags.DEFAULT):
super(ByteString, self).__init__(tag, type=Types.BYTE_STRING)
def __init__(self, value=None, tag=enums.Tags.DEFAULT):
super(ByteString, self).__init__(tag, type=enums.Types.BYTE_STRING)
if value is None:
self.value = bytes()
@ -843,7 +933,7 @@ class DateTime(LongInteger):
more information, see Section 9.1 of the KMIP 1.1 specification.
"""
def __init__(self, value=None, tag=Tags.DEFAULT):
def __init__(self, value=None, tag=enums.Tags.DEFAULT):
"""
Create a DateTime.
@ -857,7 +947,7 @@ class DateTime(LongInteger):
if value is None:
value = int(time.time())
super(DateTime, self).__init__(value, tag)
self.type = Types.DATE_TIME
self.type = enums.Types.DATE_TIME
def __repr__(self):
return "DateTime(value={0}, tag={1})".format(self.value, self.tag)
@ -881,8 +971,8 @@ class Interval(Base):
MIN = 0
MAX = 4294967296
def __init__(self, value=0, tag=Tags.DEFAULT):
super(Interval, self).__init__(tag, type=Types.INTERVAL)
def __init__(self, value=0, tag=enums.Tags.DEFAULT):
super(Interval, self).__init__(tag, type=enums.Types.INTERVAL)
self.value = value
self.length = Interval.LENGTH

View File

@ -235,11 +235,10 @@ class SplitKey(Struct):
value, Tags.SPLIT_KEY_THRESHOLD)
class SplitKeyMethod(Enumeration):
ENUM_TYPE = enums.SplitKeyMethod
def __init__(self, value=None):
super(SplitKey.SplitKeyMethod, self).__init__(
value, Tags.SPLIT_KEY_METHOD)
enums.SplitKeyMethod, value, Tags.SPLIT_KEY_METHOD)
class PrimeFieldSize(BigInteger):
@ -361,11 +360,10 @@ class Template(Struct):
class SecretData(Struct):
class SecretDataType(Enumeration):
ENUM_TYPE = enums.SecretDataType
def __init__(self, value=None):
super(SecretData.SecretDataType, self).__init__(
value, Tags.SECRET_DATA_TYPE)
enums.SecretDataType, value, Tags.SECRET_DATA_TYPE)
def __init__(self,
secret_data_type=None,
@ -411,11 +409,10 @@ class SecretData(Struct):
class OpaqueObject(Struct):
class OpaqueDataType(Enumeration):
ENUM_TYPE = enums.OpaqueDataType
def __init__(self, value=None):
super(OpaqueObject.OpaqueDataType, self).__init__(
value, Tags.OPAQUE_DATA_TYPE)
enums.OpaqueDataType, value, Tags.OPAQUE_DATA_TYPE)
class OpaqueDataValue(ByteString):

View File

@ -102,24 +102,18 @@ class KMIPImpl(KMIP):
bit_length = 256
attributes = template_attribute.attributes
ret_attributes = []
if object_type.enum != OT.SYMMETRIC_KEY:
if object_type.value != OT.SYMMETRIC_KEY:
self.logger.debug('invalid object type')
return self._get_invalid_field_result('invalid object type')
try:
alg_attr =\
self._validate_req_field(attributes,
AT.CRYPTOGRAPHIC_ALGORITHM.value,
(CA.AES.value,),
'unsupported algorithm')
len_attr = self._validate_req_field(attributes,
AT.CRYPTOGRAPHIC_LENGTH.value,
(128, 256, 512),
'unsupported key length',
False)
self._validate_req_field(attributes,
AT.CRYPTOGRAPHIC_USAGE_MASK.value,
(),
'')
alg_attr = self._validate_req_field(
attributes, AT.CRYPTOGRAPHIC_ALGORITHM.value,
(CA.AES,), 'unsupported algorithm')
len_attr = self._validate_req_field(
attributes, AT.CRYPTOGRAPHIC_LENGTH.value,
(128, 256, 512), 'unsupported key length', False)
self._validate_req_field(
attributes, AT.CRYPTOGRAPHIC_USAGE_MASK.value, (), '')
except InvalidFieldException as e:
self.logger.debug('InvalidFieldException raised')
return e.result
@ -158,7 +152,7 @@ class KMIPImpl(KMIP):
if object_type is None:
self.logger.debug('invalid object type')
return self._get_missing_field_result('object type')
if object_type.enum != OT.SYMMETRIC_KEY:
if object_type.value != OT.SYMMETRIC_KEY:
self.logger.debug('invalid object type')
return self._get_invalid_field_result('invalid object type')
if secret is None or not isinstance(secret, SymmetricKey):
@ -173,18 +167,14 @@ class KMIPImpl(KMIP):
self.logger.debug('Verifying all attributes are valid and set')
try:
self._validate_req_field(attributes,
AT.CRYPTOGRAPHIC_ALGORITHM.value,
(CA.AES.value,),
'unsupported algorithm')
self._validate_req_field(attributes,
AT.CRYPTOGRAPHIC_LENGTH.value,
(128, 256, 512),
'unsupported key length')
self._validate_req_field(attributes,
AT.CRYPTOGRAPHIC_USAGE_MASK.value,
(),
'')
self._validate_req_field(
attributes, AT.CRYPTOGRAPHIC_ALGORITHM.value, (CA.AES,),
'unsupported algorithm')
self._validate_req_field(
attributes, AT.CRYPTOGRAPHIC_LENGTH.value, (128, 256, 512),
'unsupported key length')
self._validate_req_field(
attributes, AT.CRYPTOGRAPHIC_USAGE_MASK.value, (), '')
except InvalidFieldException as e:
self.logger.debug('InvalidFieldException raised')
return RegisterResult(e.result.result_status,
@ -220,7 +210,7 @@ class KMIPImpl(KMIP):
if key_format_type is None:
self.logger.debug('key format type is None, setting to raw')
key_format_type = KeyFormatType(KeyFormatTypeEnum.RAW)
if key_format_type.enum != KeyFormatTypeEnum.RAW:
if key_format_type.value != KeyFormatTypeEnum.RAW:
self.logger.debug('key format type is not raw')
reason = ResultReason(ResultReasonEnum.
KEY_FORMAT_TYPE_NOT_SUPPORTED)
@ -370,7 +360,7 @@ class KMIPImpl(KMIP):
self.logger.debug('crypto_alg set on key block')
self.logger.debug('adding crypto algorithm attribute')
at = AT.CRYPTOGRAPHIC_ALGORITHM
alg = key_block.cryptographic_algorithm.enum
alg = key_block.cryptographic_algorithm.value
attributes.append(self.attribute_factory.create_attribute(at, alg))
if key_block.cryptographic_length is not None:
self.logger.debug('crypto_length set on key block')

View File

@ -54,12 +54,12 @@ if __name__ == '__main__':
# Display operation results
logger.info('activate() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
logger.info('activated UUID: {0}'.format(result.uuid.value))
else:
logger.info('activate() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('activate() result message: {0}'.format(
result.result_message.value))

View File

@ -122,16 +122,16 @@ if __name__ == '__main__':
# Display operation results
logger.info('create() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
logger.info('created object type: {0}'.format(
result.object_type.enum))
result.object_type.value))
logger.info('created UUID: {0}'.format(result.uuid.value))
logger.info('created template attribute: {0}'.
format(result.template_attribute))
else:
logger.info('create() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('create() result message: {0}'.format(
result.result_message.value))

View File

@ -125,9 +125,9 @@ if __name__ == '__main__':
# Display operation results
logger.info('create_key_pair() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
logger.info('created private key UUID: {0}'.format(
result.private_key_uuid))
logger.info('created public key UUID: {0}'.format(
@ -144,6 +144,6 @@ if __name__ == '__main__':
logger, result.public_key_template_attribute)
else:
logger.info('create() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('create() result message: {0}'.format(
result.result_message.value))

View File

@ -73,12 +73,12 @@ if __name__ == '__main__':
# Display operation results
logger.info('destroy() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
logger.info('destroyed UUID: {0}'.format(result.uuid.value))
else:
logger.info('destroy() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('destroy() result message: {0}'.format(
result.result_message.value))

View File

@ -49,9 +49,9 @@ if __name__ == '__main__':
# Display operation results
logger.info('discover_versions() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
protocol_versions = result.protocol_versions
if isinstance(protocol_versions, list):
logger.info('number of protocol versions returned: {0}'.format(
@ -63,6 +63,6 @@ if __name__ == '__main__':
logger.info('number of protocol versions returned: 0')
else:
logger.info('discover_versions() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('discover_versions() result message: {0}'.format(
result.result_message.value))

View File

@ -92,16 +92,16 @@ if __name__ == '__main__':
# Display operation results
logger.info('get() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
logger.info('retrieved object type: {0}'.format(
result.object_type.enum))
result.object_type.value))
logger.info('retrieved UUID: {0}'.format(result.uuid.value))
utils.log_secret(logger, result.object_type.enum, result.secret)
utils.log_secret(logger, result.object_type.value, result.secret)
else:
logger.info('get() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('get() result message: {0}'.format(
result.result_message.value))

View File

@ -88,14 +88,14 @@ if __name__ == '__main__':
# Display operation results
logger.info('locate() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
logger.info('located UUIDs:')
for uuid in result.uuids:
logger.info('{0}'.format(uuid))
else:
logger.info('get() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('get() result message: {0}'.format(
result.result_message.value))

View File

@ -69,9 +69,9 @@ if __name__ == '__main__':
# Display operation results
logger.info('query() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
operations = result.operations
object_types = result.object_types
vendor_identification = result.vendor_identification
@ -106,6 +106,6 @@ if __name__ == '__main__':
else:
logger.info('query() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('query() result message: {0}'.format(
result.result_message.value))

View File

@ -73,14 +73,14 @@ if __name__ == '__main__':
# Display operation results
logger.info('register() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
logger.info('registered UUID: {0}'.format(result.uuid.value))
logger.info('registered template attribute: {0}'.
format(result.template_attribute))
else:
logger.info('register() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('register() result message: {0}'.format(
result.result_message.value))

View File

@ -58,12 +58,12 @@ if __name__ == '__main__':
# Display operation results
logger.info('revoke() result status: {0}'.format(
result.result_status.enum))
result.result_status.value))
if result.result_status.enum == ResultStatus.SUCCESS:
if result.result_status.value == ResultStatus.SUCCESS:
logger.info('revoked UUID: {0}'.format(result.unique_identifier.value))
else:
logger.info('revoke() result reason: {0}'.format(
result.result_reason.enum))
result.result_reason.value))
logger.info('revoke() result message: {0}'.format(
result.result_message.value))

View File

@ -170,12 +170,12 @@ class ProxyKmipClient(api.KmipClient):
# Create the symmetric key and handle the results
result = self.proxy.create(enums.ObjectType.SYMMETRIC_KEY, template)
status = result.result_status.enum
status = result.result_status.value
if status == enums.ResultStatus.SUCCESS:
uid = result.uuid.value
return uid
else:
reason = result.result_reason.enum
reason = result.result_reason.value
message = result.result_message.value
raise exceptions.KmipOperationFailure(status, reason, message)
@ -215,13 +215,13 @@ class ProxyKmipClient(api.KmipClient):
# Create the asymmetric key pair and handle the results
result = self.proxy.create_key_pair(common_template_attribute=template)
status = result.result_status.enum
status = result.result_status.value
if status == enums.ResultStatus.SUCCESS:
public_uid = result.public_key_uuid.value
private_uid = result.private_key_uuid.value
return public_uid, private_uid
else:
reason = result.result_reason.enum
reason = result.result_reason.value
message = result.result_message.value
raise exceptions.KmipOperationFailure(status, reason, message)
@ -265,12 +265,12 @@ class ProxyKmipClient(api.KmipClient):
secret = self.object_factory.convert(managed_object)
result = self.proxy.register(object_type, template, secret)
status = result.result_status.enum
status = result.result_status.value
if status == enums.ResultStatus.SUCCESS:
uid = result.uuid.value
return uid
else:
reason = result.result_reason.enum
reason = result.result_reason.value
message = result.result_message.value
raise exceptions.KmipOperationFailure(status, reason, message)
@ -300,12 +300,12 @@ class ProxyKmipClient(api.KmipClient):
# Get the managed object and handle the results
result = self.proxy.get(uid)
status = result.result_status.enum
status = result.result_status.value
if status == enums.ResultStatus.SUCCESS:
managed_object = self.object_factory.convert(result.secret)
return managed_object
else:
reason = result.result_reason.enum
reason = result.result_reason.value
message = result.result_message.value
raise exceptions.KmipOperationFailure(status, reason, message)
@ -333,12 +333,12 @@ class ProxyKmipClient(api.KmipClient):
# Get the list of attribute names for a managed object.
result = self.proxy.get_attribute_list(uid)
status = result.result_status.enum
status = result.result_status.value
if status == enums.ResultStatus.SUCCESS:
attribute_names = sorted(result.names)
return attribute_names
else:
reason = result.result_reason.enum
reason = result.result_reason.value
message = result.result_message.value
raise exceptions.KmipOperationFailure(status, reason, message)
@ -368,11 +368,11 @@ class ProxyKmipClient(api.KmipClient):
# Destroy the managed object and handle the results
result = self.proxy.destroy(uid)
status = result.result_status.enum
status = result.result_status.value
if status == enums.ResultStatus.SUCCESS:
return
else:
reason = result.result_reason.enum
reason = result.result_reason.value
message = result.result_message.value
raise exceptions.KmipOperationFailure(status, reason, message)

View File

@ -72,7 +72,7 @@ class ObjectFactory:
raise TypeError("object type unsupported and cannot be converted")
def _build_pie_certificate(self, cert):
certificate_type = cert.certificate_type.enum
certificate_type = cert.certificate_type.value
value = cert.certificate_value.value
if certificate_type == enums.CertificateTypeEnum.X_509:
@ -81,10 +81,10 @@ class ObjectFactory:
raise TypeError("core certificate type not supported")
def _build_pie_key(self, key, cls):
algorithm = key.key_block.cryptographic_algorithm.enum
algorithm = key.key_block.cryptographic_algorithm.value
length = key.key_block.cryptographic_length.value
value = key.key_block.key_value.key_material.value
format_type = key.key_block.key_format_type.enum
format_type = key.key_block.key_format_type.value
if cls is pobjects.SymmetricKey:
key = cls(algorithm, length, value)
@ -99,13 +99,13 @@ class ObjectFactory:
return cls(algorithm, length, value, format_type)
def _build_pie_secret_data(self, secret):
secret_data_type = secret.secret_data_type.enum
secret_data_type = secret.secret_data_type.value
value = secret.key_block.key_value.key_material.value
return pobjects.SecretData(value, secret_data_type)
def _build_pie_opaque_object(self, obj):
opaque_type = obj.opaque_data_type.enum
opaque_type = obj.opaque_data_type.value
value = obj.opaque_data_value.value
return pobjects.OpaqueObject(value, opaque_type)

View File

@ -475,7 +475,7 @@ class KMIPProxy(KMIP):
def _process_batch_items(self, response):
results = []
for batch_item in response.batch_items:
operation = batch_item.operation.enum
operation = batch_item.operation.value
processor = self._get_batch_item_processor(operation)
result = processor(batch_item)
results.append(result)
@ -597,7 +597,7 @@ class KMIPProxy(KMIP):
if unique_identifier is not None:
uuid = attr.UniqueIdentifier(unique_identifier)
if key_format_type is not None:
kft = get.GetRequestPayload.KeyFormatType(key_format_type.enum)
kft = get.GetRequestPayload.KeyFormatType(key_format_type.value)
if key_compression_type is not None:
kct = key_compression_type
kct = get.GetRequestPayload.KeyCompressionType(kct)

View File

@ -109,16 +109,16 @@ class Processor(object):
response_payload = None
message_extension = None
if result_status.enum is RS.SUCCESS:
if result_status.value is RS.SUCCESS:
response_payload = result[3]
elif result_status.enum is RS.OPERATION_FAILED:
elif result_status.value is RS.OPERATION_FAILED:
failure_occurred = True
result_reason = result[1]
elif result_status.enum is RS.OPERATION_PENDING:
elif result_status.value is RS.OPERATION_PENDING:
# TODO (peter-hamilton) Need to add a way to track async
# TODO (peter-hamilton) operations.
asyn_cv = b'\x00'
elif result_status.enum is RS.OPERATION_UNDONE:
elif result_status.value is RS.OPERATION_UNDONE:
result_reason = result[1]
else:
msg = 'Unrecognized operation result status: {0}'
@ -135,13 +135,13 @@ class Processor(object):
response_batch_items.append(resp_bi)
if failure_occurred:
if batch_error_cont_option.enum is BECO.STOP:
if batch_error_cont_option.value is BECO.STOP:
break
elif batch_error_cont_option.enum is BECO.UNDO:
elif batch_error_cont_option.value is BECO.UNDO:
# TODO (peter-hamilton) Tell client to undo operations.
# TODO (peter-hamilton) Unclear what response should be.
break
elif batch_error_cont_option.enum is BECO.CONTINUE:
elif batch_error_cont_option.value is BECO.CONTINUE:
continue
else:
msg = 'Unrecognized batch error continuation option: {0}'
@ -161,7 +161,7 @@ class Processor(object):
raise NotImplementedError()
def _process_operation(self, operation, payload):
op = operation.enum
op = operation.value
if op is Operation.CREATE:
return self._process_create_request(payload)

View File

@ -170,7 +170,7 @@ class TestIntegration(TestCase):
:param result_status_value: value of the result status
"""
result_status = result.result_status.enum
result_status = result.result_status.value
# Error check the result status type and value
expected = result_status_type
@ -303,7 +303,7 @@ class TestIntegration(TestCase):
result = self.client.discover_versions()
expected = ResultStatus.SUCCESS
observed = result.result_status.enum
observed = result.result_status.value
self.assertEqual(expected, observed)
@ -326,7 +326,7 @@ class TestIntegration(TestCase):
result = self.client.query(query_functions=query_functions)
expected = ResultStatus.SUCCESS
observed = result.result_status.enum
observed = result.result_status.value
self.assertEqual(expected, observed)
@ -338,14 +338,14 @@ class TestIntegration(TestCase):
result = self._create_symmetric_key(key_name=key_name)
self._check_result_status(result, ResultStatus, ResultStatus.SUCCESS)
self._check_object_type(result.object_type.enum, ObjectType,
self._check_object_type(result.object_type.value, ObjectType,
ObjectType.SYMMETRIC_KEY)
self._check_uuid(result.uuid.value, str)
result = self.client.get(uuid=result.uuid.value, credential=None)
self._check_result_status(result, ResultStatus, ResultStatus.SUCCESS)
self._check_object_type(result.object_type.enum, ObjectType,
self._check_object_type(result.object_type.value, ObjectType,
ObjectType.SYMMETRIC_KEY)
self._check_uuid(result.uuid.value, str)
@ -370,12 +370,12 @@ class TestIntegration(TestCase):
ResultStatus.OPERATION_FAILED)
expected = ResultReason
observed = type(result.result_reason.enum)
observed = type(result.result_reason.value)
self.assertEqual(expected, observed)
expected = ResultReason.ITEM_NOT_FOUND
observed = result.result_reason.enum
observed = result.result_reason.value
self.assertEqual(expected, observed)
@ -434,7 +434,7 @@ class TestIntegration(TestCase):
result = self.client.get(uuid=uuid, credential=None)
self._check_result_status(result, ResultStatus, ResultStatus.SUCCESS)
self._check_object_type(result.object_type.enum, ObjectType,
self._check_object_type(result.object_type.value, ObjectType,
ObjectType.SYMMETRIC_KEY)
self._check_uuid(result.uuid.value, str)
@ -469,12 +469,12 @@ class TestIntegration(TestCase):
ResultStatus.OPERATION_FAILED)
expected = ResultReason
observed = type(result.result_reason.enum)
observed = type(result.result_reason.value)
self.assertEqual(expected, observed)
expected = ResultReason.ITEM_NOT_FOUND
observed = result.result_reason.enum
observed = result.result_reason.value
self.assertEqual(expected, observed)
@ -500,13 +500,13 @@ class TestIntegration(TestCase):
self._check_result_status(priv_key_result, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(priv_key_result.object_type.enum, ObjectType,
self._check_object_type(priv_key_result.object_type.value, ObjectType,
ObjectType.PRIVATE_KEY)
self._check_uuid(priv_key_result.uuid.value, str)
self._check_result_status(pub_key_result, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(pub_key_result.object_type.enum, ObjectType,
self._check_object_type(pub_key_result.object_type.value, ObjectType,
ObjectType.PUBLIC_KEY)
self._check_uuid(pub_key_result.uuid.value, str)
@ -552,8 +552,8 @@ class TestIntegration(TestCase):
ResultStatus.OPERATION_FAILED)
expected = ResultReason
observed_priv = type(priv_key_destroyed_result.result_reason.enum)
observed_pub = type(pub_key_destroyed_result.result_reason.enum)
observed_priv = type(priv_key_destroyed_result.result_reason.value)
observed_pub = type(pub_key_destroyed_result.result_reason.value)
self.assertEqual(expected, observed_priv)
self.assertEqual(expected, observed_pub)
@ -664,7 +664,7 @@ class TestIntegration(TestCase):
self._check_result_status(priv_key_result, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(priv_key_result.object_type.enum, ObjectType,
self._check_object_type(priv_key_result.object_type.value, ObjectType,
ObjectType.PRIVATE_KEY)
self._check_uuid(priv_key_result.uuid.value, str)
@ -704,7 +704,7 @@ class TestIntegration(TestCase):
ResultStatus.OPERATION_FAILED)
expected = ResultReason
priv_observed = type(priv_key_destroyed_result.result_reason.enum)
priv_observed = type(priv_key_destroyed_result.result_reason.value)
self.assertEqual(expected, priv_observed)
@ -771,7 +771,7 @@ class TestIntegration(TestCase):
self._check_result_status(pub_key_result, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(pub_key_result.object_type.enum, ObjectType,
self._check_object_type(pub_key_result.object_type.value, ObjectType,
ObjectType.PUBLIC_KEY)
self._check_uuid(pub_key_result.uuid.value, str)
@ -801,7 +801,7 @@ class TestIntegration(TestCase):
self._check_result_status(pub_key_destroyed_result, ResultStatus,
ResultStatus.OPERATION_FAILED)
expected = ResultReason
pub_observed = type(pub_key_destroyed_result.result_reason.enum)
pub_observed = type(pub_key_destroyed_result.result_reason.value)
self.assertEqual(expected, pub_observed)
@ -911,7 +911,7 @@ class TestIntegration(TestCase):
self._check_result_status(cert_result, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(cert_result.object_type.enum, ObjectType,
self._check_object_type(cert_result.object_type.value, ObjectType,
ObjectType.CERTIFICATE)
self._check_uuid(cert_result.uuid.value, str)
@ -947,7 +947,7 @@ class TestIntegration(TestCase):
ResultStatus.OPERATION_FAILED)
expected = ResultReason
cert_observed = type(cert_result_destroyed_result.result_reason.enum)
cert_observed = type(cert_result_destroyed_result.result_reason.value)
self.assertEqual(expected, cert_observed)
@ -1018,7 +1018,7 @@ class TestIntegration(TestCase):
self._check_result_status(pass_result, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(pass_result.object_type.enum, ObjectType,
self._check_object_type(pass_result.object_type.value, ObjectType,
ObjectType.SECRET_DATA)
self._check_uuid(pass_result.uuid.value, str)
@ -1055,7 +1055,7 @@ class TestIntegration(TestCase):
ResultStatus.OPERATION_FAILED)
expected = ResultReason
pass_observed = type(pass_result_destroyed_result.result_reason.enum)
pass_observed = type(pass_result_destroyed_result.result_reason.value)
self.assertEqual(expected, pass_observed)
@ -1113,8 +1113,9 @@ class TestIntegration(TestCase):
self._check_result_status(opaque_obj_result, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(opaque_obj_result.object_type.enum, ObjectType,
ObjectType.OPAQUE_DATA)
self._check_object_type(
opaque_obj_result.object_type.value, ObjectType,
ObjectType.OPAQUE_DATA)
self._check_uuid(opaque_obj_result.uuid.value, str)
@ -1149,7 +1150,7 @@ class TestIntegration(TestCase):
expected = ResultReason
opaque_obj_observed = \
type(opaque_obj_result_destroyed_result.result_reason.enum)
type(opaque_obj_result_destroyed_result.result_reason.value)
self.assertEqual(expected, opaque_obj_observed)

View File

@ -102,9 +102,9 @@ class TestKMIPClientIntegration(TestCase):
def test_create(self):
result = self._create_symmetric_key()
self._check_result_status(result.result_status.enum, ResultStatus,
self._check_result_status(result.result_status.value, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(result.object_type.enum, ObjectType,
self._check_object_type(result.object_type.value, ObjectType,
ObjectType.SYMMETRIC_KEY)
self._check_uuid(result.uuid.value, str)
@ -126,9 +126,9 @@ class TestKMIPClientIntegration(TestCase):
result = self.client.get(uuid=uuid, credential=credential)
self._check_result_status(result.result_status.enum, ResultStatus,
self._check_result_status(result.result_status.value, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(result.object_type.enum, ObjectType,
self._check_object_type(result.object_type.value, ObjectType,
ObjectType.SYMMETRIC_KEY)
self._check_uuid(result.uuid.value, str)
@ -151,9 +151,9 @@ class TestKMIPClientIntegration(TestCase):
# Verify the secret was created
result = self.client.get(uuid=uuid, credential=credential)
self._check_result_status(result.result_status.enum, ResultStatus,
self._check_result_status(result.result_status.value, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(result.object_type.enum, ObjectType,
self._check_object_type(result.object_type.value, ObjectType,
ObjectType.SYMMETRIC_KEY)
self._check_uuid(result.uuid.value, str)
@ -166,24 +166,24 @@ class TestKMIPClientIntegration(TestCase):
# Destroy the SYMMETRIC_KEY object
result = self.client.destroy(uuid, credential)
self._check_result_status(result.result_status.enum, ResultStatus,
self._check_result_status(result.result_status.value, ResultStatus,
ResultStatus.SUCCESS)
self._check_uuid(result.uuid.value, str)
# Verify the secret was destroyed
result = self.client.get(uuid=uuid, credential=credential)
self._check_result_status(result.result_status.enum, ResultStatus,
self._check_result_status(result.result_status.value, ResultStatus,
ResultStatus.OPERATION_FAILED)
expected = ResultReason
observed = type(result.result_reason.enum)
observed = type(result.result_reason.value)
message = utils.build_er_error(result.result_reason.__class__, 'type',
expected, observed)
self.assertEqual(expected, observed, message)
expected = ResultReason.ITEM_NOT_FOUND
observed = result.result_reason.enum
observed = result.result_reason.value
message = utils.build_er_error(result.result_reason.__class__,
'value', expected, observed)
self.assertEqual(expected, observed, message)
@ -228,7 +228,7 @@ class TestKMIPClientIntegration(TestCase):
result = self.client.register(object_type, template_attribute, secret,
credential)
self._check_result_status(result.result_status.enum, ResultStatus,
self._check_result_status(result.result_status.value, ResultStatus,
ResultStatus.SUCCESS)
self._check_uuid(result.uuid.value, str)
@ -241,9 +241,9 @@ class TestKMIPClientIntegration(TestCase):
uuid = result.uuid.value
result = self.client.get(uuid=uuid, credential=credential)
self._check_result_status(result.result_status.enum, ResultStatus,
self._check_result_status(result.result_status.value, ResultStatus,
ResultStatus.SUCCESS)
self._check_object_type(result.object_type.enum, ObjectType,
self._check_object_type(result.object_type.value, ObjectType,
ObjectType.SYMMETRIC_KEY)
self._check_uuid(result.uuid.value, str)

View File

@ -154,8 +154,8 @@ class TestHashingAlgorithm(TestCase):
hashing_algorithm = HashingAlgorithm(value)
msg = "expected {0}, observed {1}".format(
value, hashing_algorithm.enum)
self.assertEqual(value, hashing_algorithm.enum, msg)
value, hashing_algorithm.value)
self.assertEqual(value, hashing_algorithm.value, msg)
else:
self.assertRaises(TypeError, HashingAlgorithm, value)
@ -205,8 +205,8 @@ class TestCertificateType(TestCase):
certificate_type = CertificateType(value)
msg = "expected {0}, observed {1}".format(
value, certificate_type.enum)
self.assertEqual(value, certificate_type.enum, msg)
value, certificate_type.value)
self.assertEqual(value, certificate_type.value, msg)
else:
self.assertRaises(TypeError, CertificateType, value)

View File

@ -337,42 +337,26 @@ class TestDigest(TestCase):
def test_repr(self):
"""
Test that the representation of a Digest object with data is formatted
properly and can be used by eval to create a new Digest object
identical to the original.
properly.
"""
hashing_algorithm = HashingAlgorithm(HashingAlgorithmEnum.MD5)
digest_value = DigestValue(b'\x00\x01\x02\x03')
key_format_type = KeyFormatType(KeyFormatTypeEnum.RAW)
digest = Digest(
hashing_algorithm=HashingAlgorithm(HashingAlgorithmEnum.MD5),
digest_value=DigestValue(b'\x00\x01\x02\x03'),
key_format_type=KeyFormatType(KeyFormatTypeEnum.RAW))
byte_value = b'\x00\x01\x02\x03'
hashing_algorithm=hashing_algorithm,
digest_value=digest_value,
key_format_type=key_format_type)
expected = "Digest("
expected += "hashing_algorithm=HashingAlgorithm("
expected += "value=HashingAlgorithm.MD5), "
expected += "digest_value=DigestValue("
expected += "value={0}), ".format(repr(byte_value))
expected += "key_format_type=KeyFormatType("
expected += "value=KeyFormatType.RAW))"
hashing_algorithm = "hashing_algorithm={0}".format(
repr(hashing_algorithm))
digest_value = "digest_value={0}".format(repr(digest_value))
key_format_type = "key_format_type={0}".format(repr(key_format_type))
expected = "Digest({0}, {1}, {2})".format(
hashing_algorithm, digest_value, key_format_type)
observed = repr(digest)
msg = "expected {0}, observed {1}".format(expected, observed)
self.assertEqual(expected, observed, msg)
# Instead of using eval(repr(digest)), we need to use a manual string,
# eval(manual), due to the name collisions of the HashingAlgorithm
# and KeyFormatType objects and enumerations.
manual = "Digest("
manual += "hashing_algorithm=HashingAlgorithm("
manual += "value=HashingAlgorithmEnum.MD5), "
manual += "digest_value=DigestValue("
manual += "value={0}), ".format(repr(byte_value))
manual += "key_format_type=KeyFormatType("
manual += "value=KeyFormatTypeEnum.RAW))"
expected = digest
observed = eval(manual)
msg = "expected {0}, observed {1}".format(expected, observed)
msg = "expected:\n{0},\nobserved:\n{1}".format(expected, observed)
self.assertEqual(expected, observed, msg)
def _test_str(self, value, expected):

View File

@ -226,9 +226,9 @@ class TestRequestMessage(TestCase):
msg.format(contents.Operation,
type(operation)))
msg = "Bad operation value: expected {0}, received {1}"
self.assertEqual(enums.Operation.CREATE, operation.enum,
self.assertEqual(enums.Operation.CREATE, operation.value,
msg.format(enums.Operation.CREATE,
operation.enum))
operation.value))
request_payload = batch_item.request_payload
msg = "Bad request payload type: expected {0}, received {1}"
@ -243,9 +243,9 @@ class TestRequestMessage(TestCase):
msg.format(attr.ObjectType,
type(object_type)))
msg = "Bad object type value: expected {0}, received {1}"
self.assertEqual(enums.ObjectType.SYMMETRIC_KEY, object_type.enum,
self.assertEqual(enums.ObjectType.SYMMETRIC_KEY, object_type.value,
msg.format(enums.ObjectType.SYMMETRIC_KEY,
object_type.enum))
object_type.value))
template_attribute = request_payload.template_attribute
msg = "Bad template attribute type: expected {0}, received {1}"
@ -284,11 +284,11 @@ class TestRequestMessage(TestCase):
self.assertIsInstance(attribute_value, exp_type,
self.msg.format('attribute value', 'type',
exp_type, rcv_type))
self.assertEquals(attribute_value.enum,
self.assertEquals(attribute_value.value,
enums.CryptographicAlgorithm.AES,
self.msg.format('cryptographic algorithm', 'value',
enums.CryptographicAlgorithm.AES,
attribute_value.enum))
attribute_value.value))
attribute_b = attributes[1]
self.assertIsInstance(attribute_b, objects.Attribute,
@ -455,9 +455,9 @@ class TestRequestMessage(TestCase):
msg.format(contents.Operation,
type(operation)))
msg = "Bad operation value: expected {0}, received {1}"
self.assertEqual(enums.Operation.GET, operation.enum,
self.assertEqual(enums.Operation.GET, operation.value,
msg.format(enums.Operation.GET,
operation.enum))
operation.value))
request_payload = batch_item.request_payload
msg = "Bad request payload type: expected {0}, received {1}"
@ -572,7 +572,7 @@ class TestRequestMessage(TestCase):
type(operation)))
msg = "Bad operation value: expected {0}, received {1}"
exp_value = enums.Operation.DESTROY
rcv_value = operation.enum
rcv_value = operation.value
self.assertEqual(exp_value, rcv_value,
msg.format(exp_value, rcv_value))
@ -689,7 +689,7 @@ class TestRequestMessage(TestCase):
type(operation)))
msg = "Bad operation value: expected {0}, received {1}"
exp_value = enums.Operation.REGISTER
rcv_value = operation.enum
rcv_value = operation.value
self.assertEqual(exp_value, rcv_value,
msg.format(exp_value, rcv_value))
@ -707,7 +707,7 @@ class TestRequestMessage(TestCase):
type(object_type)))
msg = "Bad object type value: expected {0}, received {1}"
exp_value = enums.ObjectType.TEMPLATE
rcv_value = object_type.enum
rcv_value = object_type.value
self.assertEqual(exp_value, rcv_value,
msg.format(exp_value, rcv_value))
@ -888,7 +888,7 @@ class TestRequestMessage(TestCase):
msg = "Bad operation value: expected {0}, received {1}"
exp_value = enums.Operation.LOCATE
rcv_value = operation.enum
rcv_value = operation.value
self.assertEqual(exp_value, rcv_value,
msg.format(exp_value, rcv_value))
@ -932,10 +932,12 @@ class TestRequestMessage(TestCase):
self.assertIsInstance(attribute_value, exp_type,
self.msg.format('attribute value', 'type',
exp_type, rcv_type))
self.assertEquals(attribute_value.enum, enums.ObjectType.SYMMETRIC_KEY,
self.msg.format('ObjectType', 'value',
enums.ObjectType.SYMMETRIC_KEY,
attribute_value.enum))
self.assertEquals(
attribute_value.value,
enums.ObjectType.SYMMETRIC_KEY,
self.msg.format(
'ObjectType', 'value', enums.ObjectType.SYMMETRIC_KEY,
attribute_value.value))
attribute_b = attributes[1]
self.assertIsInstance(attribute_b, objects.Attribute,
@ -1125,20 +1127,20 @@ class TestResponseMessage(TestCase):
self.msg.format('operation', 'type',
contents.Operation,
type(operation)))
self.assertEqual(enums.Operation.CREATE, operation.enum,
self.assertEqual(enums.Operation.CREATE, operation.value,
self.msg.format('operation', 'value',
enums.Operation.CREATE,
operation.enum))
operation.value))
result_status = batch_item.result_status
self.assertIsInstance(result_status, contents.ResultStatus,
self.msg.format('result status', 'type',
contents.ResultStatus,
type(result_status)))
self.assertEqual(enums.ResultStatus.SUCCESS, result_status.enum,
self.assertEqual(enums.ResultStatus.SUCCESS, result_status.value,
self.msg.format('result status', 'value',
enums.ResultStatus.SUCCESS,
result_status.enum))
result_status.value))
response_payload = batch_item.response_payload
exp_type = create.CreateResponsePayload
@ -1152,10 +1154,10 @@ class TestResponseMessage(TestCase):
self.msg.format('object type', 'type',
attr.ObjectType,
type(object_type)))
self.assertEqual(enums.ObjectType.SYMMETRIC_KEY, object_type.enum,
self.assertEqual(enums.ObjectType.SYMMETRIC_KEY, object_type.value,
self.msg.format('object type', 'value',
enums.ObjectType.SYMMETRIC_KEY,
object_type.enum))
object_type.value))
unique_identifier = response_payload.unique_identifier
value = 'fb4b5b9c-6188-4c63-8142-fe9c328129fc'
@ -1274,20 +1276,20 @@ class TestResponseMessage(TestCase):
self.msg.format('operation', 'type',
contents.Operation,
type(operation)))
self.assertEqual(enums.Operation.GET, operation.enum,
self.assertEqual(enums.Operation.GET, operation.value,
self.msg.format('operation', 'value',
enums.Operation.GET,
operation.enum))
operation.value))
result_status = batch_item.result_status
self.assertIsInstance(result_status, contents.ResultStatus,
self.msg.format('result status', 'type',
contents.ResultStatus,
type(result_status)))
self.assertEqual(enums.ResultStatus.SUCCESS, result_status.enum,
self.assertEqual(enums.ResultStatus.SUCCESS, result_status.value,
self.msg.format('result status', 'value',
enums.ResultStatus.SUCCESS,
result_status.enum))
result_status.value))
response_payload = batch_item.response_payload
exp_type = get.GetResponsePayload
@ -1301,10 +1303,10 @@ class TestResponseMessage(TestCase):
self.msg.format('object type', 'type',
attr.ObjectType,
type(object_type)))
self.assertEqual(enums.ObjectType.SYMMETRIC_KEY, object_type.enum,
self.assertEqual(enums.ObjectType.SYMMETRIC_KEY, object_type.value,
self.msg.format('object type', 'value',
enums.ObjectType.SYMMETRIC_KEY,
object_type.enum))
object_type.value))
unique_identifier = response_payload.unique_identifier
value = '49a1ca88-6bea-4fb2-b450-7e58802c3038'
@ -1360,7 +1362,7 @@ class TestResponseMessage(TestCase):
self.msg.format('cryptographic_algorithm',
'type', exp_type, rcv_type))
exp = enums.CryptographicAlgorithm.TRIPLE_DES
obs = cryptographic_algorithm.enum
obs = cryptographic_algorithm.value
self.assertEqual(exp, obs,
self.msg.format('cryptographic_algorithm',
'value', exp, obs))
@ -1517,7 +1519,7 @@ class TestResponseMessage(TestCase):
type(operation)))
msg = "Bad operation value: expected {0}, received {1}"
exp_value = enums.Operation.DESTROY
rcv_value = operation.enum
rcv_value = operation.value
self.assertEqual(exp_value, rcv_value,
msg.format(exp_value, rcv_value))
@ -1526,10 +1528,10 @@ class TestResponseMessage(TestCase):
self.msg.format('result status', 'type',
contents.ResultStatus,
type(result_status)))
self.assertEqual(enums.ResultStatus.SUCCESS, result_status.enum,
self.assertEqual(enums.ResultStatus.SUCCESS, result_status.value,
self.msg.format('result status', 'value',
enums.ResultStatus.SUCCESS,
result_status.enum))
result_status.value))
response_payload = batch_item.response_payload
msg = "Bad response payload type: expected {0}, received {1}"
@ -1660,7 +1662,7 @@ class TestResponseMessage(TestCase):
type(operation)))
msg = "Bad operation value: expected {0}, received {1}"
exp_value = enums.Operation.REGISTER
rcv_value = operation.enum
rcv_value = operation.value
self.assertEqual(exp_value, rcv_value,
msg.format(exp_value, rcv_value))
@ -1669,10 +1671,10 @@ class TestResponseMessage(TestCase):
self.msg.format('result status', 'type',
contents.ResultStatus,
type(result_status)))
self.assertEqual(enums.ResultStatus.SUCCESS, result_status.enum,
self.assertEqual(enums.ResultStatus.SUCCESS, result_status.value,
self.msg.format('result status', 'value',
enums.ResultStatus.SUCCESS,
result_status.enum))
result_status.value))
response_payload = batch_item.response_payload
msg = "Bad response payload type: expected {0}, received {1}"

View File

@ -89,8 +89,8 @@ class TestQueryFunction(TestCase):
query_function = QueryFunction(value)
msg = "expected {0}, observed {1}".format(
value, query_function.enum)
self.assertEqual(value, query_function.enum, msg)
value, query_function.value)
self.assertEqual(value, query_function.value, msg)
else:
self.assertRaises(TypeError, QueryFunction, value)
@ -184,8 +184,8 @@ class TestKeyFormatType(TestCase):
key_format_type = KeyFormatType(value)
msg = "expected {0}, observed {1}".format(
value, key_format_type.enum)
self.assertEqual(value, key_format_type.enum, msg)
value, key_format_type.value)
self.assertEqual(value, key_format_type.value, msg)
else:
self.assertRaises(TypeError, KeyFormatType, value)

View File

@ -13,119 +13,271 @@
# License for the specific language governing permissions and limitations
# under the License.
import enum as enumeration
import testtools
from kmip.core import enums
from kmip.core import errors
from kmip.core import exceptions
from kmip.core import primitives
from kmip.core import utils
# flake8: noqa
class DummyEnumeration(enumeration.Enum):
SMALL = primitives.Enumeration.MIN
TOO_SMALL = primitives.Enumeration.MIN - 1
LARGE = primitives.Enumeration.MAX
TOO_LARGE = primitives.Enumeration.MAX + 1
INVALID = 'invalid'
class TestEnumeration(testtools.TestCase):
def setUp(self):
super(TestEnumeration, self).setUp()
self.stream = utils.BytearrayStream()
primitives.Enumeration.ENUM_TYPE = enums.Types
self.bad_type = errors.ErrorStrings.BAD_EXP_RECV.format(
'primitives.Enumeration.{0}', 'type', '{1}', '{2}')
self.bad_value = errors.ErrorStrings.BAD_EXP_RECV.format(
'primitives.Enumeration.{0}', 'value', '{1}', '{2}')
self.bad_write = errors.ErrorStrings.BAD_EXP_RECV.format(
'primitives.Enumeration', 'write', '{0} bytes', '{1} bytes')
self.bad_encoding = errors.ErrorStrings.BAD_ENCODING.format(
'primitives.Enumeration', 'write')
self.encoding = (
b'\x42\x00\x00\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00'
b'\x00')
self.encoding_bad_length = (
b'\x42\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
b'\x00')
self.encoding_bad_padding = (
b'\x42\x00\x00\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00'
b'\xFF')
def tearDown(self):
super(TestEnumeration, self).tearDown()
def test_init(self):
e = primitives.Enumeration(enums.Types.DEFAULT)
self.assertIsInstance(e.enum, enums.Types,
self.bad_type.format('enum', enums.Types,
type(e.enum)))
self.assertEqual(
enums.Types.DEFAULT, e.enum,
self.bad_value.format('enum', enums.Types.DEFAULT, e.enum))
default = enums.Types.DEFAULT
self.assertEqual(default.value, e.value,
self.bad_value.format('value', default.value,
e.value))
"""
Test that an Enumeration can be instantiated.
"""
enum = primitives.Enumeration(
DummyEnumeration, DummyEnumeration.SMALL,
enums.Tags.ACTIVATION_DATE)
self.assertEqual(DummyEnumeration, enum.enum)
self.assertEqual(DummyEnumeration.SMALL, enum.value)
self.assertEqual(enums.Tags.ACTIVATION_DATE, enum.tag)
def test_init_unset(self):
e = primitives.Enumeration()
"""
Test that an Enumeration can be instantiated with no input.
"""
enum = primitives.Enumeration(DummyEnumeration)
self.assertEqual(DummyEnumeration, enum.enum)
self.assertEqual(None, enum.value)
self.assertEqual(enums.Tags.DEFAULT, enum.tag)
self.assertEqual(None, e.enum,
self.bad_value.format('enum', None, e.enum))
self.assertEqual(0, e.value,
self.bad_value.format('value', 0, e.value))
def test_validate_on_invalid_enum_type(self):
"""
Test that a TypeError is thrown on input of invalid enum type
(e.g., str).
"""
args = ['invalid']
kwargs = {'value': enums.Tags.DEFAULT}
self.assertRaises(TypeError, primitives.Enumeration, *args, **kwargs)
def test_validate_on_valid(self):
e = primitives.Enumeration()
e.enum = enums.Types.DEFAULT
def test_validate_on_invalid_enum_value_type(self):
"""
Test that a TypeError is thrown on input of invalid enum value type.
"""
args = [DummyEnumeration]
kwargs = {'value': enums.Tags.DEFAULT}
self.assertRaises(TypeError, primitives.Enumeration, *args, **kwargs)
# Check no exception thrown
e.validate()
def test_validate_on_invalid_value_type(self):
"""
Test that a TypeError is thrown on input of invalid value type
(e.g., str).
"""
args = [DummyEnumeration]
kwargs = {'value': DummyEnumeration.INVALID}
self.assertRaises(TypeError, primitives.Enumeration, *args, **kwargs)
def test_validate_on_valid_unset(self):
e = primitives.Enumeration()
def test_validate_on_invalid_value_too_big(self):
"""
Test that a ValueError is thrown on input that is too large.
"""
args = [DummyEnumeration]
kwargs = {'value': DummyEnumeration.TOO_LARGE}
self.assertRaises(ValueError, primitives.Enumeration, *args, **kwargs)
# Check no exception thrown
e.validate()
def test_validate_on_invalid_type(self):
e = primitives.Enumeration()
e.enum = 0
self.assertRaises(TypeError, e.validate)
def test_validate_on_invalid_value_too_small(self):
"""
Test that a ValueError is thrown on input that is too small.
"""
args = [DummyEnumeration]
kwargs = {'value': DummyEnumeration.TOO_SMALL}
self.assertRaises(ValueError, primitives.Enumeration, *args, **kwargs)
def test_read(self):
encoding = (
b'\x42\x00\x00\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00'
b'\x00')
self.stream = utils.BytearrayStream(encoding)
e = primitives.Enumeration()
e.read(self.stream)
"""
Test that an Enumeration can be read from a byte stream.
"""
stream = utils.BytearrayStream(self.encoding)
enum = primitives.Enumeration(DummyEnumeration)
enum.read(stream)
self.assertEqual(DummyEnumeration.SMALL, enum.value)
self.assertIsInstance(e.enum, enums.Types,
self.bad_type.format('enum', enums.Types,
type(e.enum)))
self.assertEqual(enums.Types.DEFAULT, e.enum,
self.bad_value.format('enum', enums.Types.DEFAULT,
type(e.enum)))
default = enums.Types.DEFAULT
self.assertEqual(default.value, e.value,
self.bad_value.format('value', default.value,
e.value))
def test_read_on_invalid_length(self):
"""
Test that an InvalidPrimitiveLength exception is thrown when attempting
to decode an Enumeration with an invalid length.
"""
stream = utils.BytearrayStream(self.encoding_bad_length)
enum = primitives.Enumeration(enums.Tags)
self.assertRaises(exceptions.InvalidPrimitiveLength, enum.read, stream)
def test_read_on_invalid_padding(self):
"""
Test that an InvalidPrimitiveLength exception is thrown when attempting
to decode an Enumeration with invalid padding bytes.
"""
stream = utils.BytearrayStream(self.encoding_bad_padding)
enum = primitives.Enumeration(enums.Types)
self.assertRaises(exceptions.InvalidPaddingBytes, enum.read, stream)
def test_write(self):
encoding = (
b'\x42\x00\x00\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00'
b'\x00')
e = primitives.Enumeration(enums.Types.DEFAULT)
e.write(self.stream)
result = self.stream.read()
len_exp = len(encoding)
len_rcv = len(result)
self.assertEqual(len_exp, len_rcv, self.bad_write.format(len_exp,
len_rcv))
self.assertEqual(encoding, result, self.bad_encoding)
def test_write_unsigned(self):
"""
Test that a large primitives.Enumeration value is written correctly as
an unsigned integer.
Test that an Enumeration can be written to a byte stream.
"""
encoding = (
b'\x42\x00\x00\x05\x00\x00\x00\x04\x80\x00\x00\x00\x00\x00\x00'
b'\x00')
e = primitives.Enumeration(enums.OpaqueDataType.NONE)
e.write(self.stream)
result = self.stream.read()
stream = utils.BytearrayStream()
enum = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
enum.write(stream)
self.assertEqual(len(encoding), len(result))
self.assertEqual(encoding, result)
result = stream.read()
self.assertEqual(len(self.encoding), len(result))
self.assertEqual(self.encoding, result)
def test_repr(self):
"""
Test that the representation of an Enumeration is formatted properly.
"""
enum = "enum={0}".format(DummyEnumeration.__name__)
value = "value={0}".format(DummyEnumeration.SMALL)
tag = "tag={0}".format(enums.Tags.DEFAULT)
r = "Enumeration({0}, {1}, {2})".format(enum, value, tag)
enum = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
self.assertEqual(r, repr(enum))
def test_str(self):
"""
Test that the string representation of an Enumeration is formatted
properly.
"""
enum = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
self.assertEqual(str(DummyEnumeration.SMALL), str(enum.value))
def test_equal_on_equal(self):
"""
Test that the equality operator returns True when comparing two
Enumerations.
"""
a = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
b = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
self.assertTrue(a == b)
self.assertTrue(b == a)
def test_equal_on_equal_and_empty(self):
"""
Test that the equality operator returns True when comparing two
Enumerations.
"""
a = primitives.Enumeration(DummyEnumeration)
b = primitives.Enumeration(DummyEnumeration)
self.assertTrue(a == b)
self.assertTrue(b == a)
def test_equal_on_not_equal(self):
"""
Test that the equality operator returns False when comparing two
Enumerations with different values.
"""
a = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
b = primitives.Enumeration(DummyEnumeration, DummyEnumeration.LARGE)
self.assertFalse(a == b)
self.assertFalse(b == a)
def test_equal_on_not_equal_enum(self):
"""
Test that the equality operator returns False when comparing two
Enumerations with different enum types.
"""
a = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
b = primitives.Enumeration(enums.Tags, enums.Tags.DEFAULT)
self.assertFalse(a == b)
self.assertFalse(b == a)
def test_equal_on_type_mismatch(self):
"""
Test that the equality operator returns False when comparing a
Enumeration to a non-Enumeration object.
"""
a = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
b = 'invalid'
self.assertFalse(a == b)
self.assertFalse(b == a)
def test_not_equal_on_equal(self):
"""
Test that the inequality operator returns False when comparing
two Enumerations with the same values.
"""
a = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
b = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
self.assertFalse(a != b)
self.assertFalse(b != a)
def test_not_equal_on_equal_and_empty(self):
"""
Test that the inequality operator returns False when comparing
two Enumerations.
"""
a = primitives.Enumeration(DummyEnumeration)
b = primitives.Enumeration(DummyEnumeration)
self.assertFalse(a != b)
self.assertFalse(b != a)
def test_not_equal_on_not_equal(self):
"""
Test that the inequality operator returns True when comparing two
Enumerations with different values.
"""
a = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
b = primitives.Enumeration(DummyEnumeration, DummyEnumeration.LARGE)
self.assertTrue(a != b)
self.assertTrue(b != a)
def test_not_equal_on_not_equal_enum(self):
"""
Test that the equality operator returns True when comparing two
Enumerations with different enum types.
"""
a = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
b = primitives.Enumeration(enums.Tags, enums.Tags.DEFAULT)
self.assertTrue(a != b)
self.assertTrue(b != a)
def test_not_equal_on_type_mismatch(self):
"""
Test that the inequality operator returns True when comparing a
Enumeration to a non-Enumeration object.
"""
a = primitives.Enumeration(DummyEnumeration, DummyEnumeration.SMALL)
b = 'invalid'
self.assertTrue(a != b)
self.assertTrue(b != a)

View File

@ -66,7 +66,7 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.create(obj_type, template_attribute)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
def test_create_no_length(self):
@ -76,7 +76,7 @@ class TestKMIPServer(TestCase):
res = self.kmip.create(obj_type, template_attribute)
self.assertNotEqual(None, res, 'result is None')
attrs = res.template_attribute.attributes
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
self.assertTrue(self._check_attr_exists(attributes[2], attrs),
'length attribute not returned')
@ -87,8 +87,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.create(obj_type, template_attribute)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.OPERATION_FAILED, res.result_status.enum,
'result status did not return failed')
self.assertEqual(
ResultStatus.OPERATION_FAILED,
res.result_status.value,
'result status did not return failed')
def test_create_no_usage_mask(self):
obj_type = ObjectType(ObjectTypeEnum.SYMMETRIC_KEY)
@ -96,8 +98,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.create(obj_type, template_attribute)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.OPERATION_FAILED, res.result_status.enum,
'result status did not return failed')
self.assertEqual(
ResultStatus.OPERATION_FAILED,
res.result_status.value,
'result status did not return failed')
def test_register(self):
obj_type = ObjectType(ObjectTypeEnum.SYMMETRIC_KEY)
@ -106,7 +110,7 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
def test_register_attrs_in_key_value(self):
@ -119,7 +123,7 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
def test_register_attrs_in_template(self):
@ -132,7 +136,7 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
def test_register_no_alg(self):
@ -143,10 +147,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.ITEM_NOT_FOUND,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_alg_in_key_value_and_key_block(self):
@ -157,10 +161,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INDEX_OUT_OF_BOUNDS,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_alg_in_template_and_key_block(self):
@ -170,10 +174,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INDEX_OUT_OF_BOUNDS,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_alg_in_template_and_key_value(self):
@ -185,10 +189,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INDEX_OUT_OF_BOUNDS,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_invalid_alg(self):
@ -222,10 +226,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INVALID_FIELD,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_no_length(self):
@ -236,10 +240,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.ITEM_NOT_FOUND,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_length_in_key_value_and_key_block(self):
@ -250,10 +254,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INDEX_OUT_OF_BOUNDS,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_length_in_template_and_key_block(self):
@ -263,10 +267,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INDEX_OUT_OF_BOUNDS,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_length_in_template_and_key_value(self):
@ -278,10 +282,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INDEX_OUT_OF_BOUNDS,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_invalid_length(self):
@ -294,10 +298,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INVALID_FIELD,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_no_usage_mask(self):
@ -308,10 +312,10 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.register(obj_type, template_attribute, key)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.ITEM_NOT_FOUND,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_no_object_type(self):
@ -322,10 +326,10 @@ class TestKMIPServer(TestCase):
res = self.kmip.register(obj_type, template_attribute, key)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.ITEM_NOT_FOUND,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_unsupported_object_type(self):
@ -344,10 +348,10 @@ class TestKMIPServer(TestCase):
res = self.kmip.register(obj_type, template_attribute, key)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INVALID_FIELD,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_register_object_type_mismatch(self):
@ -366,23 +370,23 @@ class TestKMIPServer(TestCase):
res = self.kmip.register(obj_type, template_attribute, key)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.INVALID_FIELD,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_get(self):
uuid = self._create()
key_format_type = KeyFormatType(KeyFormatTypeEnum.RAW)
res = self.kmip.get(uuid, key_format_type)
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
def test_get_no_key_format_type(self):
uuid = self._create()
res = self.kmip.get(uuid, None)
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
def test_get_unknown(self):
@ -391,17 +395,18 @@ class TestKMIPServer(TestCase):
key_format_type = KeyFormatType(KeyFormatTypeEnum.RAW)
res = self.kmip.get(uuid, key_format_type)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.ITEM_NOT_FOUND,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_get_no_uuid(self):
self._create()
key_format_type = KeyFormatType(KeyFormatTypeEnum.RAW)
res = self.kmip.get(None, key_format_type)
self.assertEqual(ResultStatus.OPERATION_FAILED, res.result_status.enum,
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.value,
'result status did not return failed')
def test_get_with_key_compression(self):
@ -410,36 +415,37 @@ class TestKMIPServer(TestCase):
key_compression = KeyCompressionType(KeyCompressionTypeEnum.
EC_PUBLIC_KEY_TYPE_UNCOMPRESSED)
res = self.kmip.get(uuid, key_format_type, key_compression)
self.assertEqual(ResultStatus.OPERATION_FAILED, res.result_status.enum,
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.KEY_COMPRESSION_TYPE_NOT_SUPPORTED,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_destroy(self):
uuid = self._create()
key_format_type = KeyFormatType(KeyFormatTypeEnum.RAW)
res = self.kmip.get(uuid, key_format_type)
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
res = self.kmip.destroy(uuid)
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
res = self.kmip.destroy(uuid)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.ITEM_NOT_FOUND,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_destroy_no_uuid(self):
res = self.kmip.destroy(None)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.ITEM_NOT_FOUND,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def test_destroy_unknown(self):
@ -448,14 +454,14 @@ class TestKMIPServer(TestCase):
key_format_type = KeyFormatType(KeyFormatTypeEnum.RAW)
res = self.kmip.get(uuid, key_format_type)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
res = self.kmip.destroy(uuid)
self.assertEqual(ResultStatus.OPERATION_FAILED,
res.result_status.enum,
res.result_status.value,
'result status did not return failed')
self.assertEqual(ResultReason.ITEM_NOT_FOUND,
res.result_reason.enum,
res.result_reason.value,
'result reason did not match')
def _create(self):
@ -464,7 +470,7 @@ class TestKMIPServer(TestCase):
template_attribute = TemplateAttribute(attributes=attributes)
res = self.kmip.create(obj_type, template_attribute)
self.assertNotEqual(None, res, 'result is None')
self.assertEqual(ResultStatus.SUCCESS, res.result_status.enum,
self.assertEqual(ResultStatus.SUCCESS, res.result_status.value,
'result status did not return success')
return res.uuid
@ -530,5 +536,7 @@ class TestKMIPServer(TestCase):
attrs = [nameattr]
res = self.kmip.locate(attributes=attrs)
self.assertEqual(ResultStatus.OPERATION_FAILED, res.result_status.enum,
'locate result status did not return success')
self.assertEqual(
ResultStatus.OPERATION_FAILED,
res.result_status.value,
'locate result status did not return success')

View File

@ -243,8 +243,8 @@ class TestObjectFactory(testtools.TestCase):
pie_key = self.factory.convert(core_key)
self.assertIsInstance(pie_key, pobjects.SymmetricKey)
self._test_pie_key(
pie_key, algorithm.enum, length.value, self.symmetric_bytes,
format_type.enum)
pie_key, algorithm.value, length.value, self.symmetric_bytes,
format_type.value)
def test_convert_public_key_pie_to_core(self):
"""
@ -282,8 +282,8 @@ class TestObjectFactory(testtools.TestCase):
pie_key = self.factory.convert(core_key)
self.assertIsInstance(pie_key, pobjects.PublicKey)
self._test_pie_key(
pie_key, algorithm.enum, length.value, self.public_bytes,
format_type.enum)
pie_key, algorithm.value, length.value, self.public_bytes,
format_type.value)
def test_convert_private_key_pie_to_core(self):
"""
@ -321,8 +321,8 @@ class TestObjectFactory(testtools.TestCase):
pie_key = self.factory.convert(core_key)
self.assertIsInstance(pie_key, pobjects.PrivateKey)
self._test_pie_key(
pie_key, algorithm.enum, length.value, self.private_bytes,
format_type.enum)
pie_key, algorithm.value, length.value, self.private_bytes,
format_type.value)
def test_convert_certificate_pie_to_core(self):
"""
@ -333,7 +333,7 @@ class TestObjectFactory(testtools.TestCase):
self.assertIsInstance(core_cert, secrets.Certificate)
self.assertEqual(
pie_cert.certificate_type, core_cert.certificate_type.enum)
pie_cert.certificate_type, core_cert.certificate_type.value)
self.assertEqual(pie_cert.value, core_cert.certificate_value.value)
def test_convert_certificate_core_to_pie(self):
@ -346,7 +346,7 @@ class TestObjectFactory(testtools.TestCase):
self.assertIsInstance(pie_cert, pobjects.X509Certificate)
self.assertEqual(
core_cert.certificate_type.enum, pie_cert.certificate_type)
core_cert.certificate_type.value, pie_cert.certificate_type)
self.assertEqual(core_cert.certificate_value.value, pie_cert.value)
def test_convert_secret_data_pie_to_core(self):
@ -360,7 +360,7 @@ class TestObjectFactory(testtools.TestCase):
self.assertIsInstance(core_secret, secrets.SecretData)
data_type = core_secret.secret_data_type.enum
data_type = core_secret.secret_data_type.value
self.assertEqual(enums.SecretDataType.PASSWORD, data_type)
key_block = core_secret.key_block
@ -408,7 +408,7 @@ class TestObjectFactory(testtools.TestCase):
self.assertIsInstance(core_obj, secrets.OpaqueObject)
opaque_type = core_obj.opaque_data_type.enum
opaque_type = core_obj.opaque_data_type.value
self.assertEqual(enums.OpaqueDataType.NONE, opaque_type)
value = core_obj.opaque_data_value.value
@ -453,8 +453,8 @@ class TestObjectFactory(testtools.TestCase):
self.assertIsInstance(pie_key, pobjects.SymmetricKey)
self._test_pie_key(
pie_key, algorithm.enum, length.value, self.symmetric_bytes,
format_type.enum)
pie_key, algorithm.value, length.value, self.symmetric_bytes,
format_type.value)
def test_build_pie_symmetric_key_on_invalid_format(self):
"""
@ -503,8 +503,8 @@ class TestObjectFactory(testtools.TestCase):
self.assertIsInstance(pie_key, pobjects.PublicKey)
self._test_pie_key(
pie_key, algorithm.enum, length.value, self.public_bytes,
format_type.enum)
pie_key, algorithm.value, length.value, self.public_bytes,
format_type.value)
def test_build_core_key(self):
"""
@ -537,13 +537,13 @@ class TestObjectFactory(testtools.TestCase):
key_format_type = key_block.key_format_type
self.assertIsInstance(key_format_type, misc.KeyFormatType)
self.assertEqual(key_format_type.enum, format_type)
self.assertEqual(key_format_type.value, format_type)
cryptographic_algorithm = key_block.cryptographic_algorithm
self.assertIsInstance(
cryptographic_algorithm, attributes.CryptographicAlgorithm)
self.assertEqual(
cryptographic_algorithm.enum, algorithm)
cryptographic_algorithm.value, algorithm)
cryptographic_length = key_block.cryptographic_length
self.assertIsInstance(

View File

@ -88,10 +88,10 @@ class TestKMIPClient(TestCase):
message = utils.build_er_error(credential.__class__, 'type',
cred_type,
credential.credential_type.enum,
credential.credential_type.value,
'value')
self.assertEqual(CredentialType.USERNAME_AND_PASSWORD,
credential.credential_type.enum,
credential.credential_type.value,
message)
message = utils.build_er_error(
@ -151,7 +151,7 @@ class TestKMIPClient(TestCase):
msg = base.format(Operation, operation)
self.assertIsInstance(operation, Operation, msg)
operation_enum = operation.enum
operation_enum = operation.value
msg = base.format(OperationEnum.CREATE_KEY_PAIR, operation_enum)
self.assertEqual(OperationEnum.CREATE_KEY_PAIR, operation_enum, msg)
@ -200,7 +200,7 @@ class TestKMIPClient(TestCase):
msg = base.format(Operation, operation)
self.assertIsInstance(operation, Operation, msg)
operation_enum = operation.enum
operation_enum = operation.value
msg = base.format(OperationEnum.REKEY_KEY_PAIR, operation_enum)
self.assertEqual(OperationEnum.REKEY_KEY_PAIR, operation_enum, msg)
@ -254,7 +254,7 @@ class TestKMIPClient(TestCase):
msg = base.format(Operation, operation)
self.assertIsInstance(operation, Operation, msg)
operation_enum = operation.enum
operation_enum = operation.value
msg = base.format(OperationEnum.QUERY, operation_enum)
self.assertEqual(OperationEnum.QUERY, operation_enum, msg)
@ -290,7 +290,7 @@ class TestKMIPClient(TestCase):
msg = base.format(Operation, operation)
self.assertIsInstance(operation, Operation, msg)
operation_enum = operation.enum
operation_enum = operation.value
msg = base.format(OperationEnum.DISCOVER_VERSIONS, operation_enum)
self.assertEqual(OperationEnum.DISCOVER_VERSIONS, operation_enum, msg)
@ -323,7 +323,7 @@ class TestKMIPClient(TestCase):
self.assertIsInstance(batch_item, RequestBatchItem)
self.assertIsInstance(batch_item.operation, Operation)
self.assertEqual(
OperationEnum.GET_ATTRIBUTE_LIST, batch_item.operation.enum)
OperationEnum.GET_ATTRIBUTE_LIST, batch_item.operation.value)
self.assertIsInstance(
batch_item.request_payload,
get_attribute_list.GetAttributeListRequestPayload)