Write the data encoding the Check response payload to a stream.

Args:
    output_stream (stream): A data stream in which to encode object
        data, supporting a write method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.

Raises:
    ValueError: Raised if the data attribute is not defined.


super(RegisterRequestPayload, self).__init__(<EOL>enums.Tags.REQUEST_PAYLOAD<EOL>)<EOL>self.secret_factory = secret_factory.SecretFactory()<EOL>self._object_type = None<EOL>self._template_attribute = None<EOL>self._secret = None<EOL>self.object_type = object_type<EOL>self.template_attribute = template_attribute<EOL>self.managed_object = managed_object<EOL>

Construct a Register request payload structure.

Args:
    object_type (enum): An ObjectType enumeration specifying the type
        of object to register. Optional, defaults to None. Required for
        read/write.
    template_attribute (TemplateAttribute): A TemplateAttribute
        structure containing a set of attributes to set on the new
        object. Optional, defaults to None. Required for read/write.
    managed_object (Struct): A managed object structure representing
        the object to register. Must be one of:
            * secrets.Certificate
            * secrets.OpaqueObject
            * secrets.PrivateKey
            * secrets.PublicKey
            * secrets.SecretData
            * secrets.SplitKey
            * secrets.SymmetricKey
            * secrets.Template
        Optional, defaults to None. Required for read/write.


def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):

super(RegisterRequestPayload, self).read(<EOL>input_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL>local_buffer = utils.BytearrayStream(input_buffer.read(self.length))<EOL>if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer):<EOL><INDENT>self._object_type = primitives.Enumeration(<EOL>enums.ObjectType,<EOL>tag=enums.Tags.OBJECT_TYPE<EOL>)<EOL>self._object_type.read(local_buffer, kmip_version=kmip_version)<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidKmipEncoding(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if kmip_version < enums.KMIPVersion.KMIP_2_0:<EOL><INDENT>if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer):<EOL><INDENT>self._template_attribute = objects.TemplateAttribute()<EOL>self._template_attribute.read(<EOL>local_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidKmipEncoding(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer):<EOL><INDENT>attributes = objects.Attributes()<EOL>attributes.read(local_buffer, kmip_version=kmip_version)<EOL>value = objects.convert_attributes_to_template_attribute(<EOL>attributes<EOL>)<EOL>self._template_attribute = value<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidKmipEncoding(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>managed_object = self.secret_factory.create(self.object_type)<EOL>if self.is_tag_next(managed_object.tag, local_buffer):<EOL><INDENT>self._managed_object = managed_object<EOL>self._managed_object.read(local_buffer, kmip_version=kmip_version)<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidKmipEncoding(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>self.is_oversized(local_buffer)<EOL>

Read the data encoding the Register request payload and decode it into
its constituent parts.

Args:
    input_buffer (stream): A data buffer containing encoded object
        data, supporting a read method.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.

Raises:
    InvalidKmipEncoding: Raised if the object type, template attribute,
        or managed object is missing from the encoded payload.


def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):

Write the data encoding the Register request payload to a buffer.

Args:
    output_buffer (stream): A data buffer in which to encode object
        data, supporting a write method.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.

Raises:
    InvalidField: Raised if the object type attribute, template
        attribute, or managed object is not defined.


super(RegisterResponsePayload, self).__init__(<EOL>enums.Tags.RESPONSE_PAYLOAD<EOL>)<EOL>self._unique_identifier = None<EOL>self._template_attribute = None<EOL>self.unique_identifier = unique_identifier<EOL>self.template_attribute = template_attribute<EOL>

Construct a Register response payload structure.

Args:
    unique_identifier (string): The ID of the new object. Optional,
        defaults to None. Required for read/write.
    template_attribute (TemplateAttribute): A TemplateAttribute
        structure containing a set of attributes that were set on the
        new object. Optional, defaults to None.


super(RegisterResponsePayload, self).read(<EOL>input_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL>local_buffer = utils.BytearrayStream(input_buffer.read(self.length))<EOL>if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):<EOL><INDENT>self._unique_identifier = primitives.TextString(<EOL>tag=enums.Tags.UNIQUE_IDENTIFIER<EOL>)<EOL>self._unique_identifier.read(<EOL>local_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidKmipEncoding(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if kmip_version < enums.KMIPVersion.KMIP_2_0:<EOL><INDENT>if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer):<EOL><INDENT>self._template_attribute = objects.TemplateAttribute()<EOL>self._template_attribute.read(<EOL>local_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT><DEDENT>self.is_oversized(local_buffer)<EOL>

Read the data encoding the Register response payload and decode it
into its constituent parts.

Args:
    input_buffer (stream): A data buffer containing encoded object
        data, supporting a read method.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.

Raises:
    InvalidKmipEncoding: Raised if the unique identifier is missing
        from the encoded payload.


Write the data encoding the Register response payload to a buffer.

Args:
    output_buffer (stream): A data buffer in which to encode object
        data, supporting a write method.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.

Raises:
    InvalidField: Raised if the unique identifier is not defined.


def __init__(self, unique_identifier=None, attribute_names=None):

super(GetAttributesRequestPayload, self).__init__(<EOL>enums.Tags.REQUEST_PAYLOAD)<EOL>self._unique_identifier = None<EOL>self._attribute_names = list()<EOL>self.unique_identifier = unique_identifier<EOL>self.attribute_names = attribute_names<EOL>

Construct a GetAttributes request payload.

Args:
    unique_identifier (string): The ID of the managed object with
        which the retrieved attributes should be associated. Optional,
        defaults to None.
    attribute_names: A list of strings identifying the names of the
        attributes associated with the managed object. Optional,
        defaults to None.


super(GetAttributesRequestPayload, self).read(<EOL>input_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL>local_buffer = utils.BytearrayStream(input_buffer.read(self.length))<EOL>if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):<EOL><INDENT>self._unique_identifier = primitives.TextString(<EOL>tag=enums.Tags.UNIQUE_IDENTIFIER<EOL>)<EOL>self._unique_identifier.read(<EOL>local_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>else:<EOL><INDENT>self._unique_identifier = None<EOL><DEDENT>names = list()<EOL>if kmip_version < enums.KMIPVersion.KMIP_2_0:<EOL><INDENT>while self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, local_buffer):<EOL><INDENT>name = primitives.TextString(tag=enums.Tags.ATTRIBUTE_NAME)<EOL>name.read(local_buffer, kmip_version=kmip_version)<EOL>names.append(name)<EOL><DEDENT>self._attribute_names = names<EOL><DEDENT>else:<EOL><INDENT>while self.is_tag_next(<EOL>enums.Tags.ATTRIBUTE_REFERENCE,<EOL>local_buffer<EOL>):<EOL><INDENT>if self.is_type_next(enums.Types.STRUCTURE, local_buffer):<EOL><INDENT>reference = objects.AttributeReference()<EOL>reference.read(local_buffer, kmip_version=kmip_version)<EOL>names.append(<EOL>primitives.TextString(<EOL>value=reference.attribute_name,<EOL>tag=enums.Tags.ATTRIBUTE_NAME<EOL>)<EOL>)<EOL><DEDENT>elif self.is_type_next(enums.Types.ENUMERATION, local_buffer):<EOL><INDENT>reference = primitives.Enumeration(<EOL>enums.Tags,<EOL>tag=enums.Tags.ATTRIBUTE_REFERENCE<EOL>)<EOL>reference.read(local_buffer, kmip_version=kmip_version)<EOL>name = enums.convert_attribute_tag_to_name(reference.value)<EOL>names.append(<EOL>primitives.TextString(<EOL>value=name,<EOL>tag=enums.Tags.ATTRIBUTE_NAME<EOL>)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidKmipEncoding(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>self._attribute_names = names<EOL><DEDENT>self.is_oversized(local_buffer)<EOL>

Read the data encoding the GetAttributes request payload and decode
it into its constituent parts.

Args:
    input_buffer (stream): A data stream containing encoded object
        data, supporting a read method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.

Raises:
    InvalidKmipEncoding: Raised if an invalid type is found for the
        AttributeReference encoding for KMIP 2.0+ encodings.


local_buffer = utils.BytearrayStream()<EOL>if self._unique_identifier:<EOL><INDENT>self._unique_identifier.write(<EOL>local_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>if kmip_version < enums.KMIPVersion.KMIP_2_0:<EOL><INDENT>for attribute_name in self._attribute_names:<EOL><INDENT>attribute_name.write(local_buffer, kmip_version=kmip_version)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for attribute_name in self._attribute_names:<EOL><INDENT>t = enums.convert_attribute_name_to_tag(attribute_name.value)<EOL>e = primitives.Enumeration(<EOL>enums.Tags,<EOL>value=t,<EOL>tag=enums.Tags.ATTRIBUTE_REFERENCE<EOL>)<EOL>e.write(local_buffer, kmip_version=kmip_version)<EOL><DEDENT><DEDENT>self.length = local_buffer.length()<EOL>super(GetAttributesRequestPayload, self).write(<EOL>output_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL>output_buffer.write(local_buffer.buffer)<EOL>

Write the data encoding the GetAttributes request payload to a
stream.

Args:
    output_buffer (stream): A data stream in which to encode object
        data, supporting a write method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.


def __init__(self, unique_identifier=None, attributes=None):

super(GetAttributesResponsePayload, self).__init__(<EOL>enums.Tags.RESPONSE_PAYLOAD)<EOL>self._unique_identifier = None<EOL>self._attributes = list()<EOL>self.unique_identifier = unique_identifier<EOL>self.attributes = attributes<EOL>

Construct a GetAttributes response payload.

Args:
    unique_identifier (string): The ID of the managed object with
        which the retrieved attributes should be associated. Optional,
        defaults to None.
    attributes (list): A list of attribute structures associated with
        the managed object. Optional, defaults to None.


super(GetAttributesResponsePayload, self).read(<EOL>input_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL>local_buffer = utils.BytearrayStream(input_buffer.read(self.length))<EOL>if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):<EOL><INDENT>unique_identifier = primitives.TextString(<EOL>tag=enums.Tags.UNIQUE_IDENTIFIER<EOL>)<EOL>unique_identifier.read(local_buffer, kmip_version=kmip_version)<EOL>self.unique_identifier = unique_identifier.value<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidKmipEncoding(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if kmip_version < enums.KMIPVersion.KMIP_2_0:<EOL><INDENT>self._attributes = list()<EOL>while self.is_tag_next(enums.Tags.ATTRIBUTE, local_buffer):<EOL><INDENT>attribute = objects.Attribute()<EOL>attribute.read(local_buffer, kmip_version=kmip_version)<EOL>self._attributes.append(attribute)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer):<EOL><INDENT>attributes = objects.Attributes()<EOL>attributes.read(local_buffer, kmip_version=kmip_version)<EOL>temp_attr = objects.convert_attributes_to_template_attribute(<EOL>attributes<EOL>)<EOL>self._attributes = temp_attr.attributes<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidKmipEncoding(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>self.is_oversized(local_buffer)<EOL>

Read the data encoding the GetAttributes response payload and decode
it into its constituent parts.

Args:
    input_buffer (stream): A data stream containing encoded object
        data, supporting a read method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.


local_buffer = utils.BytearrayStream()<EOL>if self._unique_identifier:<EOL><INDENT>self._unique_identifier.write(<EOL>local_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if kmip_version < enums.KMIPVersion.KMIP_2_0:<EOL><INDENT>for attribute in self._attributes:<EOL><INDENT>attribute.write(local_buffer, kmip_version=kmip_version)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self._attributes:<EOL><INDENT>template_attribute = objects.TemplateAttribute(<EOL>attributes=self.attributes<EOL>)<EOL>attributes = objects.convert_template_attribute_to_attributes(<EOL>template_attribute<EOL>)<EOL>attributes.write(local_buffer, kmip_version=kmip_version)<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>self.length = local_buffer.length()<EOL>super(GetAttributesResponsePayload, self).write(<EOL>output_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL>output_buffer.write(local_buffer.buffer)<EOL>

Write the data encoding the GetAttributes response payload to a
stream.

Args:
    output_buffer (stream): A data stream in which to encode object
        data, supporting a write method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.


super(CreateKeyPairRequestPayload, self).__init__(<EOL>enums.Tags.REQUEST_PAYLOAD<EOL>)<EOL>self._common_template_attribute = None<EOL>self._private_key_template_attribute = None<EOL>self._public_key_template_attribute = None<EOL>self.common_template_attribute = common_template_attribute<EOL>self.private_key_template_attribute = private_key_template_attribute<EOL>self.public_key_template_attribute = public_key_template_attribute<EOL>

Construct a CreateKeyPair request payload structure.

Args:
    common_template_attribute (TemplateAttribute): A TemplateAttribute
        structure with the CommonTemplateAttribute tag containing a set
        of attributes to set on the new public and private keys.
        Optional, defaults to None.
    private_key_template_attribute (TemplateAttribute): A
        TemplateAttribute structure with the
        PrivateKeyTemplateAttribute tag containing a set of attributes
        to set on the new private key. Optional, defaults to None.
    public_key_template_attribute (TemplateAttribute): A
        TemplateAttribute structure with the PublicKeyTemplateAttribute
        tag containing a set of attributes to set on the new public
        key. Optional, defaults to None.


Read the data encoding the CreateKeyPair request payload and decode it
into its constituent parts.

Args:
    input_buffer (stream): A data buffer containing encoded object
        data, supporting a read method.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.


local_buffer = utils.BytearrayStream()<EOL>if kmip_version < enums.KMIPVersion.KMIP_2_0:<EOL><INDENT>if self._common_template_attribute is not None:<EOL><INDENT>self._common_template_attribute.write(<EOL>local_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self._common_template_attribute is not None:<EOL><INDENT>attributes = objects.convert_template_attribute_to_attributes(<EOL>self._common_template_attribute<EOL>)<EOL>attributes.write(local_buffer, kmip_version=kmip_version)<EOL><DEDENT><DEDENT>if kmip_version < enums.KMIPVersion.KMIP_2_0:<EOL><INDENT>if self._private_key_template_attribute is not None:<EOL><INDENT>self._private_key_template_attribute.write(<EOL>local_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self._private_key_template_attribute is not None:<EOL><INDENT>attributes = objects.convert_template_attribute_to_attributes(<EOL>self._private_key_template_attribute<EOL>)<EOL>attributes.write(local_buffer, kmip_version=kmip_version)<EOL><DEDENT><DEDENT>if kmip_version < enums.KMIPVersion.KMIP_2_0:<EOL><INDENT>if self._public_key_template_attribute is not None:<EOL><INDENT>self._public_key_template_attribute.write(<EOL>local_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self._public_key_template_attribute is not None:<EOL><INDENT>attributes = objects.convert_template_attribute_to_attributes(<EOL>self._public_key_template_attribute<EOL>)<EOL>attributes.write(local_buffer, kmip_version=kmip_version)<EOL><DEDENT><DEDENT>self.length = local_buffer.length()<EOL>super(CreateKeyPairRequestPayload, self).write(<EOL>output_buffer,<EOL>kmip_version=kmip_version<EOL>)<EOL>output_buffer.write(local_buffer.buffer)<EOL>

Write the data encoding the CreateKeyPair request payload to a buffer.

Args:
    output_buffer (stream): A data buffer in which to encode object
        data, supporting a write method.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.


super(CreateKeyPairResponsePayload, self).__init__(<EOL>enums.Tags.RESPONSE_PAYLOAD<EOL>)<EOL>self._private_key_unique_identifier = None<EOL>self._public_key_unique_identifier = None<EOL>self._private_key_template_attribute = None<EOL>self._public_key_template_attribute = None<EOL>self.private_key_unique_identifier = private_key_unique_identifier<EOL>self.public_key_unique_identifier = public_key_unique_identifier<EOL>self.private_key_template_attribute = private_key_template_attribute<EOL>self.public_key_template_attribute = public_key_template_attribute<EOL>

Construct a CreateKeyPair response payload structure.

Args:
    private_key_unique_identifier (string): A string specifying the
        ID of the new private key. Optional, defaults to None. Required
        for read/write.
    public_key_unique_identifier (string): A string specifying the
        ID of the new public key. Optional, defaults to None. Required
        for read/write.
    private_key_template_attribute (TemplateAttribute): A
        TemplateAttribute structure with the
        PrivateKeyTemplateAttribute tag containing the set of
        attributes that were set on the new private key. Optional,
        defaults to None.
    public_key_template_attribute (TemplateAttribute): A
        TemplateAttribute structure with the PublicKeyTemplateAttribute
        tag containing the set of attributes that were set on the new
        public key. Optional, defaults to None.


Read the data encoding the CreateKeyPair response payload and decode it
into its constituent parts.

Args:
    input_buffer (stream): A data buffer containing encoded object
        data, supporting a read method.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.

Raises:
    InvalidKmipEncoding: Raised if the private key unique identifier or
        the public key unique identifier is missing from the encoded
        payload.


Write the data encoding the CreateKeyPair response payload to a buffer.

Args:
    output_buffer (stream): A data buffer in which to encode object
        data, supporting a write method.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.

Raises:
    InvalidField: Raised if the private key unique identifier or the
        public key unique identifier is not defined.


super(ActivateRequestPayload, self).__init__(<EOL>tag=enums.Tags.REQUEST_PAYLOAD)<EOL>self.unique_identifier = unique_identifier<EOL>self.validate()<EOL>

Construct a ActivateRequestPayload object.
Args:
    unique_identifier (UniqueIdentifier): The UUID of a managed
        cryptographic object.


def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):

super(ActivateRequestPayload, self).read(<EOL>istream,<EOL>kmip_version=kmip_version<EOL>)<EOL>tstream = BytearrayStream(istream.read(self.length))<EOL>self.unique_identifier = attributes.UniqueIdentifier()<EOL>self.unique_identifier.read(tstream, kmip_version=kmip_version)<EOL>self.is_oversized(tstream)<EOL>self.validate()<EOL>

Read the data encoding the ActivateRequestPayload object and decode it
into its constituent parts.
Args:
    istream (Stream): A data stream containing encoded object data,
        supporting a read method; usually a BytearrayStream object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.


def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):

tstream = BytearrayStream()<EOL>if self.unique_identifier is not None:<EOL><INDENT>self.unique_identifier.write(tstream, kmip_version=kmip_version)<EOL><DEDENT>self.length = tstream.length()<EOL>super(ActivateRequestPayload, self).write(<EOL>ostream,<EOL>kmip_version=kmip_version<EOL>)<EOL>ostream.write(tstream.buffer)<EOL>

Write the data encoding the ActivateRequestPayload object to a stream.
Args:
    ostream (Stream): A data stream in which to encode object data,
        supporting a write method; usually a BytearrayStream object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.


if self.unique_identifier is not None:<EOL><INDENT>if not isinstance(self.unique_identifier,<EOL>attributes.UniqueIdentifier):<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise TypeError(msg)<EOL><DEDENT><DEDENT>

Error check the attributes of the ActivateRequestPayload object.


super(ActivateResponsePayload, self).__init__(<EOL>tag=enums.Tags.RESPONSE_PAYLOAD)<EOL>if unique_identifier is None:<EOL><INDENT>self.unique_identifier = attributes.UniqueIdentifier()<EOL><DEDENT>else:<EOL><INDENT>self.unique_identifier = unique_identifier<EOL><DEDENT>self.validate()<EOL>

Construct a ActivateResponsePayload object.

Args:
    unique_identifier (UniqueIdentifier): The UUID of a managed
        cryptographic object.


super(ActivateResponsePayload, self).read(<EOL>istream,<EOL>kmip_version=kmip_version<EOL>)<EOL>tstream = BytearrayStream(istream.read(self.length))<EOL>self.unique_identifier = attributes.UniqueIdentifier()<EOL>self.unique_identifier.read(tstream, kmip_version=kmip_version)<EOL>self.is_oversized(tstream)<EOL>self.validate()<EOL>

Read the data encoding the ActivateResponsePayload object and decode it
into its constituent parts.

Args:
    istream (Stream): A data stream containing encoded object data,
        supporting a read method; usually a BytearrayStream object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.


tstream = BytearrayStream()<EOL>self.unique_identifier.write(tstream, kmip_version=kmip_version)<EOL>self.length = tstream.length()<EOL>super(ActivateResponsePayload, self).write(<EOL>ostream,<EOL>kmip_version=kmip_version<EOL>)<EOL>ostream.write(tstream.buffer)<EOL>

Write the data encoding the ActivateResponsePayload object to a stream.

Args:
    ostream (Stream): A data stream in which to encode object data,
        supporting a write method; usually a BytearrayStream object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.


if not isinstance(self.unique_identifier, attributes.UniqueIdentifier):<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise TypeError(msg)<EOL><DEDENT>


super(RekeyRequestPayload, self).__init__(<EOL>enums.Tags.REQUEST_PAYLOAD<EOL>)<EOL>self._unique_identifier = None<EOL>self._offset = None<EOL>self._template_attribute = None<EOL>self.unique_identifier = unique_identifier<EOL>self.offset = offset<EOL>self.template_attribute = template_attribute<EOL>

Construct a Rekey request payload struct.

Args:
    unique_identifier (string): The ID of the symmetric key to rekey.
        Optional, defaults to None.
    offset (int): The number of seconds between the initialization and
        activation dates of the replacement key. Optional, defaults to
        None.
    template_attribute (TemplateAttribute): A structure containing a
        set of attributes (e.g., cryptographic algorithm,
        cryptographic length) that should be set on the replacement
        key. Optional, defaults to None.


def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):

super(RekeyRequestPayload, self).read(<EOL>input_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL>local_stream = utils.BytearrayStream(input_stream.read(self.length))<EOL>if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):<EOL><INDENT>self._unique_identifier = primitives.TextString(<EOL>tag=enums.Tags.UNIQUE_IDENTIFIER<EOL>)<EOL>self._unique_identifier.read(<EOL>local_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>if self.is_tag_next(enums.Tags.OFFSET, local_stream):<EOL><INDENT>self._offset = primitives.Interval(<EOL>tag=enums.Tags.OFFSET<EOL>)<EOL>self._offset.read(local_stream, kmip_version=kmip_version)<EOL><DEDENT>if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_stream):<EOL><INDENT>self._template_attribute = objects.TemplateAttribute()<EOL>self._template_attribute.read(<EOL>local_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>self.is_oversized(local_stream)<EOL>

Read the data encoding the Rekey request payload and decode it into
its constituent parts.

Args:
    input_stream (stream): A data stream containing encoded object
        data, supporting a read method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.


def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):

local_stream = utils.BytearrayStream()<EOL>if self._unique_identifier is not None:<EOL><INDENT>self._unique_identifier.write(<EOL>local_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>if self._offset is not None:<EOL><INDENT>self._offset.write(local_stream, kmip_version=kmip_version)<EOL><DEDENT>if self._template_attribute is not None:<EOL><INDENT>self._template_attribute.write(<EOL>local_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>self.length = local_stream.length()<EOL>super(RekeyRequestPayload, self).write(<EOL>output_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL>output_stream.write(local_stream.buffer)<EOL>

Write the data encoding the Rekey request payload to a stream.

Args:
    output_stream (stream): A data stream in which to encode object
        data, supporting a write method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.


super(RekeyResponsePayload, self).__init__(<EOL>enums.Tags.RESPONSE_PAYLOAD<EOL>)<EOL>self._unique_identifier = None<EOL>self._template_attribute = None<EOL>self.unique_identifier = unique_identifier<EOL>self.template_attribute = template_attribute<EOL>

Construct a Rekey response payload struct.

Args:
    unique_identifier (string): The ID of the replacement key.
        Optional, defaults to None. Required for read/write.
    template_attribute (TemplateAttribute): A structure containing a
        set of attributes (e.g., cryptographic algorithm,
        cryptographic length) that were set by the server on the
        replacement key. Optional, defaults to None.


Read the data encoding the Rekey response payload and decode it into
its constituent parts.

Args:
    input_stream (stream): A data stream containing encoded object
        data, supporting a read method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.

Raises:
    ValueError: Raised if the unique identifier attribute is missing
        from the encoded payload.


local_stream = utils.BytearrayStream()<EOL>if self._unique_identifier is not None:<EOL><INDENT>self._unique_identifier.write(<EOL>local_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if self._template_attribute is not None:<EOL><INDENT>self._template_attribute.write(<EOL>local_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>self.length = local_stream.length()<EOL>super(RekeyResponsePayload, self).write(<EOL>output_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL>output_stream.write(local_stream.buffer)<EOL>

Write the data encoding the Rekey request payload to a stream.

Args:
    output_stream (stream): A data stream in which to encode object
        data, supporting a write method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.

Raises:
    ValueError: Raised if the payload is missing the unique identifier.


super(RevokeRequestPayload, self).__init__(<EOL>tag=enums.Tags.REQUEST_PAYLOAD)<EOL>self.unique_identifier = unique_identifier<EOL>self.compromise_occurrence_date = compromise_occurrence_date<EOL>self.revocation_reason = revocation_reason<EOL>if self.revocation_reason is None:<EOL><INDENT>self.revocation_reason = objects.RevocationReason()<EOL><DEDENT>self.validate()<EOL>

Construct a RevokeRequestPayload object.
Args:
    unique_identifier (UniqueIdentifier): The UUID of a managed
        cryptographic object.
    revocation_reason (RevocationReason): The reason why the object was
        revoked.
    compromise_occurrence_date (DateTime): the datetime when the object
        was first believed to be compromised.


super(RevokeRequestPayload, self).read(<EOL>istream,<EOL>kmip_version=kmip_version<EOL>)<EOL>tstream = BytearrayStream(istream.read(self.length))<EOL>self.unique_identifier = attributes.UniqueIdentifier()<EOL>self.unique_identifier.read(tstream, kmip_version=kmip_version)<EOL>self.revocation_reason = objects.RevocationReason()<EOL>self.revocation_reason.read(tstream, kmip_version=kmip_version)<EOL>if self.is_tag_next(enums.Tags.COMPROMISE_OCCURRENCE_DATE, tstream):<EOL><INDENT>self.compromise_occurrence_date = primitives.DateTime(<EOL>tag=enums.Tags.COMPROMISE_OCCURRENCE_DATE)<EOL>self.compromise_occurrence_date.read(<EOL>tstream,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>self.is_oversized(tstream)<EOL>self.validate()<EOL>

Read the data encoding the RevokeRequestPayload object and decode it
into its constituent parts.
Args:
    istream (Stream): A data stream containing encoded object data,
        supporting a read method; usually a BytearrayStream object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.


tstream = BytearrayStream()<EOL>if self.unique_identifier is not None:<EOL><INDENT>self.unique_identifier.write(tstream, kmip_version=kmip_version)<EOL><DEDENT>self.revocation_reason.write(tstream, kmip_version=kmip_version)<EOL>if self.compromise_occurrence_date is not None:<EOL><INDENT>self.compromise_occurrence_date.write(<EOL>tstream,<EOL>kmip_version=kmip_version<EOL>)<EOL><DEDENT>self.length = tstream.length()<EOL>super(RevokeRequestPayload, self).write(<EOL>ostream,<EOL>kmip_version=kmip_version<EOL>)<EOL>ostream.write(tstream.buffer)<EOL>

Write the data encoding the RevokeRequestPayload object to a stream.
Args:
    ostream (Stream): A data stream in which to encode object data,
        supporting a write method; usually a BytearrayStream object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.


if self.unique_identifier is not None:<EOL><INDENT>if not isinstance(self.unique_identifier,<EOL>attributes.UniqueIdentifier):<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise TypeError(msg)<EOL><DEDENT><DEDENT>if self.compromise_occurrence_date is not None:<EOL><INDENT>if not isinstance(self.compromise_occurrence_date,<EOL>primitives.DateTime):<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise TypeError(msg)<EOL><DEDENT><DEDENT>if not isinstance(self.revocation_reason, objects.RevocationReason):<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise TypeError(msg)<EOL><DEDENT>


super(RevokeResponsePayload, self).__init__(<EOL>tag=enums.Tags.RESPONSE_PAYLOAD)<EOL>if unique_identifier is None:<EOL><INDENT>self.unique_identifier = attributes.UniqueIdentifier()<EOL><DEDENT>else:<EOL><INDENT>self.unique_identifier = unique_identifier<EOL><DEDENT>self.validate()<EOL>

Construct a RevokeResponsePayload object.
Args:
    unique_identifier (UniqueIdentifier): The UUID of a managed
        cryptographic object.


super(RevokeResponsePayload, self).read(<EOL>istream,<EOL>kmip_version=kmip_version<EOL>)<EOL>tstream = BytearrayStream(istream.read(self.length))<EOL>self.unique_identifier = attributes.UniqueIdentifier()<EOL>self.unique_identifier.read(tstream, kmip_version=kmip_version)<EOL>self.is_oversized(tstream)<EOL>self.validate()<EOL>

Read the data encoding the RevokeResponsePayload object and decode it
into its constituent parts.
Args:
    istream (Stream): A data stream containing encoded object data,
        supporting a read method; usually a BytearrayStream object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.


tstream = BytearrayStream()<EOL>self.unique_identifier.write(tstream, kmip_version=kmip_version)<EOL>self.length = tstream.length()<EOL>super(RevokeResponsePayload, self).write(<EOL>ostream,<EOL>kmip_version=kmip_version<EOL>)<EOL>ostream.write(tstream.buffer)<EOL>

Write the data encoding the RevokeResponsePayload object to a stream.
Args:
    ostream (Stream): A data stream in which to encode object data,
        supporting a write method; usually a BytearrayStream object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.


Error check the attributes of the RevokeRequestPayload object.


if not isinstance(value, ProtocolVersion):<EOL><INDENT>return None<EOL><DEDENT>if value.major == <NUM_LIT:1>:<EOL><INDENT>if value.minor == <NUM_LIT:0>:<EOL><INDENT>return enums.KMIPVersion.KMIP_1_0<EOL><DEDENT>elif value.minor == <NUM_LIT:1>:<EOL><INDENT>return enums.KMIPVersion.KMIP_1_1<EOL><DEDENT>elif value.minor == <NUM_LIT:2>:<EOL><INDENT>return enums.KMIPVersion.KMIP_1_2<EOL><DEDENT>elif value.minor == <NUM_LIT:3>:<EOL><INDENT>return enums.KMIPVersion.KMIP_1_3<EOL><DEDENT>elif value.minor == <NUM_LIT:4>:<EOL><INDENT>return enums.KMIPVersion.KMIP_1_4<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Convert a ProtocolVersion struct to its KMIPVersion enumeration equivalent.

Args:
    value (ProtocolVersion): A ProtocolVersion struct to be converted into
        a KMIPVersion enumeration.

Returns:
    KMIPVersion: The enumeration equivalent of the struct. If the struct
        cannot be converted to a valid enumeration, None is returned.


def __init__(self, major=None, minor=None):

super(ProtocolVersion, self).__init__(enums.Tags.PROTOCOL_VERSION)<EOL>self._major = None<EOL>self._minor = None<EOL>self.major = major<EOL>self.minor = minor<EOL>

Construct a ProtocolVersion struct.

Args:
    major (int): The major protocol version number. Optional, defaults
        to None.
    minor (int): The minor protocol version number. Optional, defaults
        to None.


super(ProtocolVersion, self).read(<EOL>input_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL>local_stream = utils.BytearrayStream(input_stream.read(self.length))<EOL>if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MAJOR, local_stream):<EOL><INDENT>self._major = primitives.Integer(<EOL>tag=enums.Tags.PROTOCOL_VERSION_MAJOR<EOL>)<EOL>self._major.read(local_stream, kmip_version=kmip_version)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MINOR, local_stream):<EOL><INDENT>self._minor = primitives.Integer(<EOL>tag=enums.Tags.PROTOCOL_VERSION_MINOR<EOL>)<EOL>self._minor.read(local_stream, kmip_version=kmip_version)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>self.is_oversized(local_stream)<EOL>

Read the data encoding the ProtocolVersion struct and decode it into
its constituent parts.

Args:
    input_stream (stream): A data stream containing encoded object
        data, supporting a read method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.

Raises:
    ValueError: Raised if either the major or minor protocol versions
        are missing from the encoding.


local_stream = utils.BytearrayStream()<EOL>if self._major:<EOL><INDENT>self._major.write(local_stream, kmip_version=kmip_version)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if self._minor:<EOL><INDENT>self._minor.write(local_stream, kmip_version=kmip_version)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>self.length = local_stream.length()<EOL>super(ProtocolVersion, self).write(<EOL>output_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL>output_stream.write(local_stream.buffer)<EOL>

Write the data encoding the ProtocolVersion struct to a stream.

Args:
    output_stream (stream): A data stream in which to encode object
        data, supporting a write method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.

Raises:
    ValueError: Raised if the data attribute is not defined.


super(Authentication, self).__init__(enums.Tags.AUTHENTICATION)<EOL>self._credentials = []<EOL>self.credentials = credentials<EOL>

Construct an Authentication struct.

Args:
    credentials (list): A list of Credential structs to be used for
        authentication. Optional, defaults to None.


super(Authentication, self).read(<EOL>input_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL>local_stream = utils.BytearrayStream(input_stream.read(self.length))<EOL>credentials = []<EOL>while self.is_tag_next(enums.Tags.CREDENTIAL, local_stream):<EOL><INDENT>credential = objects.Credential()<EOL>credential.read(local_stream, kmip_version=kmip_version)<EOL>credentials.append(credential)<EOL><DEDENT>if len(credentials) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>self._credentials = credentials<EOL>self.is_oversized(local_stream)<EOL>

Read the data encoding the Authentication struct and decode it into
its constituent parts.

Args:
    input_stream (stream): A data stream containing encoded object
        data, supporting a read method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be decoded. Optional,
        defaults to KMIP 1.0.


local_stream = utils.BytearrayStream()<EOL>if len(self._credentials) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>for credential in self._credentials:<EOL><INDENT>credential.write(local_stream, kmip_version=kmip_version)<EOL><DEDENT>self.length = local_stream.length()<EOL>super(Authentication, self).write(<EOL>output_stream,<EOL>kmip_version=kmip_version<EOL>)<EOL>output_stream.write(local_stream.buffer)<EOL>

Write the data encoding the Authentication struct to a stream.

Args:
    output_stream (stream): A data stream in which to encode object
        data, supporting a write method; usually a BytearrayStream
        object.
    kmip_version (KMIPVersion): An enumeration defining the KMIP
        version with which the object will be encoded. Optional,
        defaults to KMIP 1.0.


super(KmipError, self).__init__(message)<EOL>self.status = status<EOL>self.reason = reason<EOL>

Create a KmipError exception.

Args:
    status (ResultStatus): An enumeration detailing the result outcome.
    reason (ResultReason): An enumeration giving the status rationale.
    message (string): A string containing more information about the
        error.


super(CryptographicFailure, self).__init__(<EOL>reason=enums.ResultReason.CRYPTOGRAPHIC_FAILURE,<EOL>message=message<EOL>)<EOL>

Create a CryptographicFailure exception.

Args:
    message (string): A string containing information about the error.


super(EncodingOptionError, self).__init__(<EOL>reason=enums.ResultReason.ENCODING_OPTION_ERROR,<EOL>message=message<EOL>)<EOL>

Create an EncodingOptionError.

Args:
    message (string): A string containing information about the error.


super(IllegalOperation, self).__init__(<EOL>reason=enums.ResultReason.ILLEGAL_OPERATION,<EOL>message=message<EOL>)<EOL>

Create an IllegalOperation exception.

Args:
    message (string): A string containing information about the error.


super(IndexOutOfBounds, self).__init__(<EOL>reason=enums.ResultReason.INDEX_OUT_OF_BOUNDS,<EOL>message=message<EOL>)<EOL>

Create an IndexOutOfBounds exception.

Args:
    message (string): A string containing information about the error.


super(InvalidField, self).__init__(<EOL>reason=enums.ResultReason.INVALID_FIELD,<EOL>message=message<EOL>)<EOL>

Create an InvalidField exception.

Args:
    message (string): A string containing information about the error.


super(InvalidMessage, self).__init__(<EOL>reason=enums.ResultReason.INVALID_MESSAGE,<EOL>message=message<EOL>)<EOL>

Create an InvalidMessage exception.

Args:
    message (string): A string containing information about the error.


super(ItemNotFound, self).__init__(<EOL>reason=enums.ResultReason.ITEM_NOT_FOUND,<EOL>message=message<EOL>)<EOL>

Create an ItemNotFound exception.

Args:
    message (string): A string containing information about the error.


super(KeyCompressionTypeNotSupported, self).__init__(<EOL>reason=enums.ResultReason.KEY_COMPRESSION_TYPE_NOT_SUPPORTED,<EOL>message=message<EOL>)<EOL>

Create a KeyCompressionTypeNotSupported exception.

Args:
    message (string): A string containing information about the error.


super(KeyFormatTypeNotSupported, self).__init__(<EOL>reason=enums.ResultReason.KEY_FORMAT_TYPE_NOT_SUPPORTED,<EOL>message=message<EOL>)<EOL>

Create a KeyFormatTypeNotSupported exception.

Args:
    message (string): A string containing information about the error.


super(OperationNotSupported, self).__init__(<EOL>reason=enums.ResultReason.OPERATION_NOT_SUPPORTED,<EOL>message=message<EOL>)<EOL>

Create an OperationNotSupported exception.

Args:
    message (string): A string containing information about the error.


super(PermissionDenied, self).__init__(<EOL>reason=enums.ResultReason.PERMISSION_DENIED,<EOL>message=message<EOL>)<EOL>

Create a PermissionDenied exception.

Args:
    message (string): A string containing information about the error.


self._custom_suites = []<EOL>if cipher_suites:<EOL><INDENT>for cipher_suite in cipher_suites:<EOL><INDENT>if cipher_suite in self.openssl_cipher_suite_map.keys():<EOL><INDENT>suite = self.openssl_cipher_suite_map.get(cipher_suite)<EOL>if suite:<EOL><INDENT>self._custom_suites.append(suite)<EOL><DEDENT><DEDENT>elif cipher_suite in self.openssl_cipher_suite_map.values():<EOL><INDENT>if cipher_suite:<EOL><INDENT>self._custom_suites.append(cipher_suite)<EOL><DEDENT><DEDENT><DEDENT>self._custom_suites = list(set(self._custom_suites))<EOL><DEDENT>suites = []<EOL>if self._custom_suites:<EOL><INDENT>for suite in self._custom_suites:<EOL><INDENT>if suite in self._default_cipher_suites:<EOL><INDENT>suites.append(suite)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>suites = self._default_cipher_suites<EOL><DEDENT>self._cipher_suites = '<STR_LIT::>'.join(suites)<EOL>if self._cipher_suites == '<STR_LIT>':<EOL><INDENT>self._cipher_suites = '<STR_LIT::>'.join(self._default_cipher_suites)<EOL><DEDENT>

Create an AuthenticationSuite object.

Args:
    cipher_suites (list): A list of strings representing the names of
        cipher suites to use. Overrides the default set of cipher
        suites. Optional, defaults to None.


return self._protocol<EOL>

Get the authentication suite protocol.

Returns:
    int: The value of the ssl.PROTOCOL_* setting for this suite.


return self._cipher_suites<EOL>

Get the authentication suite cipher string.

Returns:
    string: A colon delimited string listing the valid ciphers for
        the suite protocol.


super(BasicAuthenticationSuite, self).__init__(cipher_suites)<EOL>self._protocol = ssl.PROTOCOL_TLSv1<EOL>

Create a BasicAuthenticationSuite object.

Args:
    cipher_suites (list): A list of strings representing the names of
        cipher suites to use. Overrides the default set of cipher
        suites. Optional, defaults to None.


super(TLS12AuthenticationSuite, self).__init__(cipher_suites)<EOL>self._protocol = ssl.PROTOCOL_TLSv1_2<EOL>

Create a TLS12AuthenticationSuite object.

Args:
    cipher_suites (list): A list of strings representing the names of
        cipher suites to use. Overrides the default set of cipher
        suites. Optional, defaults to None.


self._logger = logging.getLogger('<STR_LIT>')<EOL>self.settings = dict()<EOL>self.settings['<STR_LIT>'] = True<EOL>self.settings['<STR_LIT>'] = []<EOL>self.settings['<STR_LIT>'] = logging.INFO<EOL>self.settings['<STR_LIT>'] = []<EOL>self._expected_settings = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT:port>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'<EOL>]<EOL>self._optional_settings = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'<EOL>]<EOL>


if setting not in self._expected_settings + self._optional_settings:<EOL><INDENT>raise exceptions.ConfigurationError(<EOL>"<STR_LIT>".format(setting)<EOL>)<EOL><DEDENT>if setting == '<STR_LIT>':<EOL><INDENT>self._set_hostname(value)<EOL><DEDENT>elif setting == '<STR_LIT:port>':<EOL><INDENT>self._set_port(value)<EOL><DEDENT>elif setting == '<STR_LIT>':<EOL><INDENT>self._set_certificate_path(value)<EOL><DEDENT>elif setting == '<STR_LIT>':<EOL><INDENT>self._set_key_path(value)<EOL><DEDENT>elif setting == '<STR_LIT>':<EOL><INDENT>self._set_ca_path(value)<EOL><DEDENT>elif setting == '<STR_LIT>':<EOL><INDENT>self._set_auth_suite(value)<EOL><DEDENT>elif setting == '<STR_LIT>':<EOL><INDENT>self._set_policy_path(value)<EOL><DEDENT>elif setting == '<STR_LIT>':<EOL><INDENT>self._set_enable_tls_client_auth(value)<EOL><DEDENT>elif setting == '<STR_LIT>':<EOL><INDENT>self._set_tls_cipher_suites(value)<EOL><DEDENT>elif setting == '<STR_LIT>':<EOL><INDENT>self._set_logging_level(value)<EOL><DEDENT>else:<EOL><INDENT>self._set_database_path(value)<EOL><DEDENT>

Set a specific setting value.

This will overwrite the current setting value for the specified
setting.

Args:
    setting (string): The name of the setting to set (e.g.,
        'certificate_path', 'hostname'). Required.
    value (misc): The value of the setting to set. Type varies based
        on setting. Required.
Raises:
    ConfigurationError: Raised if the setting is not supported or if
        the setting value is invalid.


Load configuration settings from the file pointed to by path.

This will overwrite all current setting values.

Args:
    path (string): The path to the configuration file containing
        the settings to load. Required.
Raises:
    ConfigurationError: Raised if the path does not point to an
        existing file or if a setting value is invalid.


self.always_has_value = always_has_value<EOL>self.initially_set_by = initially_set_by<EOL>self.modifiable_by_server = modifiable_by_server<EOL>self.modifiable_by_client = modifiable_by_client<EOL>self.deletable_by_client = deletable_by_client<EOL>self.multiple_instances_permitted = multivalued<EOL>self.implicitly_set_by = implicitly_set_by<EOL>self.applies_to_object_types = applies_to_object_types<EOL>self.version_added = version_added<EOL>self.version_deprecated = version_deprecated<EOL>

Create an AttributeRuleSet.

Args:
    always_has_value (bool): A flag indicating whether or not this
        attribute is always set for a managed object. Required.
    initially_set_by (list): A list of strings indicating if the
        attribute can be initially set by the 'server' and/or the
        'client'. Required.
    modifiable_by_server (bool): A flag indicating whether the server
        can independently modify the value of the attribute without
        any prompting by the client. Required.
    modifiable_by_client (bool): A flag indicating whether the client
        can modify the value of the attribute. Required.
    deletable_by_client (bool): A flag indicating whether the client
        can delete the attribute from the managed object. Required.
    multivalued (bool): A flag indicating whether or not a managed
        object can have multiple instances of the attribute set at
        the same time. Required.
    implicitly_set_by (list): A list of Operation enumerations
        detailing which server operations are allowed to set the
        value of the attribute without direct instruction by the
        client.Required.
    applies_to_object_types (list): A list of ObjectType enumerations
        detailing which managed object types the attribute applies to.
    version_added (ProtocolVersion): The KMIP version in which support
        for the attribute was added. Required.
    version_deprecated (ProtocolVersion): The KMIP version in which
        support for the attribute was deprecated. Optional, defaults
        to None.


Create an AttributePolicy.

Args:
    version (ProtocolVersion): The KMIP protocol version under which
        this set of attribute policies should be evaluated. Required.


if attribute not in self._attribute_rule_sets.keys():<EOL><INDENT>return False<EOL><DEDENT>rule_set = self._attribute_rule_sets.get(attribute)<EOL>if self._version >= rule_set.version_added:<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Check if the attribute is supported by the current KMIP version.

Args:
    attribute (string): The name of the attribute
        (e.g., 'Cryptographic Algorithm'). Required.
Returns:
    bool: True if the attribute is supported by the current KMIP
        version. False otherwise.


rule_set = self._attribute_rule_sets.get(attribute)<EOL>if rule_set.version_deprecated:<EOL><INDENT>if self._version >= rule_set.version_deprecated:<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Check if the attribute is deprecated by the current KMIP version.

Args:
    attribute (string): The name of the attribute
        (e.g., 'Unique Identifier'). Required.


def is_attribute_applicable_to_object_type(self, attribute, object_type):

<EOL>rule_set = self._attribute_rule_sets.get(attribute)<EOL>if object_type in rule_set.applies_to_object_types:<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Check if the attribute is supported by the given object type.

Args:
    attribute (string): The name of the attribute (e.g., 'Name').
        Required.
    object_type (ObjectType): An ObjectType enumeration
        (e.g., ObjectType.SYMMETRIC_KEY). Required.
Returns:
    bool: True if the attribute is applicable to the object type.
        False otherwise.


<EOL>rule_set = self._attribute_rule_sets.get(attribute)<EOL>return rule_set.multiple_instances_permitted<EOL>

Check if the attribute is allowed to have multiple instances.

Args:
    attribute (string): The name of the attribute
        (e.g., 'State'). Required.


return self._attribute_rule_sets.keys()<EOL>

Get a list of all supported attribute names.

Returns:
    list: A list of string attribute names.


def __init__(self, policies=None, database_path=None):

self._logger = logging.getLogger('<STR_LIT>')<EOL>self._cryptography_engine = engine.CryptographyEngine()<EOL>self.database_path = '<STR_LIT>'.format(database_path)<EOL>if not database_path:<EOL><INDENT>self.database_path = '<STR_LIT>'<EOL><DEDENT>self._data_store = sqlalchemy.create_engine(<EOL>self.database_path,<EOL>echo=False,<EOL>connect_args={'<STR_LIT>': False}<EOL>)<EOL>sqltypes.Base.metadata.create_all(self._data_store)<EOL>self._data_store_session_factory = sqlalchemy.orm.sessionmaker(<EOL>bind=self._data_store<EOL>)<EOL>self._lock = threading.RLock()<EOL>self._id_placeholder = None<EOL>self._protocol_versions = [<EOL>contents.ProtocolVersion(<NUM_LIT:1>, <NUM_LIT:4>),<EOL>contents.ProtocolVersion(<NUM_LIT:1>, <NUM_LIT:3>),<EOL>contents.ProtocolVersion(<NUM_LIT:1>, <NUM_LIT:2>),<EOL>contents.ProtocolVersion(<NUM_LIT:1>, <NUM_LIT:1>),<EOL>contents.ProtocolVersion(<NUM_LIT:1>, <NUM_LIT:0>)<EOL>]<EOL>self.default_protocol_version = self._protocol_versions[<NUM_LIT:2>]<EOL>self._protocol_version = self._protocol_versions[<NUM_LIT:2>]<EOL>self._object_map = {<EOL>enums.ObjectType.CERTIFICATE: objects.X509Certificate,<EOL>enums.ObjectType.SYMMETRIC_KEY: objects.SymmetricKey,<EOL>enums.ObjectType.PUBLIC_KEY: objects.PublicKey,<EOL>enums.ObjectType.PRIVATE_KEY: objects.PrivateKey,<EOL>enums.ObjectType.SPLIT_KEY: None,<EOL>enums.ObjectType.TEMPLATE: None,<EOL>enums.ObjectType.SECRET_DATA: objects.SecretData,<EOL>enums.ObjectType.OPAQUE_DATA: objects.OpaqueObject<EOL>}<EOL>self._attribute_policy = policy.AttributePolicy(self._protocol_version)<EOL>self._operation_policies = policies<EOL>self._client_identity = [None, None]<EOL>

Create a KmipEngine.

Args:
    policy_path (string): The path to the filesystem directory
        containing PyKMIP server operation policy JSON files.
        Optional, defaults to None.
    database_path (string): The path to the SQLite database file
        used to store all server data. Optional, defaults to None.
        If none, database path defaults to '/tmp/pykmip.database'.


@_synchronize<EOL><INDENT>def process_request(self, request, credential=None):<DEDENT>

self._client_identity = [None, None]<EOL>header = request.request_header<EOL>self._set_protocol_version(header.protocol_version)<EOL>max_response_size = None<EOL>if header.maximum_response_size:<EOL><INDENT>max_response_size = header.maximum_response_size.value<EOL><DEDENT>now = int(time.time())<EOL>if header.time_stamp:<EOL><INDENT>then = header.time_stamp.value<EOL>if (now >= then) and ((now - then) < <NUM_LIT>):<EOL><INDENT>self._logger.info("<STR_LIT>".format(<EOL>time.strftime(<EOL>"<STR_LIT>",<EOL>time.gmtime(then)<EOL>)<EOL>))<EOL><DEDENT>else:<EOL><INDENT>if now < then:<EOL><INDENT>self._logger.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>then,<EOL>now<EOL>)<EOL>)<EOL>raise exceptions.InvalidMessage(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>else:<EOL><INDENT>self._logger.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(then, now)<EOL>)<EOL>raise exceptions.InvalidMessage(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>self._logger.info("<STR_LIT>".format(<EOL>time.strftime(<EOL>"<STR_LIT>",<EOL>time.gmtime(now)<EOL>)<EOL>))<EOL><DEDENT>self.is_asynchronous = False<EOL>if header.asynchronous_indicator is not None:<EOL><INDENT>self.is_asynchronous = header.asynchronous_indicator.value<EOL><DEDENT>if self.is_asynchronous:<EOL><INDENT>raise exceptions.InvalidMessage(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if header.authentication:<EOL><INDENT>if header.authentication.credentials:<EOL><INDENT>auth_credentials = header.authentication.credentials[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>auth_credentials = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>auth_credentials = None<EOL><DEDENT>self._verify_credential(auth_credentials, credential)<EOL>batch_error_option = enums.BatchErrorContinuationOption.STOP<EOL>if header.batch_error_cont_option is not None:<EOL><INDENT>batch_error_option = header.batch_error_cont_option.value<EOL><DEDENT>if batch_error_option == enums.BatchErrorContinuationOption.UNDO:<EOL><INDENT>raise exceptions.InvalidMessage(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>batch_order_option = False<EOL>if header.batch_order_option:<EOL><INDENT>batch_order_option = header.batch_order_option.value<EOL><DEDENT>response_batch = self._process_batch(<EOL>request.batch_items,<EOL>batch_error_option,<EOL>batch_order_option<EOL>)<EOL>response = self._build_response(<EOL>header.protocol_version,<EOL>response_batch<EOL>)<EOL>return response, max_response_size, header.protocol_version<EOL>

Process a KMIP request message.

This routine is the main driver of the KmipEngine. It breaks apart and
processes the request header, handles any message errors that may
result, and then passes the set of request batch items on for
processing. This routine is thread-safe, allowing multiple client
connections to use the same KmipEngine.

Args:
    request (RequestMessage): The request message containing the batch
        items to be processed.
    credential (string): Identifying information about the client
        obtained from the client certificate. Optional, defaults to
        None.

Returns:
    ResponseMessage: The response containing all of the results from
        the request batch items.


def build_error_response(self, version, reason, message):

Build a simple ResponseMessage with a single error result.

Args:
    version (ProtocolVersion): The protocol version the response
        should be addressed with.
    reason (ResultReason): An enumeration classifying the type of
        error occurred.
    message (str): A string providing additional information about
        the error.

Returns:
    ResponseMessage: The simple ResponseMessage containing a
        single error result.


attributes = {}<EOL>if len(template_attribute.names) > <NUM_LIT:0>:<EOL><INDENT>raise exceptions.ItemNotFound(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>for attribute in template_attribute.attributes:<EOL><INDENT>name = attribute.attribute_name.value<EOL>if not self._attribute_policy.is_attribute_supported(name):<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>".format(name)<EOL>)<EOL><DEDENT>if self._attribute_policy.is_attribute_multivalued(name):<EOL><INDENT>values = attributes.get(name, list())<EOL>if (not attribute.attribute_index) and len(values) > <NUM_LIT:0>:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>values.append(attribute.attribute_value)<EOL>attributes.update([(name, values)])<EOL><DEDENT>else:<EOL><INDENT>if attribute.attribute_index:<EOL><INDENT>if attribute.attribute_index.value != <NUM_LIT:0>:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>value = attributes.get(name, None)<EOL>if value:<EOL><INDENT>raise exceptions.IndexOutOfBounds(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(name)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>attributes.update([(name, attribute.attribute_value)])<EOL><DEDENT><DEDENT><DEDENT>return attributes<EOL>

Given a kmip.core TemplateAttribute object, extract the attribute
value data into a usable dictionary format.


def _get_attributes_from_managed_object(self, managed_object, attr_names):

attr_factory = attribute_factory.AttributeFactory()<EOL>retrieved_attributes = list()<EOL>if not attr_names:<EOL><INDENT>attr_names = self._attribute_policy.get_all_attribute_names()<EOL><DEDENT>for attribute_name in attr_names:<EOL><INDENT>object_type = managed_object._object_type<EOL>if not self._attribute_policy.is_attribute_supported(<EOL>attribute_name<EOL>):<EOL><INDENT>continue<EOL><DEDENT>if self._attribute_policy.is_attribute_applicable_to_object_type(<EOL>attribute_name,<EOL>object_type<EOL>):<EOL><INDENT>try:<EOL><INDENT>attribute_value = self._get_attribute_from_managed_object(<EOL>managed_object,<EOL>attribute_name<EOL>)<EOL><DEDENT>except Exception:<EOL><INDENT>attribute_value = None<EOL><DEDENT>if attribute_value is not None:<EOL><INDENT>if self._attribute_policy.is_attribute_multivalued(<EOL>attribute_name<EOL>):<EOL><INDENT>for count, value in enumerate(attribute_value):<EOL><INDENT>attribute = attr_factory.create_attribute(<EOL>enums.AttributeType(attribute_name),<EOL>value,<EOL>count<EOL>)<EOL>retrieved_attributes.append(attribute)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>attribute = attr_factory.create_attribute(<EOL>enums.AttributeType(attribute_name),<EOL>attribute_value<EOL>)<EOL>retrieved_attributes.append(attribute)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return retrieved_attributes<EOL>

Given a kmip.pie object and a list of attribute names, attempt to get
all of the existing attribute values from the object.


def _get_attribute_from_managed_object(self, managed_object, attr_name):

if attr_name == '<STR_LIT>':<EOL><INDENT>return str(managed_object.unique_identifier)<EOL><DEDENT>elif attr_name == '<STR_LIT:Name>':<EOL><INDENT>names = list()<EOL>for name in managed_object.names:<EOL><INDENT>name = attributes.Name(<EOL>attributes.Name.NameValue(name),<EOL>attributes.Name.NameType(<EOL>enums.NameType.UNINTERPRETED_TEXT_STRING<EOL>)<EOL>)<EOL>names.append(name)<EOL><DEDENT>return names<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return managed_object._object_type<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return managed_object.cryptographic_algorithm<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return managed_object.cryptographic_length<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return managed_object.certificate_type<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return managed_object.operation_policy_name<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return managed_object.cryptographic_usage_masks<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return managed_object.state<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return managed_object.initial_date<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>elif attr_name == '<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Get the attribute value from the kmip.pie managed object.


def _set_attributes_on_managed_object(self, managed_object, attributes):

for attribute_name, attribute_value in six.iteritems(attributes):<EOL><INDENT>object_type = managed_object._object_type<EOL>if self._attribute_policy.is_attribute_applicable_to_object_type(<EOL>attribute_name,<EOL>object_type):<EOL><INDENT>self._set_attribute_on_managed_object(<EOL>managed_object,<EOL>(attribute_name, attribute_value)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>name = object_type.name<EOL>raise exceptions.InvalidField(<EOL>"<STR_LIT>".format(<EOL>attribute_name,<EOL>'<STR_LIT>'.join([x.capitalize() for x in name.split('<STR_LIT:_>')])<EOL>)<EOL>)<EOL><DEDENT><DEDENT>

Given a kmip.pie object and a dictionary of attributes, attempt to set
the attribute values on the object.


def _set_attribute_on_managed_object(self, managed_object, attribute):

attribute_name = attribute[<NUM_LIT:0>]<EOL>attribute_value = attribute[<NUM_LIT:1>]<EOL>if self._attribute_policy.is_attribute_multivalued(attribute_name):<EOL><INDENT>if attribute_name == '<STR_LIT:Name>':<EOL><INDENT>managed_object.names.extend(<EOL>[x.name_value.value for x in attribute_value]<EOL>)<EOL>for name in managed_object.names:<EOL><INDENT>if managed_object.names.count(name) > <NUM_LIT:1>:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>".format(attribute_name)<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>field = None<EOL>value = attribute_value.value<EOL>if attribute_name == '<STR_LIT>':<EOL><INDENT>field = '<STR_LIT>'<EOL><DEDENT>elif attribute_name == '<STR_LIT>':<EOL><INDENT>field = '<STR_LIT>'<EOL><DEDENT>elif attribute_name == '<STR_LIT>':<EOL><INDENT>field = '<STR_LIT>'<EOL>value = list()<EOL>for e in enums.CryptographicUsageMask:<EOL><INDENT>if e.value & attribute_value.value:<EOL><INDENT>value.append(e)<EOL><DEDENT><DEDENT><DEDENT>elif attribute_name == '<STR_LIT>':<EOL><INDENT>field = '<STR_LIT>'<EOL><DEDENT>if field:<EOL><INDENT>existing_value = getattr(managed_object, field)<EOL>if existing_value:<EOL><INDENT>if existing_value != value:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>".format(<EOL>attribute_name<EOL>)<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>setattr(managed_object, field, value)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>".format(attribute_name)<EOL>)<EOL><DEDENT><DEDENT>

Set the attribute value on the kmip.pie managed object.


def get_relevant_policy_section(self, policy_name, group=None):

policy_bundle = self._operation_policies.get(policy_name)<EOL>if not policy_bundle:<EOL><INDENT>self._logger.warning(<EOL>"<STR_LIT>".format(policy_name)<EOL>)<EOL>return None<EOL><DEDENT>if group:<EOL><INDENT>groups_policy_bundle = policy_bundle.get('<STR_LIT>')<EOL>if not groups_policy_bundle:<EOL><INDENT>self._logger.debug(<EOL>"<STR_LIT>".format(<EOL>policy_name<EOL>)<EOL>)<EOL>return None<EOL><DEDENT>else:<EOL><INDENT>group_policy = groups_policy_bundle.get(group)<EOL>if not group_policy:<EOL><INDENT>self._logger.debug(<EOL>"<STR_LIT>".format(<EOL>policy_name,<EOL>group<EOL>)<EOL>)<EOL>return None<EOL><DEDENT>else:<EOL><INDENT>return group_policy<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>return policy_bundle.get('<STR_LIT>')<EOL><DEDENT>

Look up the policy corresponding to the provided policy name and
group (optional). Log any issues found during the look up.


policy_section = self.get_relevant_policy_section(<EOL>policy_name,<EOL>session_group<EOL>)<EOL>if policy_section is None:<EOL><INDENT>return False<EOL><DEDENT>object_policy = policy_section.get(object_type)<EOL>if not object_policy:<EOL><INDENT>self._logger.warning(<EOL>"<STR_LIT>".format(<EOL>policy_name,<EOL>self._get_enum_string(object_type)<EOL>)<EOL>)<EOL>return False<EOL><DEDENT>operation_object_policy = object_policy.get(operation)<EOL>if not operation_object_policy:<EOL><INDENT>self._logger.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>policy_name,<EOL>self._get_enum_string(operation),<EOL>self._get_enum_string(object_type)<EOL>)<EOL>)<EOL>return False<EOL><DEDENT>if operation_object_policy == enums.Policy.ALLOW_ALL:<EOL><INDENT>return True<EOL><DEDENT>elif operation_object_policy == enums.Policy.ALLOW_OWNER:<EOL><INDENT>if session_user == object_owner:<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>elif operation_object_policy == enums.Policy.DISALLOW_ALL:<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>

Determine if object access is allowed for the provided policy and
session settings.


self.logger = logging.getLogger('<STR_LIT>')<EOL>self._symmetric_key_algorithms = {<EOL>enums.CryptographicAlgorithm.TRIPLE_DES: algorithms.TripleDES,<EOL>enums.CryptographicAlgorithm.AES:        algorithms.AES,<EOL>enums.CryptographicAlgorithm.BLOWFISH:   algorithms.Blowfish,<EOL>enums.CryptographicAlgorithm.CAMELLIA:   algorithms.Camellia,<EOL>enums.CryptographicAlgorithm.CAST5:      algorithms.CAST5,<EOL>enums.CryptographicAlgorithm.IDEA:       algorithms.IDEA,<EOL>enums.CryptographicAlgorithm.RC4:        algorithms.ARC4<EOL>}<EOL>self._asymmetric_key_algorithms = {<EOL>enums.CryptographicAlgorithm.RSA: self._create_rsa_key_pair<EOL>}<EOL>self._hash_algorithms = {<EOL>enums.CryptographicAlgorithm.HMAC_SHA1: hashes.SHA1,<EOL>enums.CryptographicAlgorithm.HMAC_SHA224: hashes.SHA224,<EOL>enums.CryptographicAlgorithm.HMAC_SHA256: hashes.SHA256,<EOL>enums.CryptographicAlgorithm.HMAC_SHA384: hashes.SHA384,<EOL>enums.CryptographicAlgorithm.HMAC_SHA512: hashes.SHA512,<EOL>enums.CryptographicAlgorithm.HMAC_MD5: hashes.MD5<EOL>}<EOL>self._encryption_hash_algorithms = {<EOL>enums.HashingAlgorithm.MD5:     hashes.MD5,<EOL>enums.HashingAlgorithm.SHA_1:   hashes.SHA1,<EOL>enums.HashingAlgorithm.SHA_224: hashes.SHA224,<EOL>enums.HashingAlgorithm.SHA_256: hashes.SHA256,<EOL>enums.HashingAlgorithm.SHA_384: hashes.SHA384,<EOL>enums.HashingAlgorithm.SHA_512: hashes.SHA512<EOL>}<EOL>self._modes = {<EOL>enums.BlockCipherMode.CBC: modes.CBC,<EOL>enums.BlockCipherMode.ECB: modes.ECB,<EOL>enums.BlockCipherMode.OFB: modes.OFB,<EOL>enums.BlockCipherMode.CFB: modes.CFB,<EOL>enums.BlockCipherMode.CTR: modes.CTR<EOL>}<EOL>self._asymmetric_padding_methods = {<EOL>enums.PaddingMethod.OAEP:     asymmetric_padding.OAEP,<EOL>enums.PaddingMethod.PKCS1v15: asymmetric_padding.PKCS1v15,<EOL>enums.PaddingMethod.PSS:      asymmetric_padding.PSS<EOL>}<EOL>self._symmetric_padding_methods = {<EOL>enums.PaddingMethod.ANSI_X923: symmetric_padding.ANSIX923,<EOL>enums.PaddingMethod.PKCS5:     symmetric_padding.PKCS7<EOL>}<EOL>self._no_mode_needed = [<EOL>enums.CryptographicAlgorithm.RC4<EOL>]<EOL>self._no_padding_needed = [<EOL>enums.BlockCipherMode.CTR,<EOL>enums.BlockCipherMode.OFB,<EOL>enums.BlockCipherMode.CFB,<EOL>enums.BlockCipherMode.GCM<EOL>]<EOL>self._digital_signature_algorithms = {<EOL>enums.DigitalSignatureAlgorithm.MD5_WITH_RSA_ENCRYPTION:<EOL>(hashes.MD5, enums.CryptographicAlgorithm.RSA),<EOL>enums.DigitalSignatureAlgorithm.SHA1_WITH_RSA_ENCRYPTION:<EOL>(hashes.SHA1, enums.CryptographicAlgorithm.RSA),<EOL>enums.DigitalSignatureAlgorithm.SHA224_WITH_RSA_ENCRYPTION:<EOL>(hashes.SHA224, enums.CryptographicAlgorithm.RSA),<EOL>enums.DigitalSignatureAlgorithm.SHA256_WITH_RSA_ENCRYPTION:<EOL>(hashes.SHA256, enums.CryptographicAlgorithm.RSA),<EOL>enums.DigitalSignatureAlgorithm.SHA384_WITH_RSA_ENCRYPTION:<EOL>(hashes.SHA384, enums.CryptographicAlgorithm.RSA),<EOL>enums.DigitalSignatureAlgorithm.SHA512_WITH_RSA_ENCRYPTION:<EOL>(hashes.SHA512, enums.CryptographicAlgorithm.RSA)<EOL>}<EOL>


def create_symmetric_key(self, algorithm, length):

if algorithm not in self._symmetric_key_algorithms.keys():<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(algorithm)<EOL>)<EOL><DEDENT>cryptography_algorithm = self._symmetric_key_algorithms.get(algorithm)<EOL>if length not in cryptography_algorithm.key_sizes:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>length, algorithm.name<EOL>)<EOL>)<EOL><DEDENT>self.logger.info(<EOL>"<STR_LIT>".format(<EOL>algorithm.name, length<EOL>)<EOL>)<EOL>key_bytes = os.urandom(length // <NUM_LIT:8>)<EOL>try:<EOL><INDENT>cryptography_algorithm(key_bytes)<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.logger.exception(e)<EOL>raise exceptions.CryptographicFailure(<EOL>"<STR_LIT>")<EOL><DEDENT>return {'<STR_LIT:value>': key_bytes, '<STR_LIT>': enums.KeyFormatType.RAW}<EOL>

Create a symmetric key.

Args:
    algorithm(CryptographicAlgorithm): An enumeration specifying the
        algorithm for which the created key will be compliant.
    length(int): The length of the key to be created. This value must
        be compliant with the constraints of the provided algorithm.

Returns:
    dict: A dictionary containing the key data, with the following
        key/value fields:
        * value - the bytes of the key
        * format - a KeyFormatType enumeration for the bytes format

Raises:
    InvalidField: Raised when the algorithm is unsupported or the
        length is incompatible with the algorithm.
    CryptographicFailure: Raised when the key generation process
        fails.

Example:
    >>> engine = CryptographyEngine()
    >>> key = engine.create_symmetric_key(
    ...     CryptographicAlgorithm.AES, 256)


def create_asymmetric_key_pair(self, algorithm, length):

if algorithm not in self._asymmetric_key_algorithms.keys():<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(algorithm)<EOL>)<EOL><DEDENT>engine_method = self._asymmetric_key_algorithms.get(algorithm)<EOL>return engine_method(length)<EOL>

Create an asymmetric key pair.

Args:
    algorithm(CryptographicAlgorithm): An enumeration specifying the
        algorithm for which the created keys will be compliant.
    length(int): The length of the keys to be created. This value must
        be compliant with the constraints of the provided algorithm.

Returns:
    dict: A dictionary containing the public key data, with at least
        the following key/value fields:
        * value - the bytes of the key
        * format - a KeyFormatType enumeration for the bytes format
    dict: A dictionary containing the private key data, identical in
        structure to the one above.

Raises:
    InvalidField: Raised when the algorithm is unsupported or the
        length is incompatible with the algorithm.
    CryptographicFailure: Raised when the key generation process
        fails.

Example:
    >>> engine = CryptographyEngine()
    >>> key = engine.create_asymmetric_key(
    ...     CryptographicAlgorithm.RSA, 2048)


mac_data = None<EOL>if algorithm in self._hash_algorithms.keys():<EOL><INDENT>self.logger.info(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(algorithm.name)<EOL>)<EOL>hash_algorithm = self._hash_algorithms.get(algorithm)<EOL>try:<EOL><INDENT>h = hmac.HMAC(key, hash_algorithm(), backend=default_backend())<EOL>h.update(data)<EOL>mac_data = h.finalize()<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.logger.exception(e)<EOL>raise exceptions.CryptographicFailure(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>elif algorithm in self._symmetric_key_algorithms.keys():<EOL><INDENT>self.logger.info(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(algorithm.name)<EOL>)<EOL>cipher_algorithm = self._symmetric_key_algorithms.get(algorithm)<EOL>try:<EOL><INDENT>c = cmac.CMAC(cipher_algorithm(key), backend=default_backend())<EOL>c.update(data)<EOL>mac_data = c.finalize()<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise exceptions.CryptographicFailure(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(algorithm)<EOL>)<EOL><DEDENT>return mac_data<EOL>

Generate message authentication code.

Args:
    algorithm(CryptographicAlgorithm): An enumeration specifying the
        algorithm for which the MAC operation will use.
    key(bytes): secret key used in the MAC operation
    data(bytes): The data to be MACed.

Returns:
    bytes: The MACed data

Raises:
    InvalidField: Raised when the algorithm is unsupported or the
        length is incompatible with the algorithm.
    CryptographicFailure: Raised when the key generation process
        fails.

Example:
    >>> engine = CryptographyEngine()
    >>> mac_data = engine.mac(
    ...     CryptographicAlgorithm.HMAC-SHA256, b'\x01\x02\x03\x04',
    ...     b'\x05\x06\x07\x08')


Encrypt data using symmetric or asymmetric encryption.

Args:
    encryption_algorithm (CryptographicAlgorithm): An enumeration
        specifying the encryption algorithm to use for encryption.
    encryption_key (bytes): The bytes of the encryption key to use for
        encryption.
    plain_text (bytes): The bytes to be encrypted.
    cipher_mode (BlockCipherMode): An enumeration specifying the
        block cipher mode to use with the encryption algorithm.
        Required in the general case. Optional if the encryption
        algorithm is RC4 (aka ARC4). If optional, defaults to None.
    padding_method (PaddingMethod): An enumeration specifying the
        padding method to use on the data before encryption. Required
        if the cipher mode is for block ciphers (e.g., CBC, ECB).
        Optional otherwise, defaults to None.
    iv_nonce (bytes): The IV/nonce value to use to initialize the mode
        of the encryption algorithm. Optional, defaults to None. If
        required and not provided, it will be autogenerated and
        returned with the cipher text.
    hashing_algorithm (HashingAlgorithm): An enumeration specifying
        the hashing algorithm to use with the encryption algorithm,
        if needed. Required for OAEP-based asymmetric encryption.
        Optional, defaults to None.

Returns:
    dict: A dictionary containing the encrypted data, with at least
        the following key/value fields:
        * cipher_text - the bytes of the encrypted data
        * iv_nonce - the bytes of the IV/counter/nonce used if it
            was needed by the encryption scheme and if it was
            automatically generated for the encryption

Raises:
    InvalidField: Raised when the algorithm is unsupported or the
        length is incompatible with the algorithm.
    CryptographicFailure: Raised when the key generation process
        fails.

Example:
    >>> engine = CryptographyEngine()
    >>> result = engine.encrypt(
    ...     encryption_algorithm=CryptographicAlgorithm.AES,
    ...     encryption_key=(
    ...         b'\xF3\x96\xE7\x1C\xCF\xCD\xEC\x1F'
    ...         b'\xFC\xE2\x8E\xA6\xF8\x74\x28\xB0'
    ...     ),
    ...     plain_text=(
    ...         b'\x00\x01\x02\x03\x04\x05\x06\x07'
    ...         b'\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F'
    ...     ),
    ...     cipher_mode=BlockCipherMode.CBC,
    ...     padding_method=PaddingMethod.ANSI_X923,
    ... )
    >>> result.get('cipher_text')
    b'\x18[\xb9y\x1bL\xd1\x8f\x9a\xa0e\x02b\xa3=c'
    >>> result.iv_counter_nonce
    b'8qA\x05\xc4\x86\x03\xd9=\xef\xdf\xb8ke\x9a\xa2'


<EOL>algorithm = self._symmetric_key_algorithms.get(<EOL>encryption_algorithm,<EOL>None<EOL>)<EOL>if algorithm is None:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(encryption_algorithm)<EOL>)<EOL><DEDENT>try:<EOL><INDENT>algorithm = algorithm(encryption_key)<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.logger.exception(e)<EOL>raise exceptions.CryptographicFailure(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>return_iv_nonce = False<EOL>if encryption_algorithm == enums.CryptographicAlgorithm.RC4:<EOL><INDENT>mode = None<EOL><DEDENT>else:<EOL><INDENT>if cipher_mode is None:<EOL><INDENT>raise exceptions.InvalidField("<STR_LIT>")<EOL><DEDENT>mode = self._modes.get(cipher_mode, None)<EOL>if mode is None:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>".format(<EOL>cipher_mode<EOL>)<EOL>)<EOL><DEDENT>if hasattr(mode, '<STR_LIT>') orhasattr(mode, '<STR_LIT>'):<EOL><INDENT>if iv_nonce is None:<EOL><INDENT>iv_nonce = os.urandom(algorithm.block_size // <NUM_LIT:8>)<EOL>return_iv_nonce = True<EOL><DEDENT>mode = mode(iv_nonce)<EOL><DEDENT>else:<EOL><INDENT>mode = mode()<EOL><DEDENT><DEDENT>if cipher_mode in [<EOL>enums.BlockCipherMode.CBC,<EOL>enums.BlockCipherMode.ECB<EOL>]:<EOL><INDENT>plain_text = self._handle_symmetric_padding(<EOL>self._symmetric_key_algorithms.get(encryption_algorithm),<EOL>plain_text,<EOL>padding_method<EOL>)<EOL><DEDENT>cipher = ciphers.Cipher(algorithm, mode, backend=default_backend())<EOL>encryptor = cipher.encryptor()<EOL>cipher_text = encryptor.update(plain_text) + encryptor.finalize()<EOL>if return_iv_nonce:<EOL><INDENT>return {<EOL>'<STR_LIT>': cipher_text,<EOL>'<STR_LIT>': iv_nonce<EOL>}<EOL><DEDENT>else:<EOL><INDENT>return {'<STR_LIT>': cipher_text}<EOL><DEDENT>

Encrypt data using symmetric encryption.

Args:
    encryption_algorithm (CryptographicAlgorithm): An enumeration
        specifying the symmetric encryption algorithm to use for
        encryption.
    encryption_key (bytes): The bytes of the symmetric key to use for
        encryption.
    plain_text (bytes): The bytes to be encrypted.
    cipher_mode (BlockCipherMode): An enumeration specifying the
        block cipher mode to use with the encryption algorithm.
        Required in the general case. Optional if the encryption
        algorithm is RC4 (aka ARC4). If optional, defaults to None.
    padding_method (PaddingMethod): An enumeration specifying the
        padding method to use on the data before encryption. Required
        if the cipher mode is for block ciphers (e.g., CBC, ECB).
        Optional otherwise, defaults to None.
    iv_nonce (bytes): The IV/nonce value to use to initialize the mode
        of the encryption algorithm. Optional, defaults to None. If
        required and not provided, it will be autogenerated and
        returned with the cipher text.

Returns:
    dict: A dictionary containing the encrypted data, with at least
        the following key/value fields:
        * cipher_text - the bytes of the encrypted data
        * iv_nonce - the bytes of the IV/counter/nonce used if it
            was needed by the encryption scheme and if it was
            automatically generated for the encryption

Raises:
    InvalidField: Raised when the algorithm is unsupported or the
        encryption key is incompatible with the algorithm.
    CryptographicFailure: Raised when the key generation process
        fails.


if encryption_algorithm == enums.CryptographicAlgorithm.RSA:<EOL><INDENT>if padding_method == enums.PaddingMethod.OAEP:<EOL><INDENT>hash_algorithm = self._encryption_hash_algorithms.get(<EOL>hashing_algorithm<EOL>)<EOL>if hash_algorithm is None:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(hashing_algorithm)<EOL>)<EOL><DEDENT>padding_method = asymmetric_padding.OAEP(<EOL>mgf=asymmetric_padding.MGF1(<EOL>algorithm=hash_algorithm()<EOL>),<EOL>algorithm=hash_algorithm(),<EOL>label=None<EOL>)<EOL><DEDENT>elif padding_method == enums.PaddingMethod.PKCS1v15:<EOL><INDENT>padding_method = asymmetric_padding.PKCS1v15()<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(padding_method)<EOL>)<EOL><DEDENT>backend = default_backend()<EOL>try:<EOL><INDENT>public_key = backend.load_der_public_key(encryption_key)<EOL><DEDENT>except Exception:<EOL><INDENT>try:<EOL><INDENT>public_key = backend.load_pem_public_key(encryption_key)<EOL><DEDENT>except Exception:<EOL><INDENT>raise exceptions.CryptographicFailure(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>cipher_text = public_key.encrypt(<EOL>plain_text,<EOL>padding_method<EOL>)<EOL>return {'<STR_LIT>': cipher_text}<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(encryption_algorithm)<EOL>)<EOL><DEDENT>

Encrypt data using asymmetric encryption.

Args:
    encryption_algorithm (CryptographicAlgorithm): An enumeration
        specifying the asymmetric encryption algorithm to use for
        encryption. Required.
    encryption_key (bytes): The bytes of the public key to use for
        encryption. Required.
    plain_text (bytes): The bytes to be encrypted. Required.
    padding_method (PaddingMethod): An enumeration specifying the
        padding method to use with the asymmetric encryption
        algorithm. Required.
    hashing_algorithm (HashingAlgorithm): An enumeration specifying
        the hashing algorithm to use with the encryption padding
        method. Required, if the padding method is OAEP. Optional
        otherwise, defaults to None.

Returns:
    dict: A dictionary containing the encrypted data, with at least
        the following key/value field:
        * cipher_text - the bytes of the encrypted data

Raises:
    InvalidField: Raised when the algorithm is unsupported or the
        length is incompatible with the algorithm.
    CryptographicFailure: Raised when the key generation process
        fails.


Decrypt data using symmetric decryption.

Args:
    decryption_algorithm (CryptographicAlgorithm): An enumeration
        specifying the symmetric decryption algorithm to use for
        decryption.
    decryption_key (bytes): The bytes of the symmetric key to use for
        decryption.
    cipher_text (bytes): The bytes to be decrypted.
    cipher_mode (BlockCipherMode): An enumeration specifying the
        block cipher mode to use with the decryption algorithm.
        Required in the general case. Optional if the decryption
        algorithm is RC4 (aka ARC4). If optional, defaults to None.
    padding_method (PaddingMethod): An enumeration specifying the
        padding method to use on the data after decryption. Required
        if the cipher mode is for block ciphers (e.g., CBC, ECB).
        Optional otherwise, defaults to None.
    iv_nonce (bytes): The IV/nonce value to use to initialize the mode
        of the decryption algorithm. Optional, defaults to None.
    hashing_algorithm (HashingAlgorithm): An enumeration specifying
        the hashing algorithm to use with the decryption algorithm,
        if needed. Required for OAEP-based asymmetric decryption.
        Optional, defaults to None.

Returns:
    bytes: the bytes of the decrypted data

Raises:
    InvalidField: Raised when the algorithm is unsupported or the
        length is incompatible with the algorithm.
    CryptographicFailure: Raised when the key generation process
        fails.

Example:
    >>> engine = CryptographyEngine()
    >>> result = engine.decrypt(
    ...     decryption_algorithm=CryptographicAlgorithm.AES,
    ...     decryption_key=(
    ...         b'\xF3\x96\xE7\x1C\xCF\xCD\xEC\x1F'
    ...         b'\xFC\xE2\x8E\xA6\xF8\x74\x28\xB0'
    ...     ),
    ...     cipher_text=(
    ...         b'\x18\x5B\xB9\x79\x1B\x4C\xD1\x8F'
    ...         b'\x9A\xA0\x65\x02\x62\xA3\x3D\x63'
    ...     ),
    ...     cipher_mode=BlockCipherMode.CBC,
    ...     padding_method=PaddingMethod.ANSI_X923,
    ...     iv_nonce=(
    ...         b'\x38\x71\x41\x05\xC4\x86\x03\xD9'
    ...         b'\x3D\xEF\xDF\xB8\x6B\x65\x9A\xA2'
    ...     )
    ... )
    >>> result
    b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'


<EOL>algorithm = self._symmetric_key_algorithms.get(<EOL>decryption_algorithm,<EOL>None<EOL>)<EOL>if algorithm is None:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(decryption_algorithm)<EOL>)<EOL><DEDENT>try:<EOL><INDENT>algorithm = algorithm(decryption_key)<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.logger.exception(e)<EOL>raise exceptions.CryptographicFailure(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if decryption_algorithm == enums.CryptographicAlgorithm.RC4:<EOL><INDENT>mode = None<EOL><DEDENT>else:<EOL><INDENT>if cipher_mode is None:<EOL><INDENT>raise exceptions.InvalidField("<STR_LIT>")<EOL><DEDENT>mode = self._modes.get(cipher_mode, None)<EOL>if mode is None:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>".format(<EOL>cipher_mode<EOL>)<EOL>)<EOL><DEDENT>if hasattr(mode, '<STR_LIT>') orhasattr(mode, '<STR_LIT>'):<EOL><INDENT>if iv_nonce is None:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>mode = mode(iv_nonce)<EOL><DEDENT>else:<EOL><INDENT>mode = mode()<EOL><DEDENT><DEDENT>cipher = ciphers.Cipher(algorithm, mode, backend=default_backend())<EOL>decryptor = cipher.decryptor()<EOL>plain_text = decryptor.update(cipher_text) + decryptor.finalize()<EOL>if cipher_mode in [<EOL>enums.BlockCipherMode.CBC,<EOL>enums.BlockCipherMode.ECB<EOL>]:<EOL><INDENT>plain_text = self._handle_symmetric_padding(<EOL>self._symmetric_key_algorithms.get(decryption_algorithm),<EOL>plain_text,<EOL>padding_method,<EOL>undo_padding=True<EOL>)<EOL><DEDENT>return plain_text<EOL>

Decrypt data using symmetric decryption.

Args:
    decryption_algorithm (CryptographicAlgorithm): An enumeration
        specifying the symmetric decryption algorithm to use for
        decryption.
    decryption_key (bytes): The bytes of the symmetric key to use for
        decryption.
    cipher_text (bytes): The bytes to be decrypted.
    cipher_mode (BlockCipherMode): An enumeration specifying the
        block cipher mode to use with the decryption algorithm.
        Required in the general case. Optional if the decryption
        algorithm is RC4 (aka ARC4). If optional, defaults to None.
    padding_method (PaddingMethod): An enumeration specifying the
        padding method to use on the data after decryption. Required
        if the cipher mode is for block ciphers (e.g., CBC, ECB).
        Optional otherwise, defaults to None.
    iv_nonce (bytes): The IV/nonce value to use to initialize the mode
        of the decryption algorithm. Optional, defaults to None.

Returns:
    bytes: the bytes of the decrypted data

Raises:
    InvalidField: Raised when the algorithm is unsupported or the
        length is incompatible with the algorithm.
    CryptographicFailure: Raised when the key generation process
        fails.


if decryption_algorithm == enums.CryptographicAlgorithm.RSA:<EOL><INDENT>if padding_method == enums.PaddingMethod.OAEP:<EOL><INDENT>hash_algorithm = self._encryption_hash_algorithms.get(<EOL>hashing_algorithm<EOL>)<EOL>if hash_algorithm is None:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(hashing_algorithm)<EOL>)<EOL><DEDENT>padding_method = asymmetric_padding.OAEP(<EOL>mgf=asymmetric_padding.MGF1(<EOL>algorithm=hash_algorithm()<EOL>),<EOL>algorithm=hash_algorithm(),<EOL>label=None<EOL>)<EOL><DEDENT>elif padding_method == enums.PaddingMethod.PKCS1v15:<EOL><INDENT>padding_method = asymmetric_padding.PKCS1v15()<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(padding_method)<EOL>)<EOL><DEDENT>backend = default_backend()<EOL>try:<EOL><INDENT>private_key = backend.load_der_private_key(<EOL>decryption_key,<EOL>None<EOL>)<EOL><DEDENT>except Exception:<EOL><INDENT>try:<EOL><INDENT>private_key = backend.load_pem_private_key(<EOL>decryption_key,<EOL>None<EOL>)<EOL><DEDENT>except Exception:<EOL><INDENT>raise exceptions.CryptographicFailure(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>plain_text = private_key.decrypt(<EOL>cipher_text,<EOL>padding_method<EOL>)<EOL>return plain_text<EOL><DEDENT>else:<EOL><INDENT>raise exceptions.InvalidField(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(decryption_algorithm)<EOL>)<EOL><DEDENT>

Encrypt data using asymmetric decryption.

Args:
    decryption_algorithm (CryptographicAlgorithm): An enumeration
        specifying the asymmetric decryption algorithm to use for
        decryption. Required.
    decryption_key (bytes): The bytes of the private key to use for
        decryption. Required.
    cipher_text (bytes): The bytes to be decrypted. Required.
    padding_method (PaddingMethod): An enumeration specifying the
        padding method to use with the asymmetric decryption
        algorithm. Required.
    hashing_algorithm (HashingAlgorithm): An enumeration specifying
        the hashing algorithm to use with the decryption padding
        method. Required, if the padding method is OAEP. Optional
        otherwise, defaults to None.

Returns:
    dict: A dictionary containing the decrypted data, with at least
        the following key/value field:
        * plain_text - the bytes of the decrypted data

Raises:
    InvalidField: Raised when the algorithm is unsupported or the
        length is incompatible with the algorithm.
    CryptographicFailure: Raised when the key generation process
        fails.


def _create_rsa_key_pair(self, length, public_exponent=<NUM_LIT>):

self.logger.info(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>length, public_exponent<EOL>)<EOL>)<EOL>try:<EOL><INDENT>private_key = rsa.generate_private_key(<EOL>public_exponent=public_exponent,<EOL>key_size=length,<EOL>backend=default_backend())<EOL>public_key = private_key.public_key()<EOL>private_bytes = private_key.private_bytes(<EOL>serialization.Encoding.DER,<EOL>serialization.PrivateFormat.PKCS8,<EOL>serialization.NoEncryption())<EOL>public_bytes = public_key.public_bytes(<EOL>serialization.Encoding.DER,<EOL>serialization.PublicFormat.PKCS1)<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.logger.exception(e)<EOL>raise exceptions.CryptographicFailure(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>public_key = {<EOL>'<STR_LIT:value>': public_bytes,<EOL>'<STR_LIT>': enums.KeyFormatType.PKCS_1,<EOL>'<STR_LIT>': public_exponent<EOL>}<EOL>private_key = {<EOL>'<STR_LIT:value>': private_bytes,<EOL>'<STR_LIT>': enums.KeyFormatType.PKCS_8,<EOL>'<STR_LIT>': public_exponent<EOL>}<EOL>return public_key, private_key<EOL>

Create an RSA key pair.

Args:
    length(int): The length of the keys to be created. This value must
        be compliant with the constraints of the provided algorithm.
    public_exponent(int): The value of the public exponent needed to
        generate the keys. Usually a small Fermat prime number.
        Optional, defaults to 65537.

Returns:
    dict: A dictionary containing the public key data, with the
        following key/value fields:
        * value - the bytes of the key
        * format - a KeyFormatType enumeration for the bytes format
        * public_exponent - the public exponent integer
    dict: A dictionary containing the private key data, identical in
        structure to the one above.

Raises:
    CryptographicFailure: Raised when the key generation process
        fails.