partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
test
get_certificate_from_connection
Extract an X.509 certificate from a socket connection.
kmip/services/server/auth/utils.py
def get_certificate_from_connection(connection): """ Extract an X.509 certificate from a socket connection. """ certificate = connection.getpeercert(binary_form=True) if certificate: return x509.load_der_x509_certificate( certificate, backends.default_backend() ) return None
def get_certificate_from_connection(connection): """ Extract an X.509 certificate from a socket connection. """ certificate = connection.getpeercert(binary_form=True) if certificate: return x509.load_der_x509_certificate( certificate, backends.default_backend() ) return None
[ "Extract", "an", "X", ".", "509", "certificate", "from", "a", "socket", "connection", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/auth/utils.py#L22-L32
[ "def", "get_certificate_from_connection", "(", "connection", ")", ":", "certificate", "=", "connection", ".", "getpeercert", "(", "binary_form", "=", "True", ")", "if", "certificate", ":", "return", "x509", ".", "load_der_x509_certificate", "(", "certificate", ",", "backends", ".", "default_backend", "(", ")", ")", "return", "None" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
get_extended_key_usage_from_certificate
Given an X.509 certificate, extract and return the extendedKeyUsage extension.
kmip/services/server/auth/utils.py
def get_extended_key_usage_from_certificate(certificate): """ Given an X.509 certificate, extract and return the extendedKeyUsage extension. """ try: return certificate.extensions.get_extension_for_oid( x509.oid.ExtensionOID.EXTENDED_KEY_USAGE ).value except x509.ExtensionNotFound: return None
def get_extended_key_usage_from_certificate(certificate): """ Given an X.509 certificate, extract and return the extendedKeyUsage extension. """ try: return certificate.extensions.get_extension_for_oid( x509.oid.ExtensionOID.EXTENDED_KEY_USAGE ).value except x509.ExtensionNotFound: return None
[ "Given", "an", "X", ".", "509", "certificate", "extract", "and", "return", "the", "extendedKeyUsage", "extension", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/auth/utils.py#L35-L45
[ "def", "get_extended_key_usage_from_certificate", "(", "certificate", ")", ":", "try", ":", "return", "certificate", ".", "extensions", ".", "get_extension_for_oid", "(", "x509", ".", "oid", ".", "ExtensionOID", ".", "EXTENDED_KEY_USAGE", ")", ".", "value", "except", "x509", ".", "ExtensionNotFound", ":", "return", "None" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
get_common_names_from_certificate
Given an X.509 certificate, extract and return all common names.
kmip/services/server/auth/utils.py
def get_common_names_from_certificate(certificate): """ Given an X.509 certificate, extract and return all common names. """ common_names = certificate.subject.get_attributes_for_oid( x509.oid.NameOID.COMMON_NAME ) return [common_name.value for common_name in common_names]
def get_common_names_from_certificate(certificate): """ Given an X.509 certificate, extract and return all common names. """ common_names = certificate.subject.get_attributes_for_oid( x509.oid.NameOID.COMMON_NAME ) return [common_name.value for common_name in common_names]
[ "Given", "an", "X", ".", "509", "certificate", "extract", "and", "return", "all", "common", "names", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/auth/utils.py#L48-L56
[ "def", "get_common_names_from_certificate", "(", "certificate", ")", ":", "common_names", "=", "certificate", ".", "subject", ".", "get_attributes_for_oid", "(", "x509", ".", "oid", ".", "NameOID", ".", "COMMON_NAME", ")", "return", "[", "common_name", ".", "value", "for", "common_name", "in", "common_names", "]" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
get_client_identity_from_certificate
Given an X.509 certificate, extract and return the client identity.
kmip/services/server/auth/utils.py
def get_client_identity_from_certificate(certificate): """ Given an X.509 certificate, extract and return the client identity. """ client_ids = get_common_names_from_certificate(certificate) if len(client_ids) > 0: if len(client_ids) > 1: raise exceptions.PermissionDenied( "Multiple client identities found." ) return client_ids[0] else: raise exceptions.PermissionDenied( "The certificate does not define any subject common names. " "Client identity unavailable." )
def get_client_identity_from_certificate(certificate): """ Given an X.509 certificate, extract and return the client identity. """ client_ids = get_common_names_from_certificate(certificate) if len(client_ids) > 0: if len(client_ids) > 1: raise exceptions.PermissionDenied( "Multiple client identities found." ) return client_ids[0] else: raise exceptions.PermissionDenied( "The certificate does not define any subject common names. " "Client identity unavailable." )
[ "Given", "an", "X", ".", "509", "certificate", "extract", "and", "return", "the", "client", "identity", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/auth/utils.py#L59-L75
[ "def", "get_client_identity_from_certificate", "(", "certificate", ")", ":", "client_ids", "=", "get_common_names_from_certificate", "(", "certificate", ")", "if", "len", "(", "client_ids", ")", ">", "0", ":", "if", "len", "(", "client_ids", ")", ">", "1", ":", "raise", "exceptions", ".", "PermissionDenied", "(", "\"Multiple client identities found.\"", ")", "return", "client_ids", "[", "0", "]", "else", ":", "raise", "exceptions", ".", "PermissionDenied", "(", "\"The certificate does not define any subject common names. \"", "\"Client identity unavailable.\"", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CreateRequestPayload.read
Read the data encoding the Create 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 or template attribute is missing from the encoded payload.
kmip/core/messages/payloads/create.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Create 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 or template attribute is missing from the encoded payload. """ super(CreateRequestPayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer): self._object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE ) self._object_type.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The Create request payload encoding is missing the object " "type." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The Create request payload encoding is missing the " "template attribute." ) else: # NOTE (ph) For now, leave attributes natively in TemplateAttribute # form and just convert to the KMIP 2.0 Attributes form as needed # for encoding/decoding purposes. Changing the payload to require # the new Attributes structure will trigger a bunch of second-order # effects across the client and server codebases that is beyond # the scope of updating the Create payloads to support KMIP 2.0. if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer): attributes = objects.Attributes() attributes.read(local_buffer, kmip_version=kmip_version) value = objects.convert_attributes_to_template_attribute( attributes ) self._template_attribute = value else: raise exceptions.InvalidKmipEncoding( "The Create request payload encoding is missing the " "attributes structure." ) self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Create 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 or template attribute is missing from the encoded payload. """ super(CreateRequestPayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer): self._object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE ) self._object_type.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The Create request payload encoding is missing the object " "type." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The Create request payload encoding is missing the " "template attribute." ) else: # NOTE (ph) For now, leave attributes natively in TemplateAttribute # form and just convert to the KMIP 2.0 Attributes form as needed # for encoding/decoding purposes. Changing the payload to require # the new Attributes structure will trigger a bunch of second-order # effects across the client and server codebases that is beyond # the scope of updating the Create payloads to support KMIP 2.0. if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer): attributes = objects.Attributes() attributes.read(local_buffer, kmip_version=kmip_version) value = objects.convert_attributes_to_template_attribute( attributes ) self._template_attribute = value else: raise exceptions.InvalidKmipEncoding( "The Create request payload encoding is missing the " "attributes structure." ) self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "Create", "request", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/create.py#L95-L161
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "CreateRequestPayload", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "OBJECT_TYPE", ",", "local_buffer", ")", ":", "self", ".", "_object_type", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "ObjectType", ",", "tag", "=", "enums", ".", "Tags", ".", "OBJECT_TYPE", ")", "self", ".", "_object_type", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The Create request payload encoding is missing the object \"", "\"type.\"", ")", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "TEMPLATE_ATTRIBUTE", ",", "local_buffer", ")", ":", "self", ".", "_template_attribute", "=", "objects", ".", "TemplateAttribute", "(", ")", "self", ".", "_template_attribute", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The Create request payload encoding is missing the \"", "\"template attribute.\"", ")", "else", ":", "# NOTE (ph) For now, leave attributes natively in TemplateAttribute", "# form and just convert to the KMIP 2.0 Attributes form as needed", "# for encoding/decoding purposes. Changing the payload to require", "# the new Attributes structure will trigger a bunch of second-order", "# effects across the client and server codebases that is beyond", "# the scope of updating the Create payloads to support KMIP 2.0.", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ATTRIBUTES", ",", "local_buffer", ")", ":", "attributes", "=", "objects", ".", "Attributes", "(", ")", "attributes", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "value", "=", "objects", ".", "convert_attributes_to_template_attribute", "(", "attributes", ")", "self", ".", "_template_attribute", "=", "value", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The Create request payload encoding is missing the \"", "\"attributes structure.\"", ")", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CreateRequestPayload.write
Write the data encoding the Create 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 or template attribute is not defined.
kmip/core/messages/payloads/create.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Create 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 or template attribute is not defined. """ local_buffer = utils.BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Create request payload is missing the object type field." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._template_attribute: self._template_attribute.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The Create request payload is missing the template " "attribute field." ) else: # NOTE (ph) For now, leave attributes natively in TemplateAttribute # form and just convert to the KMIP 2.0 Attributes form as needed # for encoding/decoding purposes. Changing the payload to require # the new Attributes structure will trigger a bunch of second-order # effects across the client and server codebases that is beyond # the scope of updating the Create payloads to support KMIP 2.0. if self._template_attribute: attributes = objects.convert_template_attribute_to_attributes( self._template_attribute ) attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Create request payload is missing the template " "attribute field." ) self.length = local_buffer.length() super(CreateRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Create 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 or template attribute is not defined. """ local_buffer = utils.BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Create request payload is missing the object type field." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._template_attribute: self._template_attribute.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The Create request payload is missing the template " "attribute field." ) else: # NOTE (ph) For now, leave attributes natively in TemplateAttribute # form and just convert to the KMIP 2.0 Attributes form as needed # for encoding/decoding purposes. Changing the payload to require # the new Attributes structure will trigger a bunch of second-order # effects across the client and server codebases that is beyond # the scope of updating the Create payloads to support KMIP 2.0. if self._template_attribute: attributes = objects.convert_template_attribute_to_attributes( self._template_attribute ) attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Create request payload is missing the template " "attribute field." ) self.length = local_buffer.length() super(CreateRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "data", "encoding", "the", "Create", "request", "payload", "to", "a", "buffer", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/create.py#L163-L221
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_object_type", ":", "self", ".", "_object_type", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The Create request payload is missing the object type field.\"", ")", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "if", "self", ".", "_template_attribute", ":", "self", ".", "_template_attribute", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The Create request payload is missing the template \"", "\"attribute field.\"", ")", "else", ":", "# NOTE (ph) For now, leave attributes natively in TemplateAttribute", "# form and just convert to the KMIP 2.0 Attributes form as needed", "# for encoding/decoding purposes. Changing the payload to require", "# the new Attributes structure will trigger a bunch of second-order", "# effects across the client and server codebases that is beyond", "# the scope of updating the Create payloads to support KMIP 2.0.", "if", "self", ".", "_template_attribute", ":", "attributes", "=", "objects", ".", "convert_template_attribute_to_attributes", "(", "self", ".", "_template_attribute", ")", "attributes", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The Create request payload is missing the template \"", "\"attribute field.\"", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "CreateRequestPayload", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CreateResponsePayload.read
Read the data encoding the Create 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 object type or unique identifier is missing from the encoded payload.
kmip/core/messages/payloads/create.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Create 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 object type or unique identifier is missing from the encoded payload. """ super(CreateResponsePayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer): self._object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE ) self._object_type.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The Create response payload encoding is missing the object " "type." ) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The Create response payload encoding is missing the unique " "identifier." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read( local_buffer, kmip_version=kmip_version ) self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Create 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 object type or unique identifier is missing from the encoded payload. """ super(CreateResponsePayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer): self._object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE ) self._object_type.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The Create response payload encoding is missing the object " "type." ) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The Create response payload encoding is missing the unique " "identifier." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read( local_buffer, kmip_version=kmip_version ) self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "Create", "response", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/create.py#L353-L409
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "CreateResponsePayload", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "OBJECT_TYPE", ",", "local_buffer", ")", ":", "self", ".", "_object_type", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "ObjectType", ",", "tag", "=", "enums", ".", "Tags", ".", "OBJECT_TYPE", ")", "self", ".", "_object_type", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The Create response payload encoding is missing the object \"", "\"type.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_buffer", ")", ":", "self", ".", "_unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "self", ".", "_unique_identifier", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The Create response payload encoding is missing the unique \"", "\"identifier.\"", ")", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "TEMPLATE_ATTRIBUTE", ",", "local_buffer", ")", ":", "self", ".", "_template_attribute", "=", "objects", ".", "TemplateAttribute", "(", ")", "self", ".", "_template_attribute", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CreateResponsePayload.write
Write the data encoding the Create 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 object type attribute or unique identifier is not defined.
kmip/core/messages/payloads/create.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Create 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 object type attribute or unique identifier is not defined. """ local_buffer = utils.BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Create response payload is missing the object type field." ) if self._unique_identifier: self._unique_identifier.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The Create response payload is missing the unique identifier " "field." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._template_attribute: self._template_attribute.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(CreateResponsePayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Create 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 object type attribute or unique identifier is not defined. """ local_buffer = utils.BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Create response payload is missing the object type field." ) if self._unique_identifier: self._unique_identifier.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The Create response payload is missing the unique identifier " "field." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._template_attribute: self._template_attribute.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(CreateResponsePayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "data", "encoding", "the", "Create", "response", "payload", "to", "a", "buffer", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/create.py#L411-L458
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_object_type", ":", "self", ".", "_object_type", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The Create response payload is missing the object type field.\"", ")", "if", "self", ".", "_unique_identifier", ":", "self", ".", "_unique_identifier", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The Create response payload is missing the unique identifier \"", "\"field.\"", ")", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "if", "self", ".", "_template_attribute", ":", "self", ".", "_template_attribute", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "CreateResponsePayload", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ObjectFactory.convert
Convert a Pie object into a core secret object and vice versa. Args: obj (various): A Pie or core secret object to convert into the opposite object space. Required. Raises: TypeError: if the object type is unrecognized or unsupported.
kmip/pie/factory.py
def convert(self, obj): """ Convert a Pie object into a core secret object and vice versa. Args: obj (various): A Pie or core secret object to convert into the opposite object space. Required. Raises: TypeError: if the object type is unrecognized or unsupported. """ if isinstance(obj, pobjects.SymmetricKey): return self._build_core_key(obj, secrets.SymmetricKey) elif isinstance(obj, secrets.SymmetricKey): return self._build_pie_key(obj, pobjects.SymmetricKey) elif isinstance(obj, pobjects.PublicKey): return self._build_core_key(obj, secrets.PublicKey) elif isinstance(obj, secrets.PublicKey): return self._build_pie_key(obj, pobjects.PublicKey) elif isinstance(obj, pobjects.PrivateKey): return self._build_core_key(obj, secrets.PrivateKey) elif isinstance(obj, secrets.PrivateKey): return self._build_pie_key(obj, pobjects.PrivateKey) elif isinstance(obj, pobjects.Certificate): return self._build_core_certificate(obj) elif isinstance(obj, secrets.Certificate): return self._build_pie_certificate(obj) elif isinstance(obj, pobjects.SecretData): return self._build_core_secret_data(obj) elif isinstance(obj, secrets.SecretData): return self._build_pie_secret_data(obj) elif isinstance(obj, pobjects.OpaqueObject): return self._build_core_opaque_object(obj) elif isinstance(obj, secrets.OpaqueObject): return self._build_pie_opaque_object(obj) else: raise TypeError("object type unsupported and cannot be converted")
def convert(self, obj): """ Convert a Pie object into a core secret object and vice versa. Args: obj (various): A Pie or core secret object to convert into the opposite object space. Required. Raises: TypeError: if the object type is unrecognized or unsupported. """ if isinstance(obj, pobjects.SymmetricKey): return self._build_core_key(obj, secrets.SymmetricKey) elif isinstance(obj, secrets.SymmetricKey): return self._build_pie_key(obj, pobjects.SymmetricKey) elif isinstance(obj, pobjects.PublicKey): return self._build_core_key(obj, secrets.PublicKey) elif isinstance(obj, secrets.PublicKey): return self._build_pie_key(obj, pobjects.PublicKey) elif isinstance(obj, pobjects.PrivateKey): return self._build_core_key(obj, secrets.PrivateKey) elif isinstance(obj, secrets.PrivateKey): return self._build_pie_key(obj, pobjects.PrivateKey) elif isinstance(obj, pobjects.Certificate): return self._build_core_certificate(obj) elif isinstance(obj, secrets.Certificate): return self._build_pie_certificate(obj) elif isinstance(obj, pobjects.SecretData): return self._build_core_secret_data(obj) elif isinstance(obj, secrets.SecretData): return self._build_pie_secret_data(obj) elif isinstance(obj, pobjects.OpaqueObject): return self._build_core_opaque_object(obj) elif isinstance(obj, secrets.OpaqueObject): return self._build_pie_opaque_object(obj) else: raise TypeError("object type unsupported and cannot be converted")
[ "Convert", "a", "Pie", "object", "into", "a", "core", "secret", "object", "and", "vice", "versa", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/pie/factory.py#L36-L72
[ "def", "convert", "(", "self", ",", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "pobjects", ".", "SymmetricKey", ")", ":", "return", "self", ".", "_build_core_key", "(", "obj", ",", "secrets", ".", "SymmetricKey", ")", "elif", "isinstance", "(", "obj", ",", "secrets", ".", "SymmetricKey", ")", ":", "return", "self", ".", "_build_pie_key", "(", "obj", ",", "pobjects", ".", "SymmetricKey", ")", "elif", "isinstance", "(", "obj", ",", "pobjects", ".", "PublicKey", ")", ":", "return", "self", ".", "_build_core_key", "(", "obj", ",", "secrets", ".", "PublicKey", ")", "elif", "isinstance", "(", "obj", ",", "secrets", ".", "PublicKey", ")", ":", "return", "self", ".", "_build_pie_key", "(", "obj", ",", "pobjects", ".", "PublicKey", ")", "elif", "isinstance", "(", "obj", ",", "pobjects", ".", "PrivateKey", ")", ":", "return", "self", ".", "_build_core_key", "(", "obj", ",", "secrets", ".", "PrivateKey", ")", "elif", "isinstance", "(", "obj", ",", "secrets", ".", "PrivateKey", ")", ":", "return", "self", ".", "_build_pie_key", "(", "obj", ",", "pobjects", ".", "PrivateKey", ")", "elif", "isinstance", "(", "obj", ",", "pobjects", ".", "Certificate", ")", ":", "return", "self", ".", "_build_core_certificate", "(", "obj", ")", "elif", "isinstance", "(", "obj", ",", "secrets", ".", "Certificate", ")", ":", "return", "self", ".", "_build_pie_certificate", "(", "obj", ")", "elif", "isinstance", "(", "obj", ",", "pobjects", ".", "SecretData", ")", ":", "return", "self", ".", "_build_core_secret_data", "(", "obj", ")", "elif", "isinstance", "(", "obj", ",", "secrets", ".", "SecretData", ")", ":", "return", "self", ".", "_build_pie_secret_data", "(", "obj", ")", "elif", "isinstance", "(", "obj", ",", "pobjects", ".", "OpaqueObject", ")", ":", "return", "self", ".", "_build_core_opaque_object", "(", "obj", ")", "elif", "isinstance", "(", "obj", ",", "secrets", ".", "OpaqueObject", ")", ":", "return", "self", ".", "_build_pie_opaque_object", "(", "obj", ")", "else", ":", "raise", "TypeError", "(", "\"object type unsupported and cannot be converted\"", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
EncryptResponsePayload.read
Read the data encoding the Encrypt 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 or data attributes are missing from the encoded payload.
kmip/core/messages/payloads/encrypt.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Encrypt 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 or data attributes are missing from the encoded payload. """ super(EncryptResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "invalid payload missing the unique identifier attribute" ) if self.is_tag_next(enums.Tags.DATA, local_stream): self._data = primitives.ByteString(tag=enums.Tags.DATA) self._data.read( local_stream, kmip_version=kmip_version ) else: raise ValueError("invalid payload missing the data attribute") if self.is_tag_next(enums.Tags.IV_COUNTER_NONCE, local_stream): self._iv_counter_nonce = primitives.ByteString( tag=enums.Tags.IV_COUNTER_NONCE ) self._iv_counter_nonce.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Encrypt 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 or data attributes are missing from the encoded payload. """ super(EncryptResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "invalid payload missing the unique identifier attribute" ) if self.is_tag_next(enums.Tags.DATA, local_stream): self._data = primitives.ByteString(tag=enums.Tags.DATA) self._data.read( local_stream, kmip_version=kmip_version ) else: raise ValueError("invalid payload missing the data attribute") if self.is_tag_next(enums.Tags.IV_COUNTER_NONCE, local_stream): self._iv_counter_nonce = primitives.ByteString( tag=enums.Tags.IV_COUNTER_NONCE ) self._iv_counter_nonce.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "Encrypt", "response", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/encrypt.py#L394-L448
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "EncryptResponsePayload", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "utils", ".", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "self", ".", "_unique_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"invalid payload missing the unique identifier attribute\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "DATA", ",", "local_stream", ")", ":", "self", ".", "_data", "=", "primitives", ".", "ByteString", "(", "tag", "=", "enums", ".", "Tags", ".", "DATA", ")", "self", ".", "_data", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"invalid payload missing the data attribute\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "IV_COUNTER_NONCE", ",", "local_stream", ")", ":", "self", ".", "_iv_counter_nonce", "=", "primitives", ".", "ByteString", "(", "tag", "=", "enums", ".", "Tags", ".", "IV_COUNTER_NONCE", ")", "self", ".", "_iv_counter_nonce", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
DeriveKeyRequestPayload.read
Read the data encoding the DeriveKey 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: ValueError: Raised if the data attribute is missing from the encoded payload.
kmip/core/messages/payloads/derive_key.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the DeriveKey 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: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(DeriveKeyRequestPayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer): self._object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE ) self._object_type.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the object " "type." ) unique_identifiers = [] while self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer): unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) unique_identifier.read(local_buffer, kmip_version=kmip_version) unique_identifiers.append(unique_identifier) if not unique_identifiers: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the unique " "identifiers." ) else: self._unique_identifiers = unique_identifiers if self.is_tag_next(enums.Tags.DERIVATION_METHOD, local_buffer): self._derivation_method = primitives.Enumeration( enums.DerivationMethod, tag=enums.Tags.DERIVATION_METHOD ) self._derivation_method.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the " "derivation method." ) if self.is_tag_next(enums.Tags.DERIVATION_PARAMETERS, local_buffer): self._derivation_parameters = attributes.DerivationParameters() self._derivation_parameters.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the " "derivation parameters." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the " "template attribute." ) else: if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer): attrs = objects.Attributes() attrs.read(local_buffer, kmip_version=kmip_version) value = objects.convert_attributes_to_template_attribute( attrs ) self._template_attribute = value else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the " "attributes structure." ) self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the DeriveKey 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: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(DeriveKeyRequestPayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer): self._object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE ) self._object_type.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the object " "type." ) unique_identifiers = [] while self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer): unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) unique_identifier.read(local_buffer, kmip_version=kmip_version) unique_identifiers.append(unique_identifier) if not unique_identifiers: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the unique " "identifiers." ) else: self._unique_identifiers = unique_identifiers if self.is_tag_next(enums.Tags.DERIVATION_METHOD, local_buffer): self._derivation_method = primitives.Enumeration( enums.DerivationMethod, tag=enums.Tags.DERIVATION_METHOD ) self._derivation_method.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the " "derivation method." ) if self.is_tag_next(enums.Tags.DERIVATION_PARAMETERS, local_buffer): self._derivation_parameters = attributes.DerivationParameters() self._derivation_parameters.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the " "derivation parameters." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_buffer): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the " "template attribute." ) else: if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer): attrs = objects.Attributes() attrs.read(local_buffer, kmip_version=kmip_version) value = objects.convert_attributes_to_template_attribute( attrs ) self._template_attribute = value else: raise exceptions.InvalidKmipEncoding( "The DeriveKey request payload encoding is missing the " "attributes structure." ) self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "DeriveKey", "request", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/derive_key.py#L198-L301
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "DeriveKeyRequestPayload", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "OBJECT_TYPE", ",", "local_buffer", ")", ":", "self", ".", "_object_type", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "ObjectType", ",", "tag", "=", "enums", ".", "Tags", ".", "OBJECT_TYPE", ")", "self", ".", "_object_type", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The DeriveKey request payload encoding is missing the object \"", "\"type.\"", ")", "unique_identifiers", "=", "[", "]", "while", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_buffer", ")", ":", "unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "unique_identifier", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "unique_identifiers", ".", "append", "(", "unique_identifier", ")", "if", "not", "unique_identifiers", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The DeriveKey request payload encoding is missing the unique \"", "\"identifiers.\"", ")", "else", ":", "self", ".", "_unique_identifiers", "=", "unique_identifiers", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "DERIVATION_METHOD", ",", "local_buffer", ")", ":", "self", ".", "_derivation_method", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "DerivationMethod", ",", "tag", "=", "enums", ".", "Tags", ".", "DERIVATION_METHOD", ")", "self", ".", "_derivation_method", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The DeriveKey request payload encoding is missing the \"", "\"derivation method.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "DERIVATION_PARAMETERS", ",", "local_buffer", ")", ":", "self", ".", "_derivation_parameters", "=", "attributes", ".", "DerivationParameters", "(", ")", "self", ".", "_derivation_parameters", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The DeriveKey request payload encoding is missing the \"", "\"derivation parameters.\"", ")", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "TEMPLATE_ATTRIBUTE", ",", "local_buffer", ")", ":", "self", ".", "_template_attribute", "=", "objects", ".", "TemplateAttribute", "(", ")", "self", ".", "_template_attribute", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The DeriveKey request payload encoding is missing the \"", "\"template attribute.\"", ")", "else", ":", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ATTRIBUTES", ",", "local_buffer", ")", ":", "attrs", "=", "objects", ".", "Attributes", "(", ")", "attrs", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "value", "=", "objects", ".", "convert_attributes_to_template_attribute", "(", "attrs", ")", "self", ".", "_template_attribute", "=", "value", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The DeriveKey request payload encoding is missing the \"", "\"attributes structure.\"", ")", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
DeriveKeyRequestPayload.write
Write the data encoding the DeriveKey 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. Raises: ValueError: Raised if the data attribute is not defined.
kmip/core/messages/payloads/derive_key.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the DeriveKey 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. Raises: ValueError: Raised if the data attribute is not defined. """ local_buffer = utils.BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the object type " "field." ) if self._unique_identifiers: for unique_identifier in self._unique_identifiers: unique_identifier.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the unique " "identifiers field." ) if self._derivation_method: self._derivation_method.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the derivation " "method field." ) if self._derivation_parameters: self._derivation_parameters.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the derivation " "parameters field." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._template_attribute: self._template_attribute.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the template " "attribute field." ) else: if self._template_attribute: attrs = objects.convert_template_attribute_to_attributes( self._template_attribute ) attrs.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the template " "attribute field." ) self.length = local_buffer.length() super(DeriveKeyRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the DeriveKey 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. Raises: ValueError: Raised if the data attribute is not defined. """ local_buffer = utils.BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the object type " "field." ) if self._unique_identifiers: for unique_identifier in self._unique_identifiers: unique_identifier.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the unique " "identifiers field." ) if self._derivation_method: self._derivation_method.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the derivation " "method field." ) if self._derivation_parameters: self._derivation_parameters.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the derivation " "parameters field." ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._template_attribute: self._template_attribute.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the template " "attribute field." ) else: if self._template_attribute: attrs = objects.convert_template_attribute_to_attributes( self._template_attribute ) attrs.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The DeriveKey request payload is missing the template " "attribute field." ) self.length = local_buffer.length() super(DeriveKeyRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "data", "encoding", "the", "DeriveKey", "request", "payload", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/derive_key.py#L303-L390
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_object_type", ":", "self", ".", "_object_type", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The DeriveKey request payload is missing the object type \"", "\"field.\"", ")", "if", "self", ".", "_unique_identifiers", ":", "for", "unique_identifier", "in", "self", ".", "_unique_identifiers", ":", "unique_identifier", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The DeriveKey request payload is missing the unique \"", "\"identifiers field.\"", ")", "if", "self", ".", "_derivation_method", ":", "self", ".", "_derivation_method", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The DeriveKey request payload is missing the derivation \"", "\"method field.\"", ")", "if", "self", ".", "_derivation_parameters", ":", "self", ".", "_derivation_parameters", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The DeriveKey request payload is missing the derivation \"", "\"parameters field.\"", ")", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "if", "self", ".", "_template_attribute", ":", "self", ".", "_template_attribute", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The DeriveKey request payload is missing the template \"", "\"attribute field.\"", ")", "else", ":", "if", "self", ".", "_template_attribute", ":", "attrs", "=", "objects", ".", "convert_template_attribute_to_attributes", "(", "self", ".", "_template_attribute", ")", "attrs", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The DeriveKey request payload is missing the template \"", "\"attribute field.\"", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "DeriveKeyRequestPayload", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
AttributePolicy.is_attribute_supported
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.
kmip/services/server/policy.py
def is_attribute_supported(self, attribute): """ 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. """ if attribute not in self._attribute_rule_sets.keys(): return False rule_set = self._attribute_rule_sets.get(attribute) if self._version >= rule_set.version_added: return True else: return False
def is_attribute_supported(self, attribute): """ 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. """ if attribute not in self._attribute_rule_sets.keys(): return False rule_set = self._attribute_rule_sets.get(attribute) if self._version >= rule_set.version_added: return True else: return False
[ "Check", "if", "the", "attribute", "is", "supported", "by", "the", "current", "KMIP", "version", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/policy.py#L1081-L1099
[ "def", "is_attribute_supported", "(", "self", ",", "attribute", ")", ":", "if", "attribute", "not", "in", "self", ".", "_attribute_rule_sets", ".", "keys", "(", ")", ":", "return", "False", "rule_set", "=", "self", ".", "_attribute_rule_sets", ".", "get", "(", "attribute", ")", "if", "self", ".", "_version", ">=", "rule_set", ".", "version_added", ":", "return", "True", "else", ":", "return", "False" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
AttributePolicy.is_attribute_deprecated
Check if the attribute is deprecated by the current KMIP version. Args: attribute (string): The name of the attribute (e.g., 'Unique Identifier'). Required.
kmip/services/server/policy.py
def is_attribute_deprecated(self, attribute): """ Check if the attribute is deprecated by the current KMIP version. Args: attribute (string): The name of the attribute (e.g., 'Unique Identifier'). Required. """ rule_set = self._attribute_rule_sets.get(attribute) if rule_set.version_deprecated: if self._version >= rule_set.version_deprecated: return True else: return False else: return False
def is_attribute_deprecated(self, attribute): """ Check if the attribute is deprecated by the current KMIP version. Args: attribute (string): The name of the attribute (e.g., 'Unique Identifier'). Required. """ rule_set = self._attribute_rule_sets.get(attribute) if rule_set.version_deprecated: if self._version >= rule_set.version_deprecated: return True else: return False else: return False
[ "Check", "if", "the", "attribute", "is", "deprecated", "by", "the", "current", "KMIP", "version", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/policy.py#L1101-L1116
[ "def", "is_attribute_deprecated", "(", "self", ",", "attribute", ")", ":", "rule_set", "=", "self", ".", "_attribute_rule_sets", ".", "get", "(", "attribute", ")", "if", "rule_set", ".", "version_deprecated", ":", "if", "self", ".", "_version", ">=", "rule_set", ".", "version_deprecated", ":", "return", "True", "else", ":", "return", "False", "else", ":", "return", "False" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
AttributePolicy.is_attribute_applicable_to_object_type
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.
kmip/services/server/policy.py
def is_attribute_applicable_to_object_type(self, attribute, object_type): """ 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. """ # TODO (peterhamilton) Handle applicability between certificate types rule_set = self._attribute_rule_sets.get(attribute) if object_type in rule_set.applies_to_object_types: return True else: return False
def is_attribute_applicable_to_object_type(self, attribute, object_type): """ 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. """ # TODO (peterhamilton) Handle applicability between certificate types rule_set = self._attribute_rule_sets.get(attribute) if object_type in rule_set.applies_to_object_types: return True else: return False
[ "Check", "if", "the", "attribute", "is", "supported", "by", "the", "given", "object", "type", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/policy.py#L1118-L1136
[ "def", "is_attribute_applicable_to_object_type", "(", "self", ",", "attribute", ",", "object_type", ")", ":", "# TODO (peterhamilton) Handle applicability between certificate types", "rule_set", "=", "self", ".", "_attribute_rule_sets", ".", "get", "(", "attribute", ")", "if", "object_type", "in", "rule_set", ".", "applies_to_object_types", ":", "return", "True", "else", ":", "return", "False" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
AttributePolicy.is_attribute_multivalued
Check if the attribute is allowed to have multiple instances. Args: attribute (string): The name of the attribute (e.g., 'State'). Required.
kmip/services/server/policy.py
def is_attribute_multivalued(self, attribute): """ Check if the attribute is allowed to have multiple instances. Args: attribute (string): The name of the attribute (e.g., 'State'). Required. """ # TODO (peterhamilton) Handle multivalue swap between certificate types rule_set = self._attribute_rule_sets.get(attribute) return rule_set.multiple_instances_permitted
def is_attribute_multivalued(self, attribute): """ Check if the attribute is allowed to have multiple instances. Args: attribute (string): The name of the attribute (e.g., 'State'). Required. """ # TODO (peterhamilton) Handle multivalue swap between certificate types rule_set = self._attribute_rule_sets.get(attribute) return rule_set.multiple_instances_permitted
[ "Check", "if", "the", "attribute", "is", "allowed", "to", "have", "multiple", "instances", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/policy.py#L1138-L1148
[ "def", "is_attribute_multivalued", "(", "self", ",", "attribute", ")", ":", "# TODO (peterhamilton) Handle multivalue swap between certificate types", "rule_set", "=", "self", ".", "_attribute_rule_sets", ".", "get", "(", "attribute", ")", "return", "rule_set", ".", "multiple_instances_permitted" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ConfigHelper.get_valid_value
Returns a value that can be used as a parameter in client or server. If a direct_value is given, that value will be returned instead of the value from the config file. If the appropriate config file option is not found, the default_value is returned. :param direct_value: represents a direct value that should be used. supercedes values from config files :param config_section: which section of the config file to use :param config_option_name: name of config option value :param default_value: default value to be used if other options not found :returns: a value that can be used as a parameter
kmip/core/config_helper.py
def get_valid_value(self, direct_value, config_section, config_option_name, default_value): """Returns a value that can be used as a parameter in client or server. If a direct_value is given, that value will be returned instead of the value from the config file. If the appropriate config file option is not found, the default_value is returned. :param direct_value: represents a direct value that should be used. supercedes values from config files :param config_section: which section of the config file to use :param config_option_name: name of config option value :param default_value: default value to be used if other options not found :returns: a value that can be used as a parameter """ ARG_MSG = "Using given value '{0}' for {1}" CONF_MSG = "Using value '{0}' from configuration file {1} for {2}" DEFAULT_MSG = "Using default value '{0}' for {1}" if direct_value: return_value = direct_value self.logger.debug(ARG_MSG.format(direct_value, config_option_name)) else: try: return_value = self.conf.get(config_section, config_option_name) self.logger.debug(CONF_MSG.format(return_value, CONFIG_FILE, config_option_name)) except Exception: return_value = default_value self.logger.debug(DEFAULT_MSG.format(default_value, config_option_name)) # TODO (peter-hamilton): Think about adding better value validation if return_value == self.NONE_VALUE: return None else: return return_value
def get_valid_value(self, direct_value, config_section, config_option_name, default_value): """Returns a value that can be used as a parameter in client or server. If a direct_value is given, that value will be returned instead of the value from the config file. If the appropriate config file option is not found, the default_value is returned. :param direct_value: represents a direct value that should be used. supercedes values from config files :param config_section: which section of the config file to use :param config_option_name: name of config option value :param default_value: default value to be used if other options not found :returns: a value that can be used as a parameter """ ARG_MSG = "Using given value '{0}' for {1}" CONF_MSG = "Using value '{0}' from configuration file {1} for {2}" DEFAULT_MSG = "Using default value '{0}' for {1}" if direct_value: return_value = direct_value self.logger.debug(ARG_MSG.format(direct_value, config_option_name)) else: try: return_value = self.conf.get(config_section, config_option_name) self.logger.debug(CONF_MSG.format(return_value, CONFIG_FILE, config_option_name)) except Exception: return_value = default_value self.logger.debug(DEFAULT_MSG.format(default_value, config_option_name)) # TODO (peter-hamilton): Think about adding better value validation if return_value == self.NONE_VALUE: return None else: return return_value
[ "Returns", "a", "value", "that", "can", "be", "used", "as", "a", "parameter", "in", "client", "or", "server", ".", "If", "a", "direct_value", "is", "given", "that", "value", "will", "be", "returned", "instead", "of", "the", "value", "from", "the", "config", "file", ".", "If", "the", "appropriate", "config", "file", "option", "is", "not", "found", "the", "default_value", "is", "returned", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/config_helper.py#L67-L103
[ "def", "get_valid_value", "(", "self", ",", "direct_value", ",", "config_section", ",", "config_option_name", ",", "default_value", ")", ":", "ARG_MSG", "=", "\"Using given value '{0}' for {1}\"", "CONF_MSG", "=", "\"Using value '{0}' from configuration file {1} for {2}\"", "DEFAULT_MSG", "=", "\"Using default value '{0}' for {1}\"", "if", "direct_value", ":", "return_value", "=", "direct_value", "self", ".", "logger", ".", "debug", "(", "ARG_MSG", ".", "format", "(", "direct_value", ",", "config_option_name", ")", ")", "else", ":", "try", ":", "return_value", "=", "self", ".", "conf", ".", "get", "(", "config_section", ",", "config_option_name", ")", "self", ".", "logger", ".", "debug", "(", "CONF_MSG", ".", "format", "(", "return_value", ",", "CONFIG_FILE", ",", "config_option_name", ")", ")", "except", "Exception", ":", "return_value", "=", "default_value", "self", ".", "logger", ".", "debug", "(", "DEFAULT_MSG", ".", "format", "(", "default_value", ",", "config_option_name", ")", ")", "# TODO (peter-hamilton): Think about adding better value validation", "if", "return_value", "==", "self", ".", "NONE_VALUE", ":", "return", "None", "else", ":", "return", "return_value" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CheckResponsePayload.read
Read the data encoding the Check 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 data attribute is missing from the encoded payload.
kmip/core/messages/payloads/check.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Check 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 data attribute is missing from the encoded payload. """ super(CheckResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.USAGE_LIMITS_COUNT, local_stream): self._usage_limits_count = primitives.LongInteger( tag=enums.Tags.USAGE_LIMITS_COUNT ) self._usage_limits_count.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_USAGE_MASK, local_stream): self._cryptographic_usage_mask = primitives.Integer( tag=enums.Tags.CRYPTOGRAPHIC_USAGE_MASK ) self._cryptographic_usage_mask.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.LEASE_TIME, local_stream): self._lease_time = primitives.Interval( tag=enums.Tags.LEASE_TIME ) self._lease_time.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Check 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 data attribute is missing from the encoded payload. """ super(CheckResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.USAGE_LIMITS_COUNT, local_stream): self._usage_limits_count = primitives.LongInteger( tag=enums.Tags.USAGE_LIMITS_COUNT ) self._usage_limits_count.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_USAGE_MASK, local_stream): self._cryptographic_usage_mask = primitives.Integer( tag=enums.Tags.CRYPTOGRAPHIC_USAGE_MASK ) self._cryptographic_usage_mask.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.LEASE_TIME, local_stream): self._lease_time = primitives.Interval( tag=enums.Tags.LEASE_TIME ) self._lease_time.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "Check", "response", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/check.py#L411-L467
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "CheckResponsePayload", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "utils", ".", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "self", ".", "_unique_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "USAGE_LIMITS_COUNT", ",", "local_stream", ")", ":", "self", ".", "_usage_limits_count", "=", "primitives", ".", "LongInteger", "(", "tag", "=", "enums", ".", "Tags", ".", "USAGE_LIMITS_COUNT", ")", "self", ".", "_usage_limits_count", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "CRYPTOGRAPHIC_USAGE_MASK", ",", "local_stream", ")", ":", "self", ".", "_cryptographic_usage_mask", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "CRYPTOGRAPHIC_USAGE_MASK", ")", "self", ".", "_cryptographic_usage_mask", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "LEASE_TIME", ",", "local_stream", ")", ":", "self", ".", "_lease_time", "=", "primitives", ".", "Interval", "(", "tag", "=", "enums", ".", "Tags", ".", "LEASE_TIME", ")", "self", ".", "_lease_time", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CheckResponsePayload.write
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.
kmip/core/messages/payloads/check.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) if self._usage_limits_count: self._usage_limits_count.write( local_stream, kmip_version=kmip_version ) if self._cryptographic_usage_mask: self._cryptographic_usage_mask.write( local_stream, kmip_version=kmip_version ) if self._lease_time: self._lease_time.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(CheckResponsePayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) if self._usage_limits_count: self._usage_limits_count.write( local_stream, kmip_version=kmip_version ) if self._cryptographic_usage_mask: self._cryptographic_usage_mask.write( local_stream, kmip_version=kmip_version ) if self._lease_time: self._lease_time.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(CheckResponsePayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "Check", "response", "payload", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/check.py#L469-L512
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_unique_identifier", ":", "self", ".", "_unique_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_usage_limits_count", ":", "self", ".", "_usage_limits_count", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_cryptographic_usage_mask", ":", "self", ".", "_cryptographic_usage_mask", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_lease_time", ":", "self", ".", "_lease_time", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "CheckResponsePayload", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
AttributeReference.read
Read the data stream and decode the AttributeReference structure into its parts. Args: input_buffer (stream): A data stream containing encoded object data, supporting a read method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be decoded. Optional, defaults to KMIP 2.0. Raises: InvalidKmipEncoding: Raised if the vendor identification or attribute name is missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the AttributeReference structure.
kmip/core/objects.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Read the data stream and decode the AttributeReference structure into its parts. Args: input_buffer (stream): A data stream containing encoded object data, supporting a read method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be decoded. Optional, defaults to KMIP 2.0. Raises: InvalidKmipEncoding: Raised if the vendor identification or attribute name is missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the AttributeReference structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the AttributeReference " "object.".format( kmip_version.value ) ) super(AttributeReference, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.VENDOR_IDENTIFICATION, local_buffer): self._vendor_identification = primitives.TextString( tag=enums.Tags.VENDOR_IDENTIFICATION ) self._vendor_identification.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The AttributeReference encoding is missing the vendor " "identification string." ) if self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, local_buffer): self._attribute_name = primitives.TextString( tag=enums.Tags.ATTRIBUTE_NAME ) self._attribute_name.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The AttributeReference encoding is missing the attribute " "name string." ) self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Read the data stream and decode the AttributeReference structure into its parts. Args: input_buffer (stream): A data stream containing encoded object data, supporting a read method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be decoded. Optional, defaults to KMIP 2.0. Raises: InvalidKmipEncoding: Raised if the vendor identification or attribute name is missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the AttributeReference structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the AttributeReference " "object.".format( kmip_version.value ) ) super(AttributeReference, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.VENDOR_IDENTIFICATION, local_buffer): self._vendor_identification = primitives.TextString( tag=enums.Tags.VENDOR_IDENTIFICATION ) self._vendor_identification.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The AttributeReference encoding is missing the vendor " "identification string." ) if self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, local_buffer): self._attribute_name = primitives.TextString( tag=enums.Tags.ATTRIBUTE_NAME ) self._attribute_name.read( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidKmipEncoding( "The AttributeReference encoding is missing the attribute " "name string." ) self.is_oversized(local_buffer)
[ "Read", "the", "data", "stream", "and", "decode", "the", "AttributeReference", "structure", "into", "its", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L250-L310
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the AttributeReference \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "super", "(", "AttributeReference", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VENDOR_IDENTIFICATION", ",", "local_buffer", ")", ":", "self", ".", "_vendor_identification", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "VENDOR_IDENTIFICATION", ")", "self", ".", "_vendor_identification", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The AttributeReference encoding is missing the vendor \"", "\"identification string.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ATTRIBUTE_NAME", ",", "local_buffer", ")", ":", "self", ".", "_attribute_name", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "ATTRIBUTE_NAME", ")", "self", ".", "_attribute_name", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The AttributeReference encoding is missing the attribute \"", "\"name string.\"", ")", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
AttributeReference.write
Write the AttributeReference structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the vendor identification or attribute name fields are not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the AttributeReference structure.
kmip/core/objects.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Write the AttributeReference structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the vendor identification or attribute name fields are not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the AttributeReference structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the AttributeReference " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._vendor_identification: self._vendor_identification.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The AttributeReference is missing the vendor identification " "field." ) if self._attribute_name: self._attribute_name.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The AttributeReference is missing the attribute name field." ) self.length = local_buffer.length() super(AttributeReference, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Write the AttributeReference structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the vendor identification or attribute name fields are not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the AttributeReference structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the AttributeReference " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._vendor_identification: self._vendor_identification.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The AttributeReference is missing the vendor identification " "field." ) if self._attribute_name: self._attribute_name.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The AttributeReference is missing the attribute name field." ) self.length = local_buffer.length() super(AttributeReference, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "AttributeReference", "structure", "encoding", "to", "the", "data", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L312-L365
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the AttributeReference \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "local_buffer", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_vendor_identification", ":", "self", ".", "_vendor_identification", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The AttributeReference is missing the vendor identification \"", "\"field.\"", ")", "if", "self", ".", "_attribute_name", ":", "self", ".", "_attribute_name", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The AttributeReference is missing the attribute name field.\"", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "AttributeReference", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Attributes.read
Read the data stream and decode the Attributes structure into its parts. Args: input_stream (stream): A data stream containing encoded object data, supporting a read method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be decoded. Optional, defaults to KMIP 2.0. Raises: AttributeNotSupported: Raised if an unsupported attribute is encountered while decoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the Attributes object.
kmip/core/objects.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Read the data stream and decode the Attributes structure into its parts. Args: input_stream (stream): A data stream containing encoded object data, supporting a read method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be decoded. Optional, defaults to KMIP 2.0. Raises: AttributeNotSupported: Raised if an unsupported attribute is encountered while decoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the Attributes object. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the Attributes object.".format( kmip_version.value ) ) super(Attributes, self).read(input_stream, kmip_version=kmip_version) local_stream = BytearrayStream(input_stream.read(self.length)) while True: if len(local_stream) < 3: break tag = struct.unpack('!I', b'\x00' + local_stream.peek(3))[0] if enums.is_enum_value(enums.Tags, tag): tag = enums.Tags(tag) if not enums.is_attribute(tag, kmip_version=kmip_version): raise exceptions.AttributeNotSupported( "Attribute {} is not supported by KMIP {}.".format( tag.name, kmip_version.value ) ) value = self._factory.create_attribute_value_by_enum(tag, None) value.read(local_stream, kmip_version=kmip_version) self._attributes.append(value) else: break self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Read the data stream and decode the Attributes structure into its parts. Args: input_stream (stream): A data stream containing encoded object data, supporting a read method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be decoded. Optional, defaults to KMIP 2.0. Raises: AttributeNotSupported: Raised if an unsupported attribute is encountered while decoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the Attributes object. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the Attributes object.".format( kmip_version.value ) ) super(Attributes, self).read(input_stream, kmip_version=kmip_version) local_stream = BytearrayStream(input_stream.read(self.length)) while True: if len(local_stream) < 3: break tag = struct.unpack('!I', b'\x00' + local_stream.peek(3))[0] if enums.is_enum_value(enums.Tags, tag): tag = enums.Tags(tag) if not enums.is_attribute(tag, kmip_version=kmip_version): raise exceptions.AttributeNotSupported( "Attribute {} is not supported by KMIP {}.".format( tag.name, kmip_version.value ) ) value = self._factory.create_attribute_value_by_enum(tag, None) value.read(local_stream, kmip_version=kmip_version) self._attributes.append(value) else: break self.is_oversized(local_stream)
[ "Read", "the", "data", "stream", "and", "decode", "the", "Attributes", "structure", "into", "its", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L477-L524
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the Attributes object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "super", "(", "Attributes", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "while", "True", ":", "if", "len", "(", "local_stream", ")", "<", "3", ":", "break", "tag", "=", "struct", ".", "unpack", "(", "'!I'", ",", "b'\\x00'", "+", "local_stream", ".", "peek", "(", "3", ")", ")", "[", "0", "]", "if", "enums", ".", "is_enum_value", "(", "enums", ".", "Tags", ",", "tag", ")", ":", "tag", "=", "enums", ".", "Tags", "(", "tag", ")", "if", "not", "enums", ".", "is_attribute", "(", "tag", ",", "kmip_version", "=", "kmip_version", ")", ":", "raise", "exceptions", ".", "AttributeNotSupported", "(", "\"Attribute {} is not supported by KMIP {}.\"", ".", "format", "(", "tag", ".", "name", ",", "kmip_version", ".", "value", ")", ")", "value", "=", "self", ".", "_factory", ".", "create_attribute_value_by_enum", "(", "tag", ",", "None", ")", "value", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_attributes", ".", "append", "(", "value", ")", "else", ":", "break", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Attributes.write
Write the Attributes structure encoding to the data stream. Args: output_stream (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: AttributeNotSupported: Raised if an unsupported attribute is found in the attribute list while encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the Attributes object.
kmip/core/objects.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Write the Attributes structure encoding to the data stream. Args: output_stream (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: AttributeNotSupported: Raised if an unsupported attribute is found in the attribute list while encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the Attributes object. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the Attributes object.".format( kmip_version.value ) ) local_stream = BytearrayStream() for attribute in self._attributes: tag = attribute.tag if not enums.is_attribute(tag, kmip_version=kmip_version): raise exceptions.AttributeNotSupported( "Attribute {} is not supported by KMIP {}.".format( tag.name, kmip_version.value ) ) attribute.write(local_stream, kmip_version=kmip_version) self.length = local_stream.length() super(Attributes, self).write(output_stream, kmip_version=kmip_version) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Write the Attributes structure encoding to the data stream. Args: output_stream (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: AttributeNotSupported: Raised if an unsupported attribute is found in the attribute list while encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the Attributes object. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the Attributes object.".format( kmip_version.value ) ) local_stream = BytearrayStream() for attribute in self._attributes: tag = attribute.tag if not enums.is_attribute(tag, kmip_version=kmip_version): raise exceptions.AttributeNotSupported( "Attribute {} is not supported by KMIP {}.".format( tag.name, kmip_version.value ) ) attribute.write(local_stream, kmip_version=kmip_version) self.length = local_stream.length() super(Attributes, self).write(output_stream, kmip_version=kmip_version) output_stream.write(local_stream.buffer)
[ "Write", "the", "Attributes", "structure", "encoding", "to", "the", "data", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L526-L565
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the Attributes object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "local_stream", "=", "BytearrayStream", "(", ")", "for", "attribute", "in", "self", ".", "_attributes", ":", "tag", "=", "attribute", ".", "tag", "if", "not", "enums", ".", "is_attribute", "(", "tag", ",", "kmip_version", "=", "kmip_version", ")", ":", "raise", "exceptions", ".", "AttributeNotSupported", "(", "\"Attribute {} is not supported by KMIP {}.\"", ".", "format", "(", "tag", ".", "name", ",", "kmip_version", ".", "value", ")", ")", "attribute", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "Attributes", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Nonce.read
Read the data encoding the Nonce 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 the nonce ID or nonce value is missing from the encoding.
kmip/core/objects.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Nonce 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 the nonce ID or nonce value is missing from the encoding. """ super(Nonce, self).read(input_stream, kmip_version=kmip_version) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.NONCE_ID, local_stream): self._nonce_id = primitives.ByteString( tag=enums.Tags.NONCE_ID ) self._nonce_id.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Nonce encoding missing the nonce ID." ) if self.is_tag_next(enums.Tags.NONCE_VALUE, local_stream): self._nonce_value = primitives.ByteString( tag=enums.Tags.NONCE_VALUE ) self._nonce_value.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Nonce encoding missing the nonce value." ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Nonce 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 the nonce ID or nonce value is missing from the encoding. """ super(Nonce, self).read(input_stream, kmip_version=kmip_version) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.NONCE_ID, local_stream): self._nonce_id = primitives.ByteString( tag=enums.Tags.NONCE_ID ) self._nonce_id.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Nonce encoding missing the nonce ID." ) if self.is_tag_next(enums.Tags.NONCE_VALUE, local_stream): self._nonce_value = primitives.ByteString( tag=enums.Tags.NONCE_VALUE ) self._nonce_value.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Nonce encoding missing the nonce value." ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "Nonce", "struct", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L671-L711
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "Nonce", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "NONCE_ID", ",", "local_stream", ")", ":", "self", ".", "_nonce_id", "=", "primitives", ".", "ByteString", "(", "tag", "=", "enums", ".", "Tags", ".", "NONCE_ID", ")", "self", ".", "_nonce_id", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Nonce encoding missing the nonce ID.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "NONCE_VALUE", ",", "local_stream", ")", ":", "self", ".", "_nonce_value", "=", "primitives", ".", "ByteString", "(", "tag", "=", "enums", ".", "Tags", ".", "NONCE_VALUE", ")", "self", ".", "_nonce_value", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Nonce encoding missing the nonce value.\"", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Nonce.write
Write the data encoding the Nonce 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 nonce ID or nonce value is not defined.
kmip/core/objects.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Nonce 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 nonce ID or nonce value is not defined. """ local_stream = BytearrayStream() if self._nonce_id: self._nonce_id.write(local_stream, kmip_version=kmip_version) else: raise ValueError("Nonce struct is missing the nonce ID.") if self._nonce_value: self._nonce_value.write(local_stream, kmip_version=kmip_version) else: raise ValueError("Nonce struct is missing the nonce value.") self.length = local_stream.length() super(Nonce, self).write(output_stream, kmip_version=kmip_version) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Nonce 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 nonce ID or nonce value is not defined. """ local_stream = BytearrayStream() if self._nonce_id: self._nonce_id.write(local_stream, kmip_version=kmip_version) else: raise ValueError("Nonce struct is missing the nonce ID.") if self._nonce_value: self._nonce_value.write(local_stream, kmip_version=kmip_version) else: raise ValueError("Nonce struct is missing the nonce value.") self.length = local_stream.length() super(Nonce, self).write(output_stream, kmip_version=kmip_version) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "Nonce", "struct", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L713-L742
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_nonce_id", ":", "self", ".", "_nonce_id", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Nonce struct is missing the nonce ID.\"", ")", "if", "self", ".", "_nonce_value", ":", "self", ".", "_nonce_value", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Nonce struct is missing the nonce value.\"", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "Nonce", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
UsernamePasswordCredential.read
Read the data encoding the UsernamePasswordCredential 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 the username is missing from the encoding.
kmip/core/objects.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the UsernamePasswordCredential 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 the username is missing from the encoding. """ super(UsernamePasswordCredential, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.USERNAME, local_stream): self._username = primitives.TextString( tag=enums.Tags.USERNAME ) self._username.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Username/password credential encoding missing the username." ) if self.is_tag_next(enums.Tags.PASSWORD, local_stream): self._password = primitives.TextString( tag=enums.Tags.PASSWORD ) self._password.read(local_stream, kmip_version=kmip_version) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the UsernamePasswordCredential 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 the username is missing from the encoding. """ super(UsernamePasswordCredential, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.USERNAME, local_stream): self._username = primitives.TextString( tag=enums.Tags.USERNAME ) self._username.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Username/password credential encoding missing the username." ) if self.is_tag_next(enums.Tags.PASSWORD, local_stream): self._password = primitives.TextString( tag=enums.Tags.PASSWORD ) self._password.read(local_stream, kmip_version=kmip_version) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "UsernamePasswordCredential", "struct", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L851-L889
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "UsernamePasswordCredential", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "USERNAME", ",", "local_stream", ")", ":", "self", ".", "_username", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "USERNAME", ")", "self", ".", "_username", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Username/password credential encoding missing the username.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "PASSWORD", ",", "local_stream", ")", ":", "self", ".", "_password", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "PASSWORD", ")", "self", ".", "_password", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
UsernamePasswordCredential.write
Write the data encoding the UsernamePasswordCredential 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 username is not defined.
kmip/core/objects.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the UsernamePasswordCredential 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 username is not defined. """ local_stream = BytearrayStream() if self._username: self._username.write(local_stream, kmip_version=kmip_version) else: raise ValueError( "Username/password credential struct missing the username." ) if self._password: self._password.write(local_stream, kmip_version=kmip_version) self.length = local_stream.length() super(UsernamePasswordCredential, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the UsernamePasswordCredential 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 username is not defined. """ local_stream = BytearrayStream() if self._username: self._username.write(local_stream, kmip_version=kmip_version) else: raise ValueError( "Username/password credential struct missing the username." ) if self._password: self._password.write(local_stream, kmip_version=kmip_version) self.length = local_stream.length() super(UsernamePasswordCredential, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "UsernamePasswordCredential", "struct", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L891-L924
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_username", ":", "self", ".", "_username", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Username/password credential struct missing the username.\"", ")", "if", "self", ".", "_password", ":", "self", ".", "_password", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "UsernamePasswordCredential", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
DeviceCredential.read
Read the data encoding the DeviceCredential 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.
kmip/core/objects.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the DeviceCredential 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. """ super(DeviceCredential, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.DEVICE_SERIAL_NUMBER, local_stream): self._device_serial_number = primitives.TextString( tag=enums.Tags.DEVICE_SERIAL_NUMBER ) self._device_serial_number.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.PASSWORD, local_stream): self._password = primitives.TextString( tag=enums.Tags.PASSWORD ) self._password.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.DEVICE_IDENTIFIER, local_stream): self._device_identifier = primitives.TextString( tag=enums.Tags.DEVICE_IDENTIFIER ) self._device_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.NETWORK_IDENTIFIER, local_stream): self._network_identifier = primitives.TextString( tag=enums.Tags.NETWORK_IDENTIFIER ) self._network_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.MACHINE_IDENTIFIER, local_stream): self._machine_identifier = primitives.TextString( tag=enums.Tags.MACHINE_IDENTIFIER ) self._machine_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.MEDIA_IDENTIFIER, local_stream): self._media_identifier = primitives.TextString( tag=enums.Tags.MEDIA_IDENTIFIER ) self._media_identifier.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the DeviceCredential 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. """ super(DeviceCredential, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.DEVICE_SERIAL_NUMBER, local_stream): self._device_serial_number = primitives.TextString( tag=enums.Tags.DEVICE_SERIAL_NUMBER ) self._device_serial_number.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.PASSWORD, local_stream): self._password = primitives.TextString( tag=enums.Tags.PASSWORD ) self._password.read(local_stream, kmip_version=kmip_version) if self.is_tag_next(enums.Tags.DEVICE_IDENTIFIER, local_stream): self._device_identifier = primitives.TextString( tag=enums.Tags.DEVICE_IDENTIFIER ) self._device_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.NETWORK_IDENTIFIER, local_stream): self._network_identifier = primitives.TextString( tag=enums.Tags.NETWORK_IDENTIFIER ) self._network_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.MACHINE_IDENTIFIER, local_stream): self._machine_identifier = primitives.TextString( tag=enums.Tags.MACHINE_IDENTIFIER ) self._machine_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.MEDIA_IDENTIFIER, local_stream): self._media_identifier = primitives.TextString( tag=enums.Tags.MEDIA_IDENTIFIER ) self._media_identifier.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "DeviceCredential", "struct", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L1124-L1194
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "DeviceCredential", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "DEVICE_SERIAL_NUMBER", ",", "local_stream", ")", ":", "self", ".", "_device_serial_number", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "DEVICE_SERIAL_NUMBER", ")", "self", ".", "_device_serial_number", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "PASSWORD", ",", "local_stream", ")", ":", "self", ".", "_password", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "PASSWORD", ")", "self", ".", "_password", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "DEVICE_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_device_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "DEVICE_IDENTIFIER", ")", "self", ".", "_device_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "NETWORK_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_network_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "NETWORK_IDENTIFIER", ")", "self", ".", "_network_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "MACHINE_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_machine_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "MACHINE_IDENTIFIER", ")", "self", ".", "_machine_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "MEDIA_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_media_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "MEDIA_IDENTIFIER", ")", "self", ".", "_media_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
DeviceCredential.write
Write the data encoding the DeviceCredential 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.
kmip/core/objects.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the DeviceCredential 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. """ local_stream = BytearrayStream() if self._device_serial_number is not None: self._device_serial_number.write( local_stream, kmip_version=kmip_version ) if self._password is not None: self._password.write( local_stream, kmip_version=kmip_version ) if self._device_identifier is not None: self._device_identifier.write( local_stream, kmip_version=kmip_version ) if self._network_identifier is not None: self._network_identifier.write( local_stream, kmip_version=kmip_version) if self._machine_identifier is not None: self._machine_identifier.write( local_stream, kmip_version=kmip_version ) if self._media_identifier is not None: self._media_identifier.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(DeviceCredential, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the DeviceCredential 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. """ local_stream = BytearrayStream() if self._device_serial_number is not None: self._device_serial_number.write( local_stream, kmip_version=kmip_version ) if self._password is not None: self._password.write( local_stream, kmip_version=kmip_version ) if self._device_identifier is not None: self._device_identifier.write( local_stream, kmip_version=kmip_version ) if self._network_identifier is not None: self._network_identifier.write( local_stream, kmip_version=kmip_version) if self._machine_identifier is not None: self._machine_identifier.write( local_stream, kmip_version=kmip_version ) if self._media_identifier is not None: self._media_identifier.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(DeviceCredential, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "DeviceCredential", "struct", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L1196-L1245
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_device_serial_number", "is", "not", "None", ":", "self", ".", "_device_serial_number", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_password", "is", "not", "None", ":", "self", ".", "_password", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_device_identifier", "is", "not", "None", ":", "self", ".", "_device_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_network_identifier", "is", "not", "None", ":", "self", ".", "_network_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_machine_identifier", "is", "not", "None", ":", "self", ".", "_machine_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_media_identifier", "is", "not", "None", ":", "self", ".", "_media_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "DeviceCredential", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Credential.read
Read the data encoding the Credential 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 credential type or value are missing from the encoding.
kmip/core/objects.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Credential 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 credential type or value are missing from the encoding. """ super(Credential, self).read(input_stream, kmip_version=kmip_version) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.CREDENTIAL_TYPE, local_stream): self._credential_type = primitives.Enumeration( enum=enums.CredentialType, tag=enums.Tags.CREDENTIAL_TYPE ) self._credential_type.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Credential encoding missing the credential type." ) if self.is_tag_next(enums.Tags.CREDENTIAL_VALUE, local_stream): if self.credential_type == \ enums.CredentialType.USERNAME_AND_PASSWORD: self._credential_value = UsernamePasswordCredential() elif self.credential_type == enums.CredentialType.DEVICE: self._credential_value = DeviceCredential() elif self.credential_type == enums.CredentialType.ATTESTATION: self._credential_value = AttestationCredential() else: raise ValueError( "Credential encoding includes unrecognized credential " "type." ) self._credential_value.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Credential encoding missing the credential value." ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Credential 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 credential type or value are missing from the encoding. """ super(Credential, self).read(input_stream, kmip_version=kmip_version) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.CREDENTIAL_TYPE, local_stream): self._credential_type = primitives.Enumeration( enum=enums.CredentialType, tag=enums.Tags.CREDENTIAL_TYPE ) self._credential_type.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Credential encoding missing the credential type." ) if self.is_tag_next(enums.Tags.CREDENTIAL_VALUE, local_stream): if self.credential_type == \ enums.CredentialType.USERNAME_AND_PASSWORD: self._credential_value = UsernamePasswordCredential() elif self.credential_type == enums.CredentialType.DEVICE: self._credential_value = DeviceCredential() elif self.credential_type == enums.CredentialType.ATTESTATION: self._credential_value = AttestationCredential() else: raise ValueError( "Credential encoding includes unrecognized credential " "type." ) self._credential_value.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Credential encoding missing the credential value." ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "Credential", "struct", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L1658-L1711
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "Credential", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "CREDENTIAL_TYPE", ",", "local_stream", ")", ":", "self", ".", "_credential_type", "=", "primitives", ".", "Enumeration", "(", "enum", "=", "enums", ".", "CredentialType", ",", "tag", "=", "enums", ".", "Tags", ".", "CREDENTIAL_TYPE", ")", "self", ".", "_credential_type", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Credential encoding missing the credential type.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "CREDENTIAL_VALUE", ",", "local_stream", ")", ":", "if", "self", ".", "credential_type", "==", "enums", ".", "CredentialType", ".", "USERNAME_AND_PASSWORD", ":", "self", ".", "_credential_value", "=", "UsernamePasswordCredential", "(", ")", "elif", "self", ".", "credential_type", "==", "enums", ".", "CredentialType", ".", "DEVICE", ":", "self", ".", "_credential_value", "=", "DeviceCredential", "(", ")", "elif", "self", ".", "credential_type", "==", "enums", ".", "CredentialType", ".", "ATTESTATION", ":", "self", ".", "_credential_value", "=", "AttestationCredential", "(", ")", "else", ":", "raise", "ValueError", "(", "\"Credential encoding includes unrecognized credential \"", "\"type.\"", ")", "self", ".", "_credential_value", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Credential encoding missing the credential value.\"", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Credential.write
Write the data encoding the Credential 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 either the credential type or value are not defined.
kmip/core/objects.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Credential 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 either the credential type or value are not defined. """ local_stream = BytearrayStream() if self._credential_type: self._credential_type.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Credential struct missing the credential type." ) if self._credential_value: self._credential_value.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Credential struct missing the credential value." ) self.length = local_stream.length() super(Credential, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Credential 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 either the credential type or value are not defined. """ local_stream = BytearrayStream() if self._credential_type: self._credential_type.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Credential struct missing the credential type." ) if self._credential_value: self._credential_value.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Credential struct missing the credential value." ) self.length = local_stream.length() super(Credential, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "Credential", "struct", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L1713-L1756
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_credential_type", ":", "self", ".", "_credential_type", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Credential struct missing the credential type.\"", ")", "if", "self", ".", "_credential_value", ":", "self", ".", "_credential_value", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Credential struct missing the credential value.\"", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "Credential", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
MACSignatureKeyInformation.read
Read the data encoding the MACSignatureKeyInformation 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.
kmip/core/objects.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the MACSignatureKeyInformation 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. """ super(MACSignatureKeyInformation, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the unique identifier attribute." ) if self.is_tag_next( enums.Tags.CRYPTOGRAPHIC_PARAMETERS, local_stream ): self._cryptographic_parameters = CryptographicParameters() self._cryptographic_parameters.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the MACSignatureKeyInformation 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. """ super(MACSignatureKeyInformation, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the unique identifier attribute." ) if self.is_tag_next( enums.Tags.CRYPTOGRAPHIC_PARAMETERS, local_stream ): self._cryptographic_parameters = CryptographicParameters() self._cryptographic_parameters.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "MACSignatureKeyInformation", "struct", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L2269-L2311
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "MACSignatureKeyInformation", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "self", ".", "_unique_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid struct missing the unique identifier attribute.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "CRYPTOGRAPHIC_PARAMETERS", ",", "local_stream", ")", ":", "self", ".", "_cryptographic_parameters", "=", "CryptographicParameters", "(", ")", "self", ".", "_cryptographic_parameters", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
MACSignatureKeyInformation.write
Write the data encoding the MACSignatureKeyInformation 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.
kmip/core/objects.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the MACSignatureKeyInformation 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. """ local_stream = BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the unique identifier attribute." ) if self._cryptographic_parameters: self._cryptographic_parameters.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(MACSignatureKeyInformation, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the MACSignatureKeyInformation 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. """ local_stream = BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the unique identifier attribute." ) if self._cryptographic_parameters: self._cryptographic_parameters.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(MACSignatureKeyInformation, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "MACSignatureKeyInformation", "struct", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L2313-L2349
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_unique_identifier", ":", "self", ".", "_unique_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid struct missing the unique identifier attribute.\"", ")", "if", "self", ".", "_cryptographic_parameters", ":", "self", ".", "_cryptographic_parameters", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "MACSignatureKeyInformation", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KeyWrappingData.read
Read the data encoding the KeyWrappingData 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.
kmip/core/objects.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the KeyWrappingData 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. """ super(KeyWrappingData, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.WRAPPING_METHOD, local_stream): self._wrapping_method = primitives.Enumeration( enum=enums.WrappingMethod, tag=enums.Tags.WRAPPING_METHOD ) self._wrapping_method.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the wrapping method attribute." ) if self.is_tag_next( enums.Tags.ENCRYPTION_KEY_INFORMATION, local_stream ): self._encryption_key_information = EncryptionKeyInformation() self._encryption_key_information.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next( enums.Tags.MAC_SIGNATURE_KEY_INFORMATION, local_stream ): self._mac_signature_key_information = MACSignatureKeyInformation() self._mac_signature_key_information.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.MAC_SIGNATURE, local_stream): self._mac_signature = primitives.ByteString( tag=enums.Tags.MAC_SIGNATURE ) self._mac_signature.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.IV_COUNTER_NONCE, local_stream): self._iv_counter_nonce = primitives.ByteString( tag=enums.Tags.IV_COUNTER_NONCE ) self._iv_counter_nonce.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.ENCODING_OPTION, local_stream): self._encoding_option = primitives.Enumeration( enum=enums.EncodingOption, tag=enums.Tags.ENCODING_OPTION ) self._encoding_option.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the KeyWrappingData 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. """ super(KeyWrappingData, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.WRAPPING_METHOD, local_stream): self._wrapping_method = primitives.Enumeration( enum=enums.WrappingMethod, tag=enums.Tags.WRAPPING_METHOD ) self._wrapping_method.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the wrapping method attribute." ) if self.is_tag_next( enums.Tags.ENCRYPTION_KEY_INFORMATION, local_stream ): self._encryption_key_information = EncryptionKeyInformation() self._encryption_key_information.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next( enums.Tags.MAC_SIGNATURE_KEY_INFORMATION, local_stream ): self._mac_signature_key_information = MACSignatureKeyInformation() self._mac_signature_key_information.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.MAC_SIGNATURE, local_stream): self._mac_signature = primitives.ByteString( tag=enums.Tags.MAC_SIGNATURE ) self._mac_signature.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.IV_COUNTER_NONCE, local_stream): self._iv_counter_nonce = primitives.ByteString( tag=enums.Tags.IV_COUNTER_NONCE ) self._iv_counter_nonce.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.ENCODING_OPTION, local_stream): self._encoding_option = primitives.Enumeration( enum=enums.EncodingOption, tag=enums.Tags.ENCODING_OPTION ) self._encoding_option.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "KeyWrappingData", "struct", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L2555-L2635
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "KeyWrappingData", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "WRAPPING_METHOD", ",", "local_stream", ")", ":", "self", ".", "_wrapping_method", "=", "primitives", ".", "Enumeration", "(", "enum", "=", "enums", ".", "WrappingMethod", ",", "tag", "=", "enums", ".", "Tags", ".", "WRAPPING_METHOD", ")", "self", ".", "_wrapping_method", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid struct missing the wrapping method attribute.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ENCRYPTION_KEY_INFORMATION", ",", "local_stream", ")", ":", "self", ".", "_encryption_key_information", "=", "EncryptionKeyInformation", "(", ")", "self", ".", "_encryption_key_information", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "MAC_SIGNATURE_KEY_INFORMATION", ",", "local_stream", ")", ":", "self", ".", "_mac_signature_key_information", "=", "MACSignatureKeyInformation", "(", ")", "self", ".", "_mac_signature_key_information", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "MAC_SIGNATURE", ",", "local_stream", ")", ":", "self", ".", "_mac_signature", "=", "primitives", ".", "ByteString", "(", "tag", "=", "enums", ".", "Tags", ".", "MAC_SIGNATURE", ")", "self", ".", "_mac_signature", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "IV_COUNTER_NONCE", ",", "local_stream", ")", ":", "self", ".", "_iv_counter_nonce", "=", "primitives", ".", "ByteString", "(", "tag", "=", "enums", ".", "Tags", ".", "IV_COUNTER_NONCE", ")", "self", ".", "_iv_counter_nonce", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ENCODING_OPTION", ",", "local_stream", ")", ":", "self", ".", "_encoding_option", "=", "primitives", ".", "Enumeration", "(", "enum", "=", "enums", ".", "EncodingOption", ",", "tag", "=", "enums", ".", "Tags", ".", "ENCODING_OPTION", ")", "self", ".", "_encoding_option", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KeyWrappingData.write
Write the data encoding the KeyWrappingData 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.
kmip/core/objects.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the KeyWrappingData 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. """ local_stream = BytearrayStream() if self._wrapping_method: self._wrapping_method.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the wrapping method attribute." ) if self._encryption_key_information: self._encryption_key_information.write( local_stream, kmip_version=kmip_version ) if self._mac_signature_key_information: self._mac_signature_key_information.write( local_stream, kmip_version=kmip_version ) if self._mac_signature: self._mac_signature.write( local_stream, kmip_version=kmip_version ) if self._iv_counter_nonce: self._iv_counter_nonce.write( local_stream, kmip_version=kmip_version ) if self._encoding_option: self._encoding_option.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(KeyWrappingData, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the KeyWrappingData 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. """ local_stream = BytearrayStream() if self._wrapping_method: self._wrapping_method.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the wrapping method attribute." ) if self._encryption_key_information: self._encryption_key_information.write( local_stream, kmip_version=kmip_version ) if self._mac_signature_key_information: self._mac_signature_key_information.write( local_stream, kmip_version=kmip_version ) if self._mac_signature: self._mac_signature.write( local_stream, kmip_version=kmip_version ) if self._iv_counter_nonce: self._iv_counter_nonce.write( local_stream, kmip_version=kmip_version ) if self._encoding_option: self._encoding_option.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(KeyWrappingData, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "KeyWrappingData", "struct", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L2637-L2692
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_wrapping_method", ":", "self", ".", "_wrapping_method", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid struct missing the wrapping method attribute.\"", ")", "if", "self", ".", "_encryption_key_information", ":", "self", ".", "_encryption_key_information", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_mac_signature_key_information", ":", "self", ".", "_mac_signature_key_information", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_mac_signature", ":", "self", ".", "_mac_signature", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_iv_counter_nonce", ":", "self", ".", "_iv_counter_nonce", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_encoding_option", ":", "self", ".", "_encoding_option", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "KeyWrappingData", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KeyWrappingSpecification.read
Read the data encoding the KeyWrappingSpecification 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.
kmip/core/objects.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the KeyWrappingSpecification 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. """ super(KeyWrappingSpecification, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.WRAPPING_METHOD, local_stream): self._wrapping_method = primitives.Enumeration( enum=enums.WrappingMethod, tag=enums.Tags.WRAPPING_METHOD ) self._wrapping_method.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the wrapping method attribute." ) if self.is_tag_next( enums.Tags.ENCRYPTION_KEY_INFORMATION, local_stream ): self._encryption_key_information = EncryptionKeyInformation() self._encryption_key_information.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next( enums.Tags.MAC_SIGNATURE_KEY_INFORMATION, local_stream ): self._mac_signature_key_information = MACSignatureKeyInformation() self._mac_signature_key_information.read( local_stream, kmip_version=kmip_version ) attribute_names = [] while self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, local_stream): attribute_name = primitives.TextString( tag=enums.Tags.ATTRIBUTE_NAME ) attribute_name.read(local_stream, kmip_version=kmip_version) attribute_names.append(attribute_name) self._attribute_names = attribute_names if self.is_tag_next(enums.Tags.ENCODING_OPTION, local_stream): self._encoding_option = primitives.Enumeration( enum=enums.EncodingOption, tag=enums.Tags.ENCODING_OPTION ) self._encoding_option.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the KeyWrappingSpecification 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. """ super(KeyWrappingSpecification, self).read( input_stream, kmip_version=kmip_version ) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.WRAPPING_METHOD, local_stream): self._wrapping_method = primitives.Enumeration( enum=enums.WrappingMethod, tag=enums.Tags.WRAPPING_METHOD ) self._wrapping_method.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the wrapping method attribute." ) if self.is_tag_next( enums.Tags.ENCRYPTION_KEY_INFORMATION, local_stream ): self._encryption_key_information = EncryptionKeyInformation() self._encryption_key_information.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next( enums.Tags.MAC_SIGNATURE_KEY_INFORMATION, local_stream ): self._mac_signature_key_information = MACSignatureKeyInformation() self._mac_signature_key_information.read( local_stream, kmip_version=kmip_version ) attribute_names = [] while self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, local_stream): attribute_name = primitives.TextString( tag=enums.Tags.ATTRIBUTE_NAME ) attribute_name.read(local_stream, kmip_version=kmip_version) attribute_names.append(attribute_name) self._attribute_names = attribute_names if self.is_tag_next(enums.Tags.ENCODING_OPTION, local_stream): self._encoding_option = primitives.Enumeration( enum=enums.EncodingOption, tag=enums.Tags.ENCODING_OPTION ) self._encoding_option.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "KeyWrappingSpecification", "struct", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L2903-L2974
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "KeyWrappingSpecification", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "WRAPPING_METHOD", ",", "local_stream", ")", ":", "self", ".", "_wrapping_method", "=", "primitives", ".", "Enumeration", "(", "enum", "=", "enums", ".", "WrappingMethod", ",", "tag", "=", "enums", ".", "Tags", ".", "WRAPPING_METHOD", ")", "self", ".", "_wrapping_method", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid struct missing the wrapping method attribute.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ENCRYPTION_KEY_INFORMATION", ",", "local_stream", ")", ":", "self", ".", "_encryption_key_information", "=", "EncryptionKeyInformation", "(", ")", "self", ".", "_encryption_key_information", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "MAC_SIGNATURE_KEY_INFORMATION", ",", "local_stream", ")", ":", "self", ".", "_mac_signature_key_information", "=", "MACSignatureKeyInformation", "(", ")", "self", ".", "_mac_signature_key_information", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "attribute_names", "=", "[", "]", "while", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ATTRIBUTE_NAME", ",", "local_stream", ")", ":", "attribute_name", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "ATTRIBUTE_NAME", ")", "attribute_name", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "attribute_names", ".", "append", "(", "attribute_name", ")", "self", ".", "_attribute_names", "=", "attribute_names", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ENCODING_OPTION", ",", "local_stream", ")", ":", "self", ".", "_encoding_option", "=", "primitives", ".", "Enumeration", "(", "enum", "=", "enums", ".", "EncodingOption", ",", "tag", "=", "enums", ".", "Tags", ".", "ENCODING_OPTION", ")", "self", ".", "_encoding_option", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KeyWrappingSpecification.write
Write the data encoding the KeyWrappingSpecification 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.
kmip/core/objects.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the KeyWrappingSpecification 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. """ local_stream = BytearrayStream() if self._wrapping_method: self._wrapping_method.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the wrapping method attribute." ) if self._encryption_key_information: self._encryption_key_information.write( local_stream, kmip_version=kmip_version ) if self._mac_signature_key_information: self._mac_signature_key_information.write( local_stream, kmip_version=kmip_version ) if self._attribute_names: for unique_identifier in self._attribute_names: unique_identifier.write( local_stream, kmip_version=kmip_version ) if self._encoding_option: self._encoding_option.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(KeyWrappingSpecification, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the KeyWrappingSpecification 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. """ local_stream = BytearrayStream() if self._wrapping_method: self._wrapping_method.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "Invalid struct missing the wrapping method attribute." ) if self._encryption_key_information: self._encryption_key_information.write( local_stream, kmip_version=kmip_version ) if self._mac_signature_key_information: self._mac_signature_key_information.write( local_stream, kmip_version=kmip_version ) if self._attribute_names: for unique_identifier in self._attribute_names: unique_identifier.write( local_stream, kmip_version=kmip_version ) if self._encoding_option: self._encoding_option.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(KeyWrappingSpecification, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "KeyWrappingSpecification", "struct", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L2976-L3028
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_wrapping_method", ":", "self", ".", "_wrapping_method", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid struct missing the wrapping method attribute.\"", ")", "if", "self", ".", "_encryption_key_information", ":", "self", ".", "_encryption_key_information", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_mac_signature_key_information", ":", "self", ".", "_mac_signature_key_information", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_attribute_names", ":", "for", "unique_identifier", "in", "self", ".", "_attribute_names", ":", "unique_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_encoding_option", ":", "self", ".", "_encoding_option", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "KeyWrappingSpecification", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ExtensionInformation.read
Read the data encoding the ExtensionInformation 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.
kmip/core/objects.py
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the ExtensionInformation 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. """ super(ExtensionInformation, self).read( istream, kmip_version=kmip_version ) tstream = BytearrayStream(istream.read(self.length)) self.extension_name.read(tstream, kmip_version=kmip_version) if self.is_tag_next(Tags.EXTENSION_TAG, tstream): self.extension_tag = ExtensionTag() self.extension_tag.read(tstream, kmip_version=kmip_version) if self.is_tag_next(Tags.EXTENSION_TYPE, tstream): self.extension_type = ExtensionType() self.extension_type.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream) self.validate()
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the ExtensionInformation 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. """ super(ExtensionInformation, self).read( istream, kmip_version=kmip_version ) tstream = BytearrayStream(istream.read(self.length)) self.extension_name.read(tstream, kmip_version=kmip_version) if self.is_tag_next(Tags.EXTENSION_TAG, tstream): self.extension_tag = ExtensionTag() self.extension_tag.read(tstream, kmip_version=kmip_version) if self.is_tag_next(Tags.EXTENSION_TYPE, tstream): self.extension_type = ExtensionType() self.extension_type.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream) self.validate()
[ "Read", "the", "data", "encoding", "the", "ExtensionInformation", "object", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3365-L3393
[ "def", "read", "(", "self", ",", "istream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "ExtensionInformation", ",", "self", ")", ".", "read", "(", "istream", ",", "kmip_version", "=", "kmip_version", ")", "tstream", "=", "BytearrayStream", "(", "istream", ".", "read", "(", "self", ".", "length", ")", ")", "self", ".", "extension_name", ".", "read", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "Tags", ".", "EXTENSION_TAG", ",", "tstream", ")", ":", "self", ".", "extension_tag", "=", "ExtensionTag", "(", ")", "self", ".", "extension_tag", ".", "read", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "Tags", ".", "EXTENSION_TYPE", ",", "tstream", ")", ":", "self", ".", "extension_type", "=", "ExtensionType", "(", ")", "self", ".", "extension_type", ".", "read", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "tstream", ")", "self", ".", "validate", "(", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ExtensionInformation.write
Write the data encoding the ExtensionInformation 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.
kmip/core/objects.py
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the ExtensionInformation 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. """ tstream = BytearrayStream() self.extension_name.write(tstream, kmip_version=kmip_version) if self.extension_tag is not None: self.extension_tag.write(tstream, kmip_version=kmip_version) if self.extension_type is not None: self.extension_type.write(tstream, kmip_version=kmip_version) self.length = tstream.length() super(ExtensionInformation, self).write( ostream, kmip_version=kmip_version ) ostream.write(tstream.buffer)
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the ExtensionInformation 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. """ tstream = BytearrayStream() self.extension_name.write(tstream, kmip_version=kmip_version) if self.extension_tag is not None: self.extension_tag.write(tstream, kmip_version=kmip_version) if self.extension_type is not None: self.extension_type.write(tstream, kmip_version=kmip_version) self.length = tstream.length() super(ExtensionInformation, self).write( ostream, kmip_version=kmip_version ) ostream.write(tstream.buffer)
[ "Write", "the", "data", "encoding", "the", "ExtensionInformation", "object", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3395-L3420
[ "def", "write", "(", "self", ",", "ostream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "tstream", "=", "BytearrayStream", "(", ")", "self", ".", "extension_name", ".", "write", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "extension_tag", "is", "not", "None", ":", "self", ".", "extension_tag", ".", "write", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "extension_type", "is", "not", "None", ":", "self", ".", "extension_type", ".", "write", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "tstream", ".", "length", "(", ")", "super", "(", "ExtensionInformation", ",", "self", ")", ".", "write", "(", "ostream", ",", "kmip_version", "=", "kmip_version", ")", "ostream", ".", "write", "(", "tstream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ExtensionInformation.create
Construct an ExtensionInformation object from provided extension values. Args: extension_name (str): The name of the extension. Optional, defaults to None. extension_tag (int): The tag number of the extension. Optional, defaults to None. extension_type (int): The type index of the extension. Optional, defaults to None. Returns: ExtensionInformation: The newly created set of extension information. Example: >>> x = ExtensionInformation.create('extension', 1, 1) >>> x.extension_name.value ExtensionName(value='extension') >>> x.extension_tag.value ExtensionTag(value=1) >>> x.extension_type.value ExtensionType(value=1)
kmip/core/objects.py
def create(cls, extension_name=None, extension_tag=None, extension_type=None): """ Construct an ExtensionInformation object from provided extension values. Args: extension_name (str): The name of the extension. Optional, defaults to None. extension_tag (int): The tag number of the extension. Optional, defaults to None. extension_type (int): The type index of the extension. Optional, defaults to None. Returns: ExtensionInformation: The newly created set of extension information. Example: >>> x = ExtensionInformation.create('extension', 1, 1) >>> x.extension_name.value ExtensionName(value='extension') >>> x.extension_tag.value ExtensionTag(value=1) >>> x.extension_type.value ExtensionType(value=1) """ extension_name = ExtensionName(extension_name) extension_tag = ExtensionTag(extension_tag) extension_type = ExtensionType(extension_type) return ExtensionInformation( extension_name=extension_name, extension_tag=extension_tag, extension_type=extension_type)
def create(cls, extension_name=None, extension_tag=None, extension_type=None): """ Construct an ExtensionInformation object from provided extension values. Args: extension_name (str): The name of the extension. Optional, defaults to None. extension_tag (int): The tag number of the extension. Optional, defaults to None. extension_type (int): The type index of the extension. Optional, defaults to None. Returns: ExtensionInformation: The newly created set of extension information. Example: >>> x = ExtensionInformation.create('extension', 1, 1) >>> x.extension_name.value ExtensionName(value='extension') >>> x.extension_tag.value ExtensionTag(value=1) >>> x.extension_type.value ExtensionType(value=1) """ extension_name = ExtensionName(extension_name) extension_tag = ExtensionTag(extension_tag) extension_type = ExtensionType(extension_type) return ExtensionInformation( extension_name=extension_name, extension_tag=extension_tag, extension_type=extension_type)
[ "Construct", "an", "ExtensionInformation", "object", "from", "provided", "extension", "values", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3478-L3512
[ "def", "create", "(", "cls", ",", "extension_name", "=", "None", ",", "extension_tag", "=", "None", ",", "extension_type", "=", "None", ")", ":", "extension_name", "=", "ExtensionName", "(", "extension_name", ")", "extension_tag", "=", "ExtensionTag", "(", "extension_tag", ")", "extension_type", "=", "ExtensionType", "(", "extension_type", ")", "return", "ExtensionInformation", "(", "extension_name", "=", "extension_name", ",", "extension_tag", "=", "extension_tag", ",", "extension_type", "=", "extension_type", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
RevocationReason.read
Read the data encoding the RevocationReason 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.
kmip/core/objects.py
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the RevocationReason 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. """ super(RevocationReason, self).read(istream, kmip_version=kmip_version) tstream = BytearrayStream(istream.read(self.length)) self.revocation_code = RevocationReasonCode() self.revocation_code.read(tstream, kmip_version=kmip_version) if self.is_tag_next(Tags.REVOCATION_MESSAGE, tstream): self.revocation_message = TextString() self.revocation_message.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream) self.validate()
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the RevocationReason 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. """ super(RevocationReason, self).read(istream, kmip_version=kmip_version) tstream = BytearrayStream(istream.read(self.length)) self.revocation_code = RevocationReasonCode() self.revocation_code.read(tstream, kmip_version=kmip_version) if self.is_tag_next(Tags.REVOCATION_MESSAGE, tstream): self.revocation_message = TextString() self.revocation_message.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream) self.validate()
[ "Read", "the", "data", "encoding", "the", "RevocationReason", "object", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3574-L3597
[ "def", "read", "(", "self", ",", "istream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "RevocationReason", ",", "self", ")", ".", "read", "(", "istream", ",", "kmip_version", "=", "kmip_version", ")", "tstream", "=", "BytearrayStream", "(", "istream", ".", "read", "(", "self", ".", "length", ")", ")", "self", ".", "revocation_code", "=", "RevocationReasonCode", "(", ")", "self", ".", "revocation_code", ".", "read", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "Tags", ".", "REVOCATION_MESSAGE", ",", "tstream", ")", ":", "self", ".", "revocation_message", "=", "TextString", "(", ")", "self", ".", "revocation_message", ".", "read", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "tstream", ")", "self", ".", "validate", "(", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
RevocationReason.write
Write the data encoding the RevocationReason 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.
kmip/core/objects.py
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the RevocationReason 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. """ tstream = BytearrayStream() self.revocation_code.write(tstream, kmip_version=kmip_version) if self.revocation_message is not None: self.revocation_message.write(tstream, kmip_version=kmip_version) # Write the length and value self.length = tstream.length() super(RevocationReason, self).write(ostream, kmip_version=kmip_version) ostream.write(tstream.buffer)
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the RevocationReason 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. """ tstream = BytearrayStream() self.revocation_code.write(tstream, kmip_version=kmip_version) if self.revocation_message is not None: self.revocation_message.write(tstream, kmip_version=kmip_version) # Write the length and value self.length = tstream.length() super(RevocationReason, self).write(ostream, kmip_version=kmip_version) ostream.write(tstream.buffer)
[ "Write", "the", "data", "encoding", "the", "RevocationReason", "object", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3599-L3619
[ "def", "write", "(", "self", ",", "ostream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "tstream", "=", "BytearrayStream", "(", ")", "self", ".", "revocation_code", ".", "write", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "revocation_message", "is", "not", "None", ":", "self", ".", "revocation_message", ".", "write", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "# Write the length and value", "self", ".", "length", "=", "tstream", ".", "length", "(", ")", "super", "(", "RevocationReason", ",", "self", ")", ".", "write", "(", "ostream", ",", "kmip_version", "=", "kmip_version", ")", "ostream", ".", "write", "(", "tstream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
RevocationReason.validate
validate the RevocationReason object
kmip/core/objects.py
def validate(self): """ validate the RevocationReason object """ if not isinstance(self.revocation_code, RevocationReasonCode): msg = "RevocationReaonCode expected" raise TypeError(msg) if self.revocation_message is not None: if not isinstance(self.revocation_message, TextString): msg = "TextString expect" raise TypeError(msg)
def validate(self): """ validate the RevocationReason object """ if not isinstance(self.revocation_code, RevocationReasonCode): msg = "RevocationReaonCode expected" raise TypeError(msg) if self.revocation_message is not None: if not isinstance(self.revocation_message, TextString): msg = "TextString expect" raise TypeError(msg)
[ "validate", "the", "RevocationReason", "object" ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3621-L3631
[ "def", "validate", "(", "self", ")", ":", "if", "not", "isinstance", "(", "self", ".", "revocation_code", ",", "RevocationReasonCode", ")", ":", "msg", "=", "\"RevocationReaonCode expected\"", "raise", "TypeError", "(", "msg", ")", "if", "self", ".", "revocation_message", "is", "not", "None", ":", "if", "not", "isinstance", "(", "self", ".", "revocation_message", ",", "TextString", ")", ":", "msg", "=", "\"TextString expect\"", "raise", "TypeError", "(", "msg", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ObjectDefaults.read
Read the data encoding the ObjectDefaults structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the object type or attributes are missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the ObjectDefaults structure.
kmip/core/objects.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Read the data encoding the ObjectDefaults structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the object type or attributes are missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the ObjectDefaults structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the ObjectDefaults object.".format( kmip_version.value ) ) super(ObjectDefaults, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer): self._object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE ) self._object_type.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The ObjectDefaults encoding is missing the object type " "enumeration." ) if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer): self._attributes = Attributes() self._attributes.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The ObjectDefaults encoding is missing the attributes " "structure." ) self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Read the data encoding the ObjectDefaults structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the object type or attributes are missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the ObjectDefaults structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the ObjectDefaults object.".format( kmip_version.value ) ) super(ObjectDefaults, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer): self._object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE ) self._object_type.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The ObjectDefaults encoding is missing the object type " "enumeration." ) if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer): self._attributes = Attributes() self._attributes.read(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidKmipEncoding( "The ObjectDefaults encoding is missing the attributes " "structure." ) self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "ObjectDefaults", "structure", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3700-L3753
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the ObjectDefaults object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "super", "(", "ObjectDefaults", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "OBJECT_TYPE", ",", "local_buffer", ")", ":", "self", ".", "_object_type", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "ObjectType", ",", "tag", "=", "enums", ".", "Tags", ".", "OBJECT_TYPE", ")", "self", ".", "_object_type", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The ObjectDefaults encoding is missing the object type \"", "\"enumeration.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ATTRIBUTES", ",", "local_buffer", ")", ":", "self", ".", "_attributes", "=", "Attributes", "(", ")", "self", ".", "_attributes", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The ObjectDefaults encoding is missing the attributes \"", "\"structure.\"", ")", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ObjectDefaults.write
Write the ObjectDefaults structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the object type or attributes fields are not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the ObjectDefaults structure.
kmip/core/objects.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Write the ObjectDefaults structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the object type or attributes fields are not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the ObjectDefaults structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the ObjectDefaults object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The ObjectDefaults structure is missing the object type " "field." ) if self._attributes: self._attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The ObjectDefaults structure is missing the attributes field." ) self.length = local_buffer.length() super(ObjectDefaults, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Write the ObjectDefaults structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the object type or attributes fields are not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the ObjectDefaults structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the ObjectDefaults object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._object_type: self._object_type.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The ObjectDefaults structure is missing the object type " "field." ) if self._attributes: self._attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The ObjectDefaults structure is missing the attributes field." ) self.length = local_buffer.length() super(ObjectDefaults, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "ObjectDefaults", "structure", "encoding", "to", "the", "data", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3755-L3801
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the ObjectDefaults object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "local_buffer", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_object_type", ":", "self", ".", "_object_type", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The ObjectDefaults structure is missing the object type \"", "\"field.\"", ")", "if", "self", ".", "_attributes", ":", "self", ".", "_attributes", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The ObjectDefaults structure is missing the attributes field.\"", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "ObjectDefaults", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
DefaultsInformation.read
Read the data encoding the DefaultsInformation structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the object defaults are missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the DefaultsInformation structure.
kmip/core/objects.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Read the data encoding the DefaultsInformation structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the object defaults are missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the DefaultsInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the DefaultsInformation " "object.".format( kmip_version.value ) ) super(DefaultsInformation, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) object_defaults = [] while self.is_tag_next(enums.Tags.OBJECT_DEFAULTS, local_buffer): object_default = ObjectDefaults() object_default.read(local_buffer, kmip_version=kmip_version) object_defaults.append(object_default) if len(object_defaults) == 0: raise exceptions.InvalidKmipEncoding( "The DefaultsInformation encoding is missing the object " "defaults structure." ) else: self._object_defaults = object_defaults self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Read the data encoding the DefaultsInformation structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the object defaults are missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the DefaultsInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the DefaultsInformation " "object.".format( kmip_version.value ) ) super(DefaultsInformation, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) object_defaults = [] while self.is_tag_next(enums.Tags.OBJECT_DEFAULTS, local_buffer): object_default = ObjectDefaults() object_default.read(local_buffer, kmip_version=kmip_version) object_defaults.append(object_default) if len(object_defaults) == 0: raise exceptions.InvalidKmipEncoding( "The DefaultsInformation encoding is missing the object " "defaults structure." ) else: self._object_defaults = object_defaults self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "DefaultsInformation", "structure", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3884-L3931
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the DefaultsInformation \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "super", "(", "DefaultsInformation", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "object_defaults", "=", "[", "]", "while", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "OBJECT_DEFAULTS", ",", "local_buffer", ")", ":", "object_default", "=", "ObjectDefaults", "(", ")", "object_default", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "object_defaults", ".", "append", "(", "object_default", ")", "if", "len", "(", "object_defaults", ")", "==", "0", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The DefaultsInformation encoding is missing the object \"", "\"defaults structure.\"", ")", "else", ":", "self", ".", "_object_defaults", "=", "object_defaults", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
DefaultsInformation.write
Write the DefaultsInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the object defaults field is not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the DefaultsInformation structure.
kmip/core/objects.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Write the DefaultsInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the object defaults field is not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the DefaultsInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the DefaultsInformation " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._object_defaults: for object_default in self._object_defaults: object_default.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The DefaultsInformation structure is missing the object " "defaults field." ) self.length = local_buffer.length() super(DefaultsInformation, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0): """ Write the DefaultsInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the object defaults field is not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the DefaultsInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_2_0: raise exceptions.VersionNotSupported( "KMIP {} does not support the DefaultsInformation " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._object_defaults: for object_default in self._object_defaults: object_default.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The DefaultsInformation structure is missing the object " "defaults field." ) self.length = local_buffer.length() super(DefaultsInformation, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "DefaultsInformation", "structure", "encoding", "to", "the", "data", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L3933-L3973
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the DefaultsInformation \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "local_buffer", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_object_defaults", ":", "for", "object_default", "in", "self", ".", "_object_defaults", ":", "object_default", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The DefaultsInformation structure is missing the object \"", "\"defaults field.\"", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "DefaultsInformation", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
RNGParameters.read
Read the data encoding the RNGParameters structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the RNG algorithm is missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the RNGParameters structure.
kmip/core/objects.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Read the data encoding the RNGParameters structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the RNG algorithm is missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the RNGParameters structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the RNGParameters object.".format( kmip_version.value ) ) super(RNGParameters, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.RNG_ALGORITHM, local_buffer): rng_algorithm = primitives.Enumeration( enums.RNGAlgorithm, tag=enums.Tags.RNG_ALGORITHM ) rng_algorithm.read(local_buffer, kmip_version=kmip_version) self._rng_algorithm = rng_algorithm else: raise exceptions.InvalidKmipEncoding( "The RNGParameters encoding is missing the RNG algorithm." ) if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_ALGORITHM, local_buffer): cryptographic_algorithm = primitives.Enumeration( enums.CryptographicAlgorithm, tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM ) cryptographic_algorithm.read( local_buffer, kmip_version=kmip_version ) self._cryptographic_algorithm = cryptographic_algorithm if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_LENGTH, local_buffer): cryptographic_length = primitives.Integer( tag=enums.Tags.CRYPTOGRAPHIC_LENGTH ) cryptographic_length.read(local_buffer, kmip_version=kmip_version) self._cryptographic_length = cryptographic_length if self.is_tag_next(enums.Tags.HASHING_ALGORITHM, local_buffer): hashing_algorithm = primitives.Enumeration( enums.HashingAlgorithm, tag=enums.Tags.HASHING_ALGORITHM ) hashing_algorithm.read(local_buffer, kmip_version=kmip_version) self._hashing_algorithm = hashing_algorithm if self.is_tag_next(enums.Tags.DRBG_ALGORITHM, local_buffer): drbg_algorithm = primitives.Enumeration( enums.DRBGAlgorithm, tag=enums.Tags.DRBG_ALGORITHM ) drbg_algorithm.read(local_buffer, kmip_version=kmip_version) self._drbg_algorithm = drbg_algorithm if self.is_tag_next(enums.Tags.RECOMMENDED_CURVE, local_buffer): recommended_curve = primitives.Enumeration( enums.RecommendedCurve, tag=enums.Tags.RECOMMENDED_CURVE ) recommended_curve.read(local_buffer, kmip_version=kmip_version) self._recommended_curve = recommended_curve if self.is_tag_next(enums.Tags.FIPS186_VARIATION, local_buffer): fips186_variation = primitives.Enumeration( enums.FIPS186Variation, tag=enums.Tags.FIPS186_VARIATION ) fips186_variation.read(local_buffer, kmip_version=kmip_version) self._fips186_variation = fips186_variation if self.is_tag_next(enums.Tags.PREDICTION_RESISTANCE, local_buffer): prediction_resistance = primitives.Boolean( tag=enums.Tags.PREDICTION_RESISTANCE ) prediction_resistance.read( local_buffer, kmip_version=kmip_version ) self._prediction_resistance = prediction_resistance self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Read the data encoding the RNGParameters structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the RNG algorithm is missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the RNGParameters structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the RNGParameters object.".format( kmip_version.value ) ) super(RNGParameters, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.RNG_ALGORITHM, local_buffer): rng_algorithm = primitives.Enumeration( enums.RNGAlgorithm, tag=enums.Tags.RNG_ALGORITHM ) rng_algorithm.read(local_buffer, kmip_version=kmip_version) self._rng_algorithm = rng_algorithm else: raise exceptions.InvalidKmipEncoding( "The RNGParameters encoding is missing the RNG algorithm." ) if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_ALGORITHM, local_buffer): cryptographic_algorithm = primitives.Enumeration( enums.CryptographicAlgorithm, tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM ) cryptographic_algorithm.read( local_buffer, kmip_version=kmip_version ) self._cryptographic_algorithm = cryptographic_algorithm if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_LENGTH, local_buffer): cryptographic_length = primitives.Integer( tag=enums.Tags.CRYPTOGRAPHIC_LENGTH ) cryptographic_length.read(local_buffer, kmip_version=kmip_version) self._cryptographic_length = cryptographic_length if self.is_tag_next(enums.Tags.HASHING_ALGORITHM, local_buffer): hashing_algorithm = primitives.Enumeration( enums.HashingAlgorithm, tag=enums.Tags.HASHING_ALGORITHM ) hashing_algorithm.read(local_buffer, kmip_version=kmip_version) self._hashing_algorithm = hashing_algorithm if self.is_tag_next(enums.Tags.DRBG_ALGORITHM, local_buffer): drbg_algorithm = primitives.Enumeration( enums.DRBGAlgorithm, tag=enums.Tags.DRBG_ALGORITHM ) drbg_algorithm.read(local_buffer, kmip_version=kmip_version) self._drbg_algorithm = drbg_algorithm if self.is_tag_next(enums.Tags.RECOMMENDED_CURVE, local_buffer): recommended_curve = primitives.Enumeration( enums.RecommendedCurve, tag=enums.Tags.RECOMMENDED_CURVE ) recommended_curve.read(local_buffer, kmip_version=kmip_version) self._recommended_curve = recommended_curve if self.is_tag_next(enums.Tags.FIPS186_VARIATION, local_buffer): fips186_variation = primitives.Enumeration( enums.FIPS186Variation, tag=enums.Tags.FIPS186_VARIATION ) fips186_variation.read(local_buffer, kmip_version=kmip_version) self._fips186_variation = fips186_variation if self.is_tag_next(enums.Tags.PREDICTION_RESISTANCE, local_buffer): prediction_resistance = primitives.Boolean( tag=enums.Tags.PREDICTION_RESISTANCE ) prediction_resistance.read( local_buffer, kmip_version=kmip_version ) self._prediction_resistance = prediction_resistance self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "RNGParameters", "structure", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L4257-L4361
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the RNGParameters object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "super", "(", "RNGParameters", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "RNG_ALGORITHM", ",", "local_buffer", ")", ":", "rng_algorithm", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "RNGAlgorithm", ",", "tag", "=", "enums", ".", "Tags", ".", "RNG_ALGORITHM", ")", "rng_algorithm", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_rng_algorithm", "=", "rng_algorithm", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The RNGParameters encoding is missing the RNG algorithm.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "CRYPTOGRAPHIC_ALGORITHM", ",", "local_buffer", ")", ":", "cryptographic_algorithm", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "CryptographicAlgorithm", ",", "tag", "=", "enums", ".", "Tags", ".", "CRYPTOGRAPHIC_ALGORITHM", ")", "cryptographic_algorithm", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_cryptographic_algorithm", "=", "cryptographic_algorithm", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "CRYPTOGRAPHIC_LENGTH", ",", "local_buffer", ")", ":", "cryptographic_length", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "CRYPTOGRAPHIC_LENGTH", ")", "cryptographic_length", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_cryptographic_length", "=", "cryptographic_length", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "HASHING_ALGORITHM", ",", "local_buffer", ")", ":", "hashing_algorithm", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "HashingAlgorithm", ",", "tag", "=", "enums", ".", "Tags", ".", "HASHING_ALGORITHM", ")", "hashing_algorithm", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_hashing_algorithm", "=", "hashing_algorithm", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "DRBG_ALGORITHM", ",", "local_buffer", ")", ":", "drbg_algorithm", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "DRBGAlgorithm", ",", "tag", "=", "enums", ".", "Tags", ".", "DRBG_ALGORITHM", ")", "drbg_algorithm", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_drbg_algorithm", "=", "drbg_algorithm", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "RECOMMENDED_CURVE", ",", "local_buffer", ")", ":", "recommended_curve", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "RecommendedCurve", ",", "tag", "=", "enums", ".", "Tags", ".", "RECOMMENDED_CURVE", ")", "recommended_curve", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_recommended_curve", "=", "recommended_curve", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "FIPS186_VARIATION", ",", "local_buffer", ")", ":", "fips186_variation", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "FIPS186Variation", ",", "tag", "=", "enums", ".", "Tags", ".", "FIPS186_VARIATION", ")", "fips186_variation", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_fips186_variation", "=", "fips186_variation", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "PREDICTION_RESISTANCE", ",", "local_buffer", ")", ":", "prediction_resistance", "=", "primitives", ".", "Boolean", "(", "tag", "=", "enums", ".", "Tags", ".", "PREDICTION_RESISTANCE", ")", "prediction_resistance", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_prediction_resistance", "=", "prediction_resistance", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
RNGParameters.write
Write the RNGParameters structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the RNG algorithm field is not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the RNGParameters structure.
kmip/core/objects.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Write the RNGParameters structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the RNG algorithm field is not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the RNGParameters structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the RNGParameters object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._rng_algorithm: self._rng_algorithm.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The RNGParameters structure is missing the RNG algorithm " "field." ) if self._cryptographic_algorithm: self._cryptographic_algorithm.write( local_buffer, kmip_version=kmip_version ) if self._cryptographic_length: self._cryptographic_length.write( local_buffer, kmip_version=kmip_version ) if self._hashing_algorithm: self._hashing_algorithm.write( local_buffer, kmip_version=kmip_version ) if self._drbg_algorithm: self._drbg_algorithm.write( local_buffer, kmip_version=kmip_version ) if self._recommended_curve: self._recommended_curve.write( local_buffer, kmip_version=kmip_version ) if self._fips186_variation: self._fips186_variation.write( local_buffer, kmip_version=kmip_version ) if self._prediction_resistance: self._prediction_resistance.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(RNGParameters, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Write the RNGParameters structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode Attributes structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the RNG algorithm field is not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the RNGParameters structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the RNGParameters object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._rng_algorithm: self._rng_algorithm.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The RNGParameters structure is missing the RNG algorithm " "field." ) if self._cryptographic_algorithm: self._cryptographic_algorithm.write( local_buffer, kmip_version=kmip_version ) if self._cryptographic_length: self._cryptographic_length.write( local_buffer, kmip_version=kmip_version ) if self._hashing_algorithm: self._hashing_algorithm.write( local_buffer, kmip_version=kmip_version ) if self._drbg_algorithm: self._drbg_algorithm.write( local_buffer, kmip_version=kmip_version ) if self._recommended_curve: self._recommended_curve.write( local_buffer, kmip_version=kmip_version ) if self._fips186_variation: self._fips186_variation.write( local_buffer, kmip_version=kmip_version ) if self._prediction_resistance: self._prediction_resistance.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(RNGParameters, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "RNGParameters", "structure", "encoding", "to", "the", "data", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L4363-L4443
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the RNGParameters object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "local_buffer", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_rng_algorithm", ":", "self", ".", "_rng_algorithm", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The RNGParameters structure is missing the RNG algorithm \"", "\"field.\"", ")", "if", "self", ".", "_cryptographic_algorithm", ":", "self", ".", "_cryptographic_algorithm", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_cryptographic_length", ":", "self", ".", "_cryptographic_length", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_hashing_algorithm", ":", "self", ".", "_hashing_algorithm", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_drbg_algorithm", ":", "self", ".", "_drbg_algorithm", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_recommended_curve", ":", "self", ".", "_recommended_curve", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_fips186_variation", ":", "self", ".", "_fips186_variation", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_prediction_resistance", ":", "self", ".", "_prediction_resistance", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "RNGParameters", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ProfileInformation.read
Read the data encoding the ProfileInformation structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the profile name is missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the ProfileInformation structure.
kmip/core/objects.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Read the data encoding the ProfileInformation structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the profile name is missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the ProfileInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the ProfileInformation " "object.".format( kmip_version.value ) ) super(ProfileInformation, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.PROFILE_NAME, local_buffer): profile_name = primitives.Enumeration( enums.ProfileName, tag=enums.Tags.PROFILE_NAME ) profile_name.read(local_buffer, kmip_version=kmip_version) self._profile_name = profile_name else: raise exceptions.InvalidKmipEncoding( "The ProfileInformation encoding is missing the profile name." ) if self.is_tag_next(enums.Tags.SERVER_URI, local_buffer): server_uri = primitives.TextString(tag=enums.Tags.SERVER_URI) server_uri.read(local_buffer, kmip_version=kmip_version) self._server_uri = server_uri if self.is_tag_next(enums.Tags.SERVER_PORT, local_buffer): server_port = primitives.Integer(tag=enums.Tags.SERVER_PORT) server_port.read(local_buffer, kmip_version=kmip_version) self._server_port = server_port self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Read the data encoding the ProfileInformation structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the profile name is missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the ProfileInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the ProfileInformation " "object.".format( kmip_version.value ) ) super(ProfileInformation, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.PROFILE_NAME, local_buffer): profile_name = primitives.Enumeration( enums.ProfileName, tag=enums.Tags.PROFILE_NAME ) profile_name.read(local_buffer, kmip_version=kmip_version) self._profile_name = profile_name else: raise exceptions.InvalidKmipEncoding( "The ProfileInformation encoding is missing the profile name." ) if self.is_tag_next(enums.Tags.SERVER_URI, local_buffer): server_uri = primitives.TextString(tag=enums.Tags.SERVER_URI) server_uri.read(local_buffer, kmip_version=kmip_version) self._server_uri = server_uri if self.is_tag_next(enums.Tags.SERVER_PORT, local_buffer): server_port = primitives.Integer(tag=enums.Tags.SERVER_PORT) server_port.read(local_buffer, kmip_version=kmip_version) self._server_port = server_port self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "ProfileInformation", "structure", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L4604-L4659
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the ProfileInformation \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "super", "(", "ProfileInformation", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "PROFILE_NAME", ",", "local_buffer", ")", ":", "profile_name", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "ProfileName", ",", "tag", "=", "enums", ".", "Tags", ".", "PROFILE_NAME", ")", "profile_name", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_profile_name", "=", "profile_name", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The ProfileInformation encoding is missing the profile name.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "SERVER_URI", ",", "local_buffer", ")", ":", "server_uri", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "SERVER_URI", ")", "server_uri", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_server_uri", "=", "server_uri", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "SERVER_PORT", ",", "local_buffer", ")", ":", "server_port", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "SERVER_PORT", ")", "server_port", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_server_port", "=", "server_port", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ProfileInformation.write
Write the ProfileInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode ProfileInformation structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the profile name field is not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the ProfileInformation structure.
kmip/core/objects.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Write the ProfileInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode ProfileInformation structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the profile name field is not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the ProfileInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the ProfileInformation " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._profile_name: self._profile_name.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The ProfileInformation structure is missing the profile " "name field." ) if self._server_uri: self._server_uri.write(local_buffer, kmip_version=kmip_version) if self._server_port: self._server_port.write(local_buffer, kmip_version=kmip_version) self.length = local_buffer.length() super(ProfileInformation, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Write the ProfileInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode ProfileInformation structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the profile name field is not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the ProfileInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the ProfileInformation " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._profile_name: self._profile_name.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The ProfileInformation structure is missing the profile " "name field." ) if self._server_uri: self._server_uri.write(local_buffer, kmip_version=kmip_version) if self._server_port: self._server_port.write(local_buffer, kmip_version=kmip_version) self.length = local_buffer.length() super(ProfileInformation, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "ProfileInformation", "structure", "encoding", "to", "the", "data", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L4661-L4706
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the ProfileInformation \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "local_buffer", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_profile_name", ":", "self", ".", "_profile_name", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The ProfileInformation structure is missing the profile \"", "\"name field.\"", ")", "if", "self", ".", "_server_uri", ":", "self", ".", "_server_uri", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_server_port", ":", "self", ".", "_server_port", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "ProfileInformation", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ValidationInformation.read
Read the data encoding the ValidationInformation structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the validation authority type, validation version major, validation type, and/or validation level are missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the ValidationInformation structure.
kmip/core/objects.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Read the data encoding the ValidationInformation structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the validation authority type, validation version major, validation type, and/or validation level are missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the ValidationInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the ValidationInformation " "object.".format( kmip_version.value ) ) super(ValidationInformation, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next( enums.Tags.VALIDATION_AUTHORITY_TYPE, local_buffer ): validation_authority_type = primitives.Enumeration( enums.ValidationAuthorityType, tag=enums.Tags.VALIDATION_AUTHORITY_TYPE ) validation_authority_type.read( local_buffer, kmip_version=kmip_version ) self._validation_authority_type = validation_authority_type else: raise exceptions.InvalidKmipEncoding( "The ValidationInformation encoding is missing the " "validation authority type." ) if self.is_tag_next( enums.Tags.VALIDATION_AUTHORITY_COUNTRY, local_buffer ): validation_authority_country = primitives.TextString( tag=enums.Tags.VALIDATION_AUTHORITY_COUNTRY ) validation_authority_country.read( local_buffer, kmip_version=kmip_version ) self._validation_authority_country = validation_authority_country if self.is_tag_next(enums.Tags.VALIDATION_AUTHORITY_URI, local_buffer): validation_authority_uri = primitives.TextString( tag=enums.Tags.VALIDATION_AUTHORITY_URI ) validation_authority_uri.read( local_buffer, kmip_version=kmip_version ) self._validation_authority_uri = validation_authority_uri if self.is_tag_next( enums.Tags.VALIDATION_VERSION_MAJOR, local_buffer ): validation_version_major = primitives.Integer( tag=enums.Tags.VALIDATION_VERSION_MAJOR ) validation_version_major.read( local_buffer, kmip_version=kmip_version ) self._validation_version_major = validation_version_major else: raise exceptions.InvalidKmipEncoding( "The ValidationInformation encoding is missing the " "validation version major." ) if self.is_tag_next( enums.Tags.VALIDATION_VERSION_MINOR, local_buffer ): validation_version_minor = primitives.Integer( tag=enums.Tags.VALIDATION_VERSION_MINOR ) validation_version_minor.read( local_buffer, kmip_version=kmip_version ) self._validation_version_minor = validation_version_minor if self.is_tag_next(enums.Tags.VALIDATION_TYPE, local_buffer): validation_type = primitives.Enumeration( enums.ValidationType, tag=enums.Tags.VALIDATION_TYPE ) validation_type.read( local_buffer, kmip_version=kmip_version ) self._validation_type = validation_type else: raise exceptions.InvalidKmipEncoding( "The ValidationInformation encoding is missing the " "validation type." ) if self.is_tag_next(enums.Tags.VALIDATION_LEVEL, local_buffer): validation_level = primitives.Integer( tag=enums.Tags.VALIDATION_LEVEL ) validation_level.read(local_buffer, kmip_version=kmip_version) self._validation_level = validation_level else: raise exceptions.InvalidKmipEncoding( "The ValidationInformation encoding is missing the " "validation level." ) if self.is_tag_next( enums.Tags.VALIDATION_CERTIFICATE_IDENTIFIER, local_buffer ): validation_certificate_identifier = primitives.TextString( tag=enums.Tags.VALIDATION_CERTIFICATE_IDENTIFIER ) validation_certificate_identifier.read( local_buffer, kmip_version=kmip_version ) self._validation_certificate_identifier = \ validation_certificate_identifier if self.is_tag_next( enums.Tags.VALIDATION_CERTIFICATE_URI, local_buffer ): validation_certificate_uri = primitives.TextString( tag=enums.Tags.VALIDATION_CERTIFICATE_URI ) validation_certificate_uri.read( local_buffer, kmip_version=kmip_version ) self._validation_certificate_uri = validation_certificate_uri if self.is_tag_next(enums.Tags.VALIDATION_VENDOR_URI, local_buffer): validation_vendor_uri = primitives.TextString( tag=enums.Tags.VALIDATION_VENDOR_URI ) validation_vendor_uri.read(local_buffer, kmip_version=kmip_version) self._validation_vendor_uri = validation_vendor_uri validation_profiles = [] while self.is_tag_next(enums.Tags.VALIDATION_PROFILE, local_buffer): validation_profile = primitives.TextString( tag=enums.Tags.VALIDATION_PROFILE ) validation_profile.read(local_buffer, kmip_version=kmip_version) validation_profiles.append(validation_profile) self._validation_profiles = validation_profiles self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Read the data encoding the ValidationInformation structure 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 2.0. Raises: InvalidKmipEncoding: Raised if the validation authority type, validation version major, validation type, and/or validation level are missing from the encoding. VersionNotSupported: Raised when a KMIP version is provided that does not support the ValidationInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the ValidationInformation " "object.".format( kmip_version.value ) ) super(ValidationInformation, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next( enums.Tags.VALIDATION_AUTHORITY_TYPE, local_buffer ): validation_authority_type = primitives.Enumeration( enums.ValidationAuthorityType, tag=enums.Tags.VALIDATION_AUTHORITY_TYPE ) validation_authority_type.read( local_buffer, kmip_version=kmip_version ) self._validation_authority_type = validation_authority_type else: raise exceptions.InvalidKmipEncoding( "The ValidationInformation encoding is missing the " "validation authority type." ) if self.is_tag_next( enums.Tags.VALIDATION_AUTHORITY_COUNTRY, local_buffer ): validation_authority_country = primitives.TextString( tag=enums.Tags.VALIDATION_AUTHORITY_COUNTRY ) validation_authority_country.read( local_buffer, kmip_version=kmip_version ) self._validation_authority_country = validation_authority_country if self.is_tag_next(enums.Tags.VALIDATION_AUTHORITY_URI, local_buffer): validation_authority_uri = primitives.TextString( tag=enums.Tags.VALIDATION_AUTHORITY_URI ) validation_authority_uri.read( local_buffer, kmip_version=kmip_version ) self._validation_authority_uri = validation_authority_uri if self.is_tag_next( enums.Tags.VALIDATION_VERSION_MAJOR, local_buffer ): validation_version_major = primitives.Integer( tag=enums.Tags.VALIDATION_VERSION_MAJOR ) validation_version_major.read( local_buffer, kmip_version=kmip_version ) self._validation_version_major = validation_version_major else: raise exceptions.InvalidKmipEncoding( "The ValidationInformation encoding is missing the " "validation version major." ) if self.is_tag_next( enums.Tags.VALIDATION_VERSION_MINOR, local_buffer ): validation_version_minor = primitives.Integer( tag=enums.Tags.VALIDATION_VERSION_MINOR ) validation_version_minor.read( local_buffer, kmip_version=kmip_version ) self._validation_version_minor = validation_version_minor if self.is_tag_next(enums.Tags.VALIDATION_TYPE, local_buffer): validation_type = primitives.Enumeration( enums.ValidationType, tag=enums.Tags.VALIDATION_TYPE ) validation_type.read( local_buffer, kmip_version=kmip_version ) self._validation_type = validation_type else: raise exceptions.InvalidKmipEncoding( "The ValidationInformation encoding is missing the " "validation type." ) if self.is_tag_next(enums.Tags.VALIDATION_LEVEL, local_buffer): validation_level = primitives.Integer( tag=enums.Tags.VALIDATION_LEVEL ) validation_level.read(local_buffer, kmip_version=kmip_version) self._validation_level = validation_level else: raise exceptions.InvalidKmipEncoding( "The ValidationInformation encoding is missing the " "validation level." ) if self.is_tag_next( enums.Tags.VALIDATION_CERTIFICATE_IDENTIFIER, local_buffer ): validation_certificate_identifier = primitives.TextString( tag=enums.Tags.VALIDATION_CERTIFICATE_IDENTIFIER ) validation_certificate_identifier.read( local_buffer, kmip_version=kmip_version ) self._validation_certificate_identifier = \ validation_certificate_identifier if self.is_tag_next( enums.Tags.VALIDATION_CERTIFICATE_URI, local_buffer ): validation_certificate_uri = primitives.TextString( tag=enums.Tags.VALIDATION_CERTIFICATE_URI ) validation_certificate_uri.read( local_buffer, kmip_version=kmip_version ) self._validation_certificate_uri = validation_certificate_uri if self.is_tag_next(enums.Tags.VALIDATION_VENDOR_URI, local_buffer): validation_vendor_uri = primitives.TextString( tag=enums.Tags.VALIDATION_VENDOR_URI ) validation_vendor_uri.read(local_buffer, kmip_version=kmip_version) self._validation_vendor_uri = validation_vendor_uri validation_profiles = [] while self.is_tag_next(enums.Tags.VALIDATION_PROFILE, local_buffer): validation_profile = primitives.TextString( tag=enums.Tags.VALIDATION_PROFILE ) validation_profile.read(local_buffer, kmip_version=kmip_version) validation_profiles.append(validation_profile) self._validation_profiles = validation_profiles self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "ValidationInformation", "structure", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L5082-L5260
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the ValidationInformation \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "super", "(", "ValidationInformation", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_AUTHORITY_TYPE", ",", "local_buffer", ")", ":", "validation_authority_type", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "ValidationAuthorityType", ",", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_AUTHORITY_TYPE", ")", "validation_authority_type", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_authority_type", "=", "validation_authority_type", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The ValidationInformation encoding is missing the \"", "\"validation authority type.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_AUTHORITY_COUNTRY", ",", "local_buffer", ")", ":", "validation_authority_country", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_AUTHORITY_COUNTRY", ")", "validation_authority_country", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_authority_country", "=", "validation_authority_country", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_AUTHORITY_URI", ",", "local_buffer", ")", ":", "validation_authority_uri", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_AUTHORITY_URI", ")", "validation_authority_uri", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_authority_uri", "=", "validation_authority_uri", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_VERSION_MAJOR", ",", "local_buffer", ")", ":", "validation_version_major", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_VERSION_MAJOR", ")", "validation_version_major", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_version_major", "=", "validation_version_major", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The ValidationInformation encoding is missing the \"", "\"validation version major.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_VERSION_MINOR", ",", "local_buffer", ")", ":", "validation_version_minor", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_VERSION_MINOR", ")", "validation_version_minor", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_version_minor", "=", "validation_version_minor", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_TYPE", ",", "local_buffer", ")", ":", "validation_type", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "ValidationType", ",", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_TYPE", ")", "validation_type", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_type", "=", "validation_type", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The ValidationInformation encoding is missing the \"", "\"validation type.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_LEVEL", ",", "local_buffer", ")", ":", "validation_level", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_LEVEL", ")", "validation_level", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_level", "=", "validation_level", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The ValidationInformation encoding is missing the \"", "\"validation level.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_CERTIFICATE_IDENTIFIER", ",", "local_buffer", ")", ":", "validation_certificate_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_CERTIFICATE_IDENTIFIER", ")", "validation_certificate_identifier", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_certificate_identifier", "=", "validation_certificate_identifier", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_CERTIFICATE_URI", ",", "local_buffer", ")", ":", "validation_certificate_uri", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_CERTIFICATE_URI", ")", "validation_certificate_uri", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_certificate_uri", "=", "validation_certificate_uri", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_VENDOR_URI", ",", "local_buffer", ")", ":", "validation_vendor_uri", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_VENDOR_URI", ")", "validation_vendor_uri", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_validation_vendor_uri", "=", "validation_vendor_uri", "validation_profiles", "=", "[", "]", "while", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "VALIDATION_PROFILE", ",", "local_buffer", ")", ":", "validation_profile", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "VALIDATION_PROFILE", ")", "validation_profile", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "validation_profiles", ".", "append", "(", "validation_profile", ")", "self", ".", "_validation_profiles", "=", "validation_profiles", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ValidationInformation.write
Write the ValidationInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode ValidationInformation structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the validation authority type, validation version major, validation type, and/or validation level fields are not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the ValidationInformation structure.
kmip/core/objects.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Write the ValidationInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode ValidationInformation structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the validation authority type, validation version major, validation type, and/or validation level fields are not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the ValidationInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the ValidationInformation " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._validation_authority_type: self._validation_authority_type.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The ValidationInformation structure is missing the " "validation authority type field." ) if self._validation_authority_country: self._validation_authority_country.write( local_buffer, kmip_version=kmip_version ) if self._validation_authority_uri: self._validation_authority_uri.write( local_buffer, kmip_version=kmip_version ) if self._validation_version_major: self._validation_version_major.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The ValidationInformation structure is missing the " "validation version major field." ) if self._validation_version_minor: self._validation_version_minor.write( local_buffer, kmip_version=kmip_version ) if self._validation_type: self._validation_type.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The ValidationInformation structure is missing the " "validation type field." ) if self._validation_level: self._validation_level.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The ValidationInformation structure is missing the " "validation level field." ) if self._validation_certificate_identifier: self._validation_certificate_identifier.write( local_buffer, kmip_version=kmip_version ) if self._validation_certificate_uri: self._validation_certificate_uri.write( local_buffer, kmip_version=kmip_version ) if self._validation_vendor_uri: self._validation_vendor_uri.write( local_buffer, kmip_version=kmip_version ) if self._validation_profiles: for validation_profile in self._validation_profiles: validation_profile.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(ValidationInformation, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Write the ValidationInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode ValidationInformation structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: InvalidField: Raised if the validation authority type, validation version major, validation type, and/or validation level fields are not defined. VersionNotSupported: Raised when a KMIP version is provided that does not support the ValidationInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the ValidationInformation " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._validation_authority_type: self._validation_authority_type.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The ValidationInformation structure is missing the " "validation authority type field." ) if self._validation_authority_country: self._validation_authority_country.write( local_buffer, kmip_version=kmip_version ) if self._validation_authority_uri: self._validation_authority_uri.write( local_buffer, kmip_version=kmip_version ) if self._validation_version_major: self._validation_version_major.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The ValidationInformation structure is missing the " "validation version major field." ) if self._validation_version_minor: self._validation_version_minor.write( local_buffer, kmip_version=kmip_version ) if self._validation_type: self._validation_type.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The ValidationInformation structure is missing the " "validation type field." ) if self._validation_level: self._validation_level.write( local_buffer, kmip_version=kmip_version ) else: raise exceptions.InvalidField( "The ValidationInformation structure is missing the " "validation level field." ) if self._validation_certificate_identifier: self._validation_certificate_identifier.write( local_buffer, kmip_version=kmip_version ) if self._validation_certificate_uri: self._validation_certificate_uri.write( local_buffer, kmip_version=kmip_version ) if self._validation_vendor_uri: self._validation_vendor_uri.write( local_buffer, kmip_version=kmip_version ) if self._validation_profiles: for validation_profile in self._validation_profiles: validation_profile.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(ValidationInformation, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "ValidationInformation", "structure", "encoding", "to", "the", "data", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L5262-L5383
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the ValidationInformation \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "local_buffer", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_validation_authority_type", ":", "self", ".", "_validation_authority_type", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The ValidationInformation structure is missing the \"", "\"validation authority type field.\"", ")", "if", "self", ".", "_validation_authority_country", ":", "self", ".", "_validation_authority_country", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_validation_authority_uri", ":", "self", ".", "_validation_authority_uri", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_validation_version_major", ":", "self", ".", "_validation_version_major", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The ValidationInformation structure is missing the \"", "\"validation version major field.\"", ")", "if", "self", ".", "_validation_version_minor", ":", "self", ".", "_validation_version_minor", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_validation_type", ":", "self", ".", "_validation_type", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The ValidationInformation structure is missing the \"", "\"validation type field.\"", ")", "if", "self", ".", "_validation_level", ":", "self", ".", "_validation_level", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The ValidationInformation structure is missing the \"", "\"validation level field.\"", ")", "if", "self", ".", "_validation_certificate_identifier", ":", "self", ".", "_validation_certificate_identifier", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_validation_certificate_uri", ":", "self", ".", "_validation_certificate_uri", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_validation_vendor_uri", ":", "self", ".", "_validation_vendor_uri", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_validation_profiles", ":", "for", "validation_profile", "in", "self", ".", "_validation_profiles", ":", "validation_profile", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "ValidationInformation", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CapabilityInformation.read
Read the data encoding the CapabilityInformation structure 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 2.0. Raises: VersionNotSupported: Raised when a KMIP version is provided that does not support the CapabilityInformation structure.
kmip/core/objects.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Read the data encoding the CapabilityInformation structure 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 2.0. Raises: VersionNotSupported: Raised when a KMIP version is provided that does not support the CapabilityInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the CapabilityInformation " "object.".format( kmip_version.value ) ) super(CapabilityInformation, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.STREAMING_CAPABILITY, local_buffer): streaming_capability = primitives.Boolean( tag=enums.Tags.STREAMING_CAPABILITY ) streaming_capability.read(local_buffer, kmip_version=kmip_version) self._streaming_capability = streaming_capability if self.is_tag_next(enums.Tags.ASYNCHRONOUS_CAPABILITY, local_buffer): asynchronous_capability = primitives.Boolean( tag=enums.Tags.ASYNCHRONOUS_CAPABILITY ) asynchronous_capability.read( local_buffer, kmip_version=kmip_version ) self._asynchronous_capability = asynchronous_capability if self.is_tag_next(enums.Tags.ATTESTATION_CAPABILITY, local_buffer): attestation_capability = primitives.Boolean( tag=enums.Tags.ATTESTATION_CAPABILITY ) attestation_capability.read( local_buffer, kmip_version=kmip_version ) self._attestation_capability = attestation_capability if kmip_version >= enums.KMIPVersion.KMIP_1_4: if self.is_tag_next( enums.Tags.BATCH_UNDO_CAPABILITY, local_buffer ): batch_undo_capability = primitives.Boolean( tag=enums.Tags.BATCH_UNDO_CAPABILITY ) batch_undo_capability.read( local_buffer, kmip_version=kmip_version ) self._batch_continue_capability = batch_undo_capability if self.is_tag_next( enums.Tags.BATCH_CONTINUE_CAPABILITY, local_buffer ): batch_continue_capability = primitives.Boolean( tag=enums.Tags.BATCH_CONTINUE_CAPABILITY ) batch_continue_capability.read( local_buffer, kmip_version=kmip_version ) self._batch_continue_capability = batch_continue_capability if self.is_tag_next(enums.Tags.UNWRAP_MODE, local_buffer): unwrap_mode = primitives.Enumeration( enums.UnwrapMode, tag=enums.Tags.UNWRAP_MODE ) unwrap_mode.read(local_buffer, kmip_version=kmip_version) self._unwrap_mode = unwrap_mode if self.is_tag_next(enums.Tags.DESTROY_ACTION, local_buffer): destroy_action = primitives.Enumeration( enums.DestroyAction, tag=enums.Tags.DESTROY_ACTION ) destroy_action.read(local_buffer, kmip_version=kmip_version) self._destroy_action = destroy_action if self.is_tag_next(enums.Tags.SHREDDING_ALGORITHM, local_buffer): shredding_algorithm = primitives.Enumeration( enums.ShreddingAlgorithm, tag=enums.Tags.SHREDDING_ALGORITHM ) shredding_algorithm.read(local_buffer, kmip_version=kmip_version) self._shredding_algorithm = shredding_algorithm if self.is_tag_next(enums.Tags.RNG_MODE, local_buffer): rng_mode = primitives.Enumeration( enums.RNGMode, tag=enums.Tags.RNG_MODE ) rng_mode.read(local_buffer, kmip_version=kmip_version) self._rng_mode = rng_mode self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Read the data encoding the CapabilityInformation structure 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 2.0. Raises: VersionNotSupported: Raised when a KMIP version is provided that does not support the CapabilityInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the CapabilityInformation " "object.".format( kmip_version.value ) ) super(CapabilityInformation, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.STREAMING_CAPABILITY, local_buffer): streaming_capability = primitives.Boolean( tag=enums.Tags.STREAMING_CAPABILITY ) streaming_capability.read(local_buffer, kmip_version=kmip_version) self._streaming_capability = streaming_capability if self.is_tag_next(enums.Tags.ASYNCHRONOUS_CAPABILITY, local_buffer): asynchronous_capability = primitives.Boolean( tag=enums.Tags.ASYNCHRONOUS_CAPABILITY ) asynchronous_capability.read( local_buffer, kmip_version=kmip_version ) self._asynchronous_capability = asynchronous_capability if self.is_tag_next(enums.Tags.ATTESTATION_CAPABILITY, local_buffer): attestation_capability = primitives.Boolean( tag=enums.Tags.ATTESTATION_CAPABILITY ) attestation_capability.read( local_buffer, kmip_version=kmip_version ) self._attestation_capability = attestation_capability if kmip_version >= enums.KMIPVersion.KMIP_1_4: if self.is_tag_next( enums.Tags.BATCH_UNDO_CAPABILITY, local_buffer ): batch_undo_capability = primitives.Boolean( tag=enums.Tags.BATCH_UNDO_CAPABILITY ) batch_undo_capability.read( local_buffer, kmip_version=kmip_version ) self._batch_continue_capability = batch_undo_capability if self.is_tag_next( enums.Tags.BATCH_CONTINUE_CAPABILITY, local_buffer ): batch_continue_capability = primitives.Boolean( tag=enums.Tags.BATCH_CONTINUE_CAPABILITY ) batch_continue_capability.read( local_buffer, kmip_version=kmip_version ) self._batch_continue_capability = batch_continue_capability if self.is_tag_next(enums.Tags.UNWRAP_MODE, local_buffer): unwrap_mode = primitives.Enumeration( enums.UnwrapMode, tag=enums.Tags.UNWRAP_MODE ) unwrap_mode.read(local_buffer, kmip_version=kmip_version) self._unwrap_mode = unwrap_mode if self.is_tag_next(enums.Tags.DESTROY_ACTION, local_buffer): destroy_action = primitives.Enumeration( enums.DestroyAction, tag=enums.Tags.DESTROY_ACTION ) destroy_action.read(local_buffer, kmip_version=kmip_version) self._destroy_action = destroy_action if self.is_tag_next(enums.Tags.SHREDDING_ALGORITHM, local_buffer): shredding_algorithm = primitives.Enumeration( enums.ShreddingAlgorithm, tag=enums.Tags.SHREDDING_ALGORITHM ) shredding_algorithm.read(local_buffer, kmip_version=kmip_version) self._shredding_algorithm = shredding_algorithm if self.is_tag_next(enums.Tags.RNG_MODE, local_buffer): rng_mode = primitives.Enumeration( enums.RNGMode, tag=enums.Tags.RNG_MODE ) rng_mode.read(local_buffer, kmip_version=kmip_version) self._rng_mode = rng_mode self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "CapabilityInformation", "structure", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L5773-L5890
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the CapabilityInformation \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "super", "(", "CapabilityInformation", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "STREAMING_CAPABILITY", ",", "local_buffer", ")", ":", "streaming_capability", "=", "primitives", ".", "Boolean", "(", "tag", "=", "enums", ".", "Tags", ".", "STREAMING_CAPABILITY", ")", "streaming_capability", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_streaming_capability", "=", "streaming_capability", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ASYNCHRONOUS_CAPABILITY", ",", "local_buffer", ")", ":", "asynchronous_capability", "=", "primitives", ".", "Boolean", "(", "tag", "=", "enums", ".", "Tags", ".", "ASYNCHRONOUS_CAPABILITY", ")", "asynchronous_capability", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_asynchronous_capability", "=", "asynchronous_capability", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ATTESTATION_CAPABILITY", ",", "local_buffer", ")", ":", "attestation_capability", "=", "primitives", ".", "Boolean", "(", "tag", "=", "enums", ".", "Tags", ".", "ATTESTATION_CAPABILITY", ")", "attestation_capability", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_attestation_capability", "=", "attestation_capability", "if", "kmip_version", ">=", "enums", ".", "KMIPVersion", ".", "KMIP_1_4", ":", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "BATCH_UNDO_CAPABILITY", ",", "local_buffer", ")", ":", "batch_undo_capability", "=", "primitives", ".", "Boolean", "(", "tag", "=", "enums", ".", "Tags", ".", "BATCH_UNDO_CAPABILITY", ")", "batch_undo_capability", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_batch_continue_capability", "=", "batch_undo_capability", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "BATCH_CONTINUE_CAPABILITY", ",", "local_buffer", ")", ":", "batch_continue_capability", "=", "primitives", ".", "Boolean", "(", "tag", "=", "enums", ".", "Tags", ".", "BATCH_CONTINUE_CAPABILITY", ")", "batch_continue_capability", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_batch_continue_capability", "=", "batch_continue_capability", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNWRAP_MODE", ",", "local_buffer", ")", ":", "unwrap_mode", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "UnwrapMode", ",", "tag", "=", "enums", ".", "Tags", ".", "UNWRAP_MODE", ")", "unwrap_mode", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_unwrap_mode", "=", "unwrap_mode", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "DESTROY_ACTION", ",", "local_buffer", ")", ":", "destroy_action", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "DestroyAction", ",", "tag", "=", "enums", ".", "Tags", ".", "DESTROY_ACTION", ")", "destroy_action", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_destroy_action", "=", "destroy_action", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "SHREDDING_ALGORITHM", ",", "local_buffer", ")", ":", "shredding_algorithm", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "ShreddingAlgorithm", ",", "tag", "=", "enums", ".", "Tags", ".", "SHREDDING_ALGORITHM", ")", "shredding_algorithm", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_shredding_algorithm", "=", "shredding_algorithm", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "RNG_MODE", ",", "local_buffer", ")", ":", "rng_mode", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "RNGMode", ",", "tag", "=", "enums", ".", "Tags", ".", "RNG_MODE", ")", "rng_mode", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_rng_mode", "=", "rng_mode", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CapabilityInformation.write
Write the CapabilityInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode CapabilityInformation structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: VersionNotSupported: Raised when a KMIP version is provided that does not support the CapabilityInformation structure.
kmip/core/objects.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Write the CapabilityInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode CapabilityInformation structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: VersionNotSupported: Raised when a KMIP version is provided that does not support the CapabilityInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the CapabilityInformation " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._streaming_capability: self._streaming_capability.write( local_buffer, kmip_version=kmip_version ) if self._asynchronous_capability: self._asynchronous_capability.write( local_buffer, kmip_version=kmip_version ) if self._attestation_capability: self._attestation_capability.write( local_buffer, kmip_version=kmip_version ) if kmip_version >= enums.KMIPVersion.KMIP_1_4: if self._batch_undo_capability: self._batch_undo_capability.write( local_buffer, kmip_version=kmip_version ) if self._batch_continue_capability: self._batch_continue_capability.write( local_buffer, kmip_version=kmip_version ) if self._unwrap_mode: self._unwrap_mode.write( local_buffer, kmip_version=kmip_version ) if self._destroy_action: self._destroy_action.write( local_buffer, kmip_version=kmip_version ) if self._shredding_algorithm: self._shredding_algorithm.write( local_buffer, kmip_version=kmip_version ) if self._rng_mode: self._rng_mode.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(CapabilityInformation, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3): """ Write the CapabilityInformation structure encoding to the data stream. Args: output_buffer (stream): A data stream in which to encode CapabilityInformation structure data, supporting a write method. kmip_version (enum): A KMIPVersion enumeration defining the KMIP version with which the object will be encoded. Optional, defaults to KMIP 2.0. Raises: VersionNotSupported: Raised when a KMIP version is provided that does not support the CapabilityInformation structure. """ if kmip_version < enums.KMIPVersion.KMIP_1_3: raise exceptions.VersionNotSupported( "KMIP {} does not support the CapabilityInformation " "object.".format( kmip_version.value ) ) local_buffer = BytearrayStream() if self._streaming_capability: self._streaming_capability.write( local_buffer, kmip_version=kmip_version ) if self._asynchronous_capability: self._asynchronous_capability.write( local_buffer, kmip_version=kmip_version ) if self._attestation_capability: self._attestation_capability.write( local_buffer, kmip_version=kmip_version ) if kmip_version >= enums.KMIPVersion.KMIP_1_4: if self._batch_undo_capability: self._batch_undo_capability.write( local_buffer, kmip_version=kmip_version ) if self._batch_continue_capability: self._batch_continue_capability.write( local_buffer, kmip_version=kmip_version ) if self._unwrap_mode: self._unwrap_mode.write( local_buffer, kmip_version=kmip_version ) if self._destroy_action: self._destroy_action.write( local_buffer, kmip_version=kmip_version ) if self._shredding_algorithm: self._shredding_algorithm.write( local_buffer, kmip_version=kmip_version ) if self._rng_mode: self._rng_mode.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(CapabilityInformation, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "CapabilityInformation", "structure", "encoding", "to", "the", "data", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/objects.py#L5892-L5978
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ")", ":", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", ":", "raise", "exceptions", ".", "VersionNotSupported", "(", "\"KMIP {} does not support the CapabilityInformation \"", "\"object.\"", ".", "format", "(", "kmip_version", ".", "value", ")", ")", "local_buffer", "=", "BytearrayStream", "(", ")", "if", "self", ".", "_streaming_capability", ":", "self", ".", "_streaming_capability", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_asynchronous_capability", ":", "self", ".", "_asynchronous_capability", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_attestation_capability", ":", "self", ".", "_attestation_capability", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "kmip_version", ">=", "enums", ".", "KMIPVersion", ".", "KMIP_1_4", ":", "if", "self", ".", "_batch_undo_capability", ":", "self", ".", "_batch_undo_capability", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_batch_continue_capability", ":", "self", ".", "_batch_continue_capability", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_unwrap_mode", ":", "self", ".", "_unwrap_mode", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_destroy_action", ":", "self", ".", "_destroy_action", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_shredding_algorithm", ":", "self", ".", "_shredding_algorithm", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_rng_mode", ":", "self", ".", "_rng_mode", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "CapabilityInformation", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KmipServer.start
Prepare the server to start serving connections. Configure the server socket handler and establish a TLS wrapping socket from which all client connections descend. Bind this TLS socket to the specified network address for the server. Raises: NetworkingError: Raised if the TLS socket cannot be bound to the network address.
kmip/services/server/server.py
def start(self): """ Prepare the server to start serving connections. Configure the server socket handler and establish a TLS wrapping socket from which all client connections descend. Bind this TLS socket to the specified network address for the server. Raises: NetworkingError: Raised if the TLS socket cannot be bound to the network address. """ self.manager = multiprocessing.Manager() self.policies = self.manager.dict() policies = copy.deepcopy(operation_policy.policies) for policy_name, policy_set in six.iteritems(policies): self.policies[policy_name] = policy_set self.policy_monitor = monitor.PolicyDirectoryMonitor( self.config.settings.get('policy_path'), self.policies, self.live_policies ) def interrupt_handler(trigger, frame): self.policy_monitor.stop() signal.signal(signal.SIGINT, interrupt_handler) signal.signal(signal.SIGTERM, interrupt_handler) self.policy_monitor.start() self._engine = engine.KmipEngine( policies=self.policies, database_path=self.config.settings.get('database_path') ) self._logger.info("Starting server socket handler.") # Create a TCP stream socket and configure it for immediate reuse. socket.setdefaulttimeout(10) self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._logger.debug( "Configured cipher suites: {0}".format( len(self.config.settings.get('tls_cipher_suites')) ) ) for cipher in self.config.settings.get('tls_cipher_suites'): self._logger.debug(cipher) auth_suite_ciphers = self.auth_suite.ciphers.split(':') self._logger.debug( "Authentication suite ciphers to use: {0}".format( len(auth_suite_ciphers) ) ) for cipher in auth_suite_ciphers: self._logger.debug(cipher) self._socket = ssl.wrap_socket( self._socket, keyfile=self.config.settings.get('key_path'), certfile=self.config.settings.get('certificate_path'), server_side=True, cert_reqs=ssl.CERT_REQUIRED, ssl_version=self.auth_suite.protocol, ca_certs=self.config.settings.get('ca_path'), do_handshake_on_connect=False, suppress_ragged_eofs=True, ciphers=self.auth_suite.ciphers ) try: self._socket.bind( ( self.config.settings.get('hostname'), int(self.config.settings.get('port')) ) ) except Exception as e: self._logger.exception(e) raise exceptions.NetworkingError( "Server failed to bind socket handler to {0}:{1}".format( self.config.settings.get('hostname'), self.config.settings.get('port') ) ) else: self._logger.info( "Server successfully bound socket handler to {0}:{1}".format( self.config.settings.get('hostname'), self.config.settings.get('port') ) ) self._is_serving = True
def start(self): """ Prepare the server to start serving connections. Configure the server socket handler and establish a TLS wrapping socket from which all client connections descend. Bind this TLS socket to the specified network address for the server. Raises: NetworkingError: Raised if the TLS socket cannot be bound to the network address. """ self.manager = multiprocessing.Manager() self.policies = self.manager.dict() policies = copy.deepcopy(operation_policy.policies) for policy_name, policy_set in six.iteritems(policies): self.policies[policy_name] = policy_set self.policy_monitor = monitor.PolicyDirectoryMonitor( self.config.settings.get('policy_path'), self.policies, self.live_policies ) def interrupt_handler(trigger, frame): self.policy_monitor.stop() signal.signal(signal.SIGINT, interrupt_handler) signal.signal(signal.SIGTERM, interrupt_handler) self.policy_monitor.start() self._engine = engine.KmipEngine( policies=self.policies, database_path=self.config.settings.get('database_path') ) self._logger.info("Starting server socket handler.") # Create a TCP stream socket and configure it for immediate reuse. socket.setdefaulttimeout(10) self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._logger.debug( "Configured cipher suites: {0}".format( len(self.config.settings.get('tls_cipher_suites')) ) ) for cipher in self.config.settings.get('tls_cipher_suites'): self._logger.debug(cipher) auth_suite_ciphers = self.auth_suite.ciphers.split(':') self._logger.debug( "Authentication suite ciphers to use: {0}".format( len(auth_suite_ciphers) ) ) for cipher in auth_suite_ciphers: self._logger.debug(cipher) self._socket = ssl.wrap_socket( self._socket, keyfile=self.config.settings.get('key_path'), certfile=self.config.settings.get('certificate_path'), server_side=True, cert_reqs=ssl.CERT_REQUIRED, ssl_version=self.auth_suite.protocol, ca_certs=self.config.settings.get('ca_path'), do_handshake_on_connect=False, suppress_ragged_eofs=True, ciphers=self.auth_suite.ciphers ) try: self._socket.bind( ( self.config.settings.get('hostname'), int(self.config.settings.get('port')) ) ) except Exception as e: self._logger.exception(e) raise exceptions.NetworkingError( "Server failed to bind socket handler to {0}:{1}".format( self.config.settings.get('hostname'), self.config.settings.get('port') ) ) else: self._logger.info( "Server successfully bound socket handler to {0}:{1}".format( self.config.settings.get('hostname'), self.config.settings.get('port') ) ) self._is_serving = True
[ "Prepare", "the", "server", "to", "start", "serving", "connections", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/server.py#L231-L325
[ "def", "start", "(", "self", ")", ":", "self", ".", "manager", "=", "multiprocessing", ".", "Manager", "(", ")", "self", ".", "policies", "=", "self", ".", "manager", ".", "dict", "(", ")", "policies", "=", "copy", ".", "deepcopy", "(", "operation_policy", ".", "policies", ")", "for", "policy_name", ",", "policy_set", "in", "six", ".", "iteritems", "(", "policies", ")", ":", "self", ".", "policies", "[", "policy_name", "]", "=", "policy_set", "self", ".", "policy_monitor", "=", "monitor", ".", "PolicyDirectoryMonitor", "(", "self", ".", "config", ".", "settings", ".", "get", "(", "'policy_path'", ")", ",", "self", ".", "policies", ",", "self", ".", "live_policies", ")", "def", "interrupt_handler", "(", "trigger", ",", "frame", ")", ":", "self", ".", "policy_monitor", ".", "stop", "(", ")", "signal", ".", "signal", "(", "signal", ".", "SIGINT", ",", "interrupt_handler", ")", "signal", ".", "signal", "(", "signal", ".", "SIGTERM", ",", "interrupt_handler", ")", "self", ".", "policy_monitor", ".", "start", "(", ")", "self", ".", "_engine", "=", "engine", ".", "KmipEngine", "(", "policies", "=", "self", ".", "policies", ",", "database_path", "=", "self", ".", "config", ".", "settings", ".", "get", "(", "'database_path'", ")", ")", "self", ".", "_logger", ".", "info", "(", "\"Starting server socket handler.\"", ")", "# Create a TCP stream socket and configure it for immediate reuse.", "socket", ".", "setdefaulttimeout", "(", "10", ")", "self", ".", "_socket", "=", "socket", ".", "socket", "(", "socket", ".", "AF_INET", ",", "socket", ".", "SOCK_STREAM", ")", "self", ".", "_socket", ".", "setsockopt", "(", "socket", ".", "SOL_SOCKET", ",", "socket", ".", "SO_REUSEADDR", ",", "1", ")", "self", ".", "_logger", ".", "debug", "(", "\"Configured cipher suites: {0}\"", ".", "format", "(", "len", "(", "self", ".", "config", ".", "settings", ".", "get", "(", "'tls_cipher_suites'", ")", ")", ")", ")", "for", "cipher", "in", "self", ".", "config", ".", "settings", ".", "get", "(", "'tls_cipher_suites'", ")", ":", "self", ".", "_logger", ".", "debug", "(", "cipher", ")", "auth_suite_ciphers", "=", "self", ".", "auth_suite", ".", "ciphers", ".", "split", "(", "':'", ")", "self", ".", "_logger", ".", "debug", "(", "\"Authentication suite ciphers to use: {0}\"", ".", "format", "(", "len", "(", "auth_suite_ciphers", ")", ")", ")", "for", "cipher", "in", "auth_suite_ciphers", ":", "self", ".", "_logger", ".", "debug", "(", "cipher", ")", "self", ".", "_socket", "=", "ssl", ".", "wrap_socket", "(", "self", ".", "_socket", ",", "keyfile", "=", "self", ".", "config", ".", "settings", ".", "get", "(", "'key_path'", ")", ",", "certfile", "=", "self", ".", "config", ".", "settings", ".", "get", "(", "'certificate_path'", ")", ",", "server_side", "=", "True", ",", "cert_reqs", "=", "ssl", ".", "CERT_REQUIRED", ",", "ssl_version", "=", "self", ".", "auth_suite", ".", "protocol", ",", "ca_certs", "=", "self", ".", "config", ".", "settings", ".", "get", "(", "'ca_path'", ")", ",", "do_handshake_on_connect", "=", "False", ",", "suppress_ragged_eofs", "=", "True", ",", "ciphers", "=", "self", ".", "auth_suite", ".", "ciphers", ")", "try", ":", "self", ".", "_socket", ".", "bind", "(", "(", "self", ".", "config", ".", "settings", ".", "get", "(", "'hostname'", ")", ",", "int", "(", "self", ".", "config", ".", "settings", ".", "get", "(", "'port'", ")", ")", ")", ")", "except", "Exception", "as", "e", ":", "self", ".", "_logger", ".", "exception", "(", "e", ")", "raise", "exceptions", ".", "NetworkingError", "(", "\"Server failed to bind socket handler to {0}:{1}\"", ".", "format", "(", "self", ".", "config", ".", "settings", ".", "get", "(", "'hostname'", ")", ",", "self", ".", "config", ".", "settings", ".", "get", "(", "'port'", ")", ")", ")", "else", ":", "self", ".", "_logger", ".", "info", "(", "\"Server successfully bound socket handler to {0}:{1}\"", ".", "format", "(", "self", ".", "config", ".", "settings", ".", "get", "(", "'hostname'", ")", ",", "self", ".", "config", ".", "settings", ".", "get", "(", "'port'", ")", ")", ")", "self", ".", "_is_serving", "=", "True" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KmipServer.stop
Stop the server. Halt server client connections and clean up any existing connection threads. Raises: NetworkingError: Raised if a failure occurs while sutting down or closing the TLS server socket.
kmip/services/server/server.py
def stop(self): """ Stop the server. Halt server client connections and clean up any existing connection threads. Raises: NetworkingError: Raised if a failure occurs while sutting down or closing the TLS server socket. """ self._logger.info("Cleaning up remaining connection threads.") for thread in threading.enumerate(): if thread is not threading.current_thread(): try: thread.join(10.0) except Exception as e: self._logger.info( "Error occurred while attempting to cleanup thread: " "{0}".format(thread.name) ) self._logger.exception(e) else: if thread.is_alive(): self._logger.warning( "Cleanup failed for thread: {0}. Thread is " "still alive".format(thread.name) ) else: self._logger.info( "Cleanup succeeded for thread: {0}".format( thread.name ) ) self._logger.info("Shutting down server socket handler.") try: self._socket.shutdown(socket.SHUT_RDWR) self._socket.close() except Exception as e: self._logger.exception(e) raise exceptions.NetworkingError( "Server failed to shutdown socket handler." ) if hasattr(self, "policy_monitor"): try: self.policy_monitor.stop() self.policy_monitor.join() except Exception as e: self._logger.exception(e) raise exceptions.ShutdownError( "Server failed to clean up the policy monitor." )
def stop(self): """ Stop the server. Halt server client connections and clean up any existing connection threads. Raises: NetworkingError: Raised if a failure occurs while sutting down or closing the TLS server socket. """ self._logger.info("Cleaning up remaining connection threads.") for thread in threading.enumerate(): if thread is not threading.current_thread(): try: thread.join(10.0) except Exception as e: self._logger.info( "Error occurred while attempting to cleanup thread: " "{0}".format(thread.name) ) self._logger.exception(e) else: if thread.is_alive(): self._logger.warning( "Cleanup failed for thread: {0}. Thread is " "still alive".format(thread.name) ) else: self._logger.info( "Cleanup succeeded for thread: {0}".format( thread.name ) ) self._logger.info("Shutting down server socket handler.") try: self._socket.shutdown(socket.SHUT_RDWR) self._socket.close() except Exception as e: self._logger.exception(e) raise exceptions.NetworkingError( "Server failed to shutdown socket handler." ) if hasattr(self, "policy_monitor"): try: self.policy_monitor.stop() self.policy_monitor.join() except Exception as e: self._logger.exception(e) raise exceptions.ShutdownError( "Server failed to clean up the policy monitor." )
[ "Stop", "the", "server", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/server.py#L327-L381
[ "def", "stop", "(", "self", ")", ":", "self", ".", "_logger", ".", "info", "(", "\"Cleaning up remaining connection threads.\"", ")", "for", "thread", "in", "threading", ".", "enumerate", "(", ")", ":", "if", "thread", "is", "not", "threading", ".", "current_thread", "(", ")", ":", "try", ":", "thread", ".", "join", "(", "10.0", ")", "except", "Exception", "as", "e", ":", "self", ".", "_logger", ".", "info", "(", "\"Error occurred while attempting to cleanup thread: \"", "\"{0}\"", ".", "format", "(", "thread", ".", "name", ")", ")", "self", ".", "_logger", ".", "exception", "(", "e", ")", "else", ":", "if", "thread", ".", "is_alive", "(", ")", ":", "self", ".", "_logger", ".", "warning", "(", "\"Cleanup failed for thread: {0}. Thread is \"", "\"still alive\"", ".", "format", "(", "thread", ".", "name", ")", ")", "else", ":", "self", ".", "_logger", ".", "info", "(", "\"Cleanup succeeded for thread: {0}\"", ".", "format", "(", "thread", ".", "name", ")", ")", "self", ".", "_logger", ".", "info", "(", "\"Shutting down server socket handler.\"", ")", "try", ":", "self", ".", "_socket", ".", "shutdown", "(", "socket", ".", "SHUT_RDWR", ")", "self", ".", "_socket", ".", "close", "(", ")", "except", "Exception", "as", "e", ":", "self", ".", "_logger", ".", "exception", "(", "e", ")", "raise", "exceptions", ".", "NetworkingError", "(", "\"Server failed to shutdown socket handler.\"", ")", "if", "hasattr", "(", "self", ",", "\"policy_monitor\"", ")", ":", "try", ":", "self", ".", "policy_monitor", ".", "stop", "(", ")", "self", ".", "policy_monitor", ".", "join", "(", ")", "except", "Exception", "as", "e", ":", "self", ".", "_logger", ".", "exception", "(", "e", ")", "raise", "exceptions", ".", "ShutdownError", "(", "\"Server failed to clean up the policy monitor.\"", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KmipServer.serve
Serve client connections. Begin listening for client connections, spinning off new KmipSessions as connections are handled. Set up signal handling to shutdown connection service as needed.
kmip/services/server/server.py
def serve(self): """ Serve client connections. Begin listening for client connections, spinning off new KmipSessions as connections are handled. Set up signal handling to shutdown connection service as needed. """ self._socket.listen(5) def _signal_handler(signal_number, stack_frame): self._is_serving = False # Python3.5+ silently ignores SIGINT and retries system calls if # the signal handler does not raise an exception. Explicitly # detect SIGINT and raise a KeyboardInterrupt exception to regain # old functionality. if signal_number == signal.SIGINT: raise KeyboardInterrupt("SIGINT received") signal.signal(signal.SIGINT, _signal_handler) signal.signal(signal.SIGTERM, _signal_handler) self._logger.info("Starting connection service...") while self._is_serving: try: connection, address = self._socket.accept() except socket.timeout: # Setting the default socket timeout to break hung connections # will cause accept to periodically raise socket.timeout. This # is expected behavior, so ignore it and retry accept. pass except socket.error as e: self._logger.warning( "Error detected while establishing new connection." ) self._logger.exception(e) except KeyboardInterrupt: self._logger.warning("Interrupting connection service.") self._is_serving = False break except Exception as e: self._logger.warning( "Error detected while establishing new connection." ) self._logger.exception(e) else: self._setup_connection_handler(connection, address) self._logger.info("Stopping connection service.")
def serve(self): """ Serve client connections. Begin listening for client connections, spinning off new KmipSessions as connections are handled. Set up signal handling to shutdown connection service as needed. """ self._socket.listen(5) def _signal_handler(signal_number, stack_frame): self._is_serving = False # Python3.5+ silently ignores SIGINT and retries system calls if # the signal handler does not raise an exception. Explicitly # detect SIGINT and raise a KeyboardInterrupt exception to regain # old functionality. if signal_number == signal.SIGINT: raise KeyboardInterrupt("SIGINT received") signal.signal(signal.SIGINT, _signal_handler) signal.signal(signal.SIGTERM, _signal_handler) self._logger.info("Starting connection service...") while self._is_serving: try: connection, address = self._socket.accept() except socket.timeout: # Setting the default socket timeout to break hung connections # will cause accept to periodically raise socket.timeout. This # is expected behavior, so ignore it and retry accept. pass except socket.error as e: self._logger.warning( "Error detected while establishing new connection." ) self._logger.exception(e) except KeyboardInterrupt: self._logger.warning("Interrupting connection service.") self._is_serving = False break except Exception as e: self._logger.warning( "Error detected while establishing new connection." ) self._logger.exception(e) else: self._setup_connection_handler(connection, address) self._logger.info("Stopping connection service.")
[ "Serve", "client", "connections", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/server.py#L383-L433
[ "def", "serve", "(", "self", ")", ":", "self", ".", "_socket", ".", "listen", "(", "5", ")", "def", "_signal_handler", "(", "signal_number", ",", "stack_frame", ")", ":", "self", ".", "_is_serving", "=", "False", "# Python3.5+ silently ignores SIGINT and retries system calls if", "# the signal handler does not raise an exception. Explicitly", "# detect SIGINT and raise a KeyboardInterrupt exception to regain", "# old functionality.", "if", "signal_number", "==", "signal", ".", "SIGINT", ":", "raise", "KeyboardInterrupt", "(", "\"SIGINT received\"", ")", "signal", ".", "signal", "(", "signal", ".", "SIGINT", ",", "_signal_handler", ")", "signal", ".", "signal", "(", "signal", ".", "SIGTERM", ",", "_signal_handler", ")", "self", ".", "_logger", ".", "info", "(", "\"Starting connection service...\"", ")", "while", "self", ".", "_is_serving", ":", "try", ":", "connection", ",", "address", "=", "self", ".", "_socket", ".", "accept", "(", ")", "except", "socket", ".", "timeout", ":", "# Setting the default socket timeout to break hung connections", "# will cause accept to periodically raise socket.timeout. This", "# is expected behavior, so ignore it and retry accept.", "pass", "except", "socket", ".", "error", "as", "e", ":", "self", ".", "_logger", ".", "warning", "(", "\"Error detected while establishing new connection.\"", ")", "self", ".", "_logger", ".", "exception", "(", "e", ")", "except", "KeyboardInterrupt", ":", "self", ".", "_logger", ".", "warning", "(", "\"Interrupting connection service.\"", ")", "self", ".", "_is_serving", "=", "False", "break", "except", "Exception", "as", "e", ":", "self", ".", "_logger", ".", "warning", "(", "\"Error detected while establishing new connection.\"", ")", "self", ".", "_logger", ".", "exception", "(", "e", ")", "else", ":", "self", ".", "_setup_connection_handler", "(", "connection", ",", "address", ")", "self", ".", "_logger", ".", "info", "(", "\"Stopping connection service.\"", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
LocateRequestPayload.read
Read the data encoding the Locate 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 attributes structure is missing from the encoded payload for KMIP 2.0+ encodings.
kmip/core/messages/payloads/locate.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Locate 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 attributes structure is missing from the encoded payload for KMIP 2.0+ encodings. """ super(LocateRequestPayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.MAXIMUM_ITEMS, local_buffer): self._maximum_items = primitives.Integer( tag=enums.Tags.MAXIMUM_ITEMS ) self._maximum_items.read( local_buffer, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.OFFSET_ITEMS, local_buffer): self._offset_items = primitives.Integer( tag=enums.Tags.OFFSET_ITEMS ) self._offset_items.read( local_buffer, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.STORAGE_STATUS_MASK, local_buffer): self._storage_status_mask = primitives.Integer( tag=enums.Tags.STORAGE_STATUS_MASK ) self._storage_status_mask.read( local_buffer, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.OBJECT_GROUP_MEMBER, local_buffer): self._object_group_member = primitives.Enumeration( enums.ObjectGroupMember, tag=enums.Tags.OBJECT_GROUP_MEMBER ) self._object_group_member.read( local_buffer, kmip_version=kmip_version ) if kmip_version < enums.KMIPVersion.KMIP_2_0: while self.is_tag_next(enums.Tags.ATTRIBUTE, local_buffer): attribute = objects.Attribute() attribute.read(local_buffer, kmip_version=kmip_version) self._attributes.append(attribute) else: if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer): attributes = objects.Attributes() attributes.read(local_buffer, kmip_version=kmip_version) # TODO (ph) Add a new utility to avoid using TemplateAttributes temp_attr = objects.convert_attributes_to_template_attribute( attributes ) self._attributes = temp_attr.attributes else: raise exceptions.InvalidKmipEncoding( "The Locate request payload encoding is missing the " "attributes structure." )
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Locate 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 attributes structure is missing from the encoded payload for KMIP 2.0+ encodings. """ super(LocateRequestPayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.MAXIMUM_ITEMS, local_buffer): self._maximum_items = primitives.Integer( tag=enums.Tags.MAXIMUM_ITEMS ) self._maximum_items.read( local_buffer, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.OFFSET_ITEMS, local_buffer): self._offset_items = primitives.Integer( tag=enums.Tags.OFFSET_ITEMS ) self._offset_items.read( local_buffer, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.STORAGE_STATUS_MASK, local_buffer): self._storage_status_mask = primitives.Integer( tag=enums.Tags.STORAGE_STATUS_MASK ) self._storage_status_mask.read( local_buffer, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.OBJECT_GROUP_MEMBER, local_buffer): self._object_group_member = primitives.Enumeration( enums.ObjectGroupMember, tag=enums.Tags.OBJECT_GROUP_MEMBER ) self._object_group_member.read( local_buffer, kmip_version=kmip_version ) if kmip_version < enums.KMIPVersion.KMIP_2_0: while self.is_tag_next(enums.Tags.ATTRIBUTE, local_buffer): attribute = objects.Attribute() attribute.read(local_buffer, kmip_version=kmip_version) self._attributes.append(attribute) else: if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer): attributes = objects.Attributes() attributes.read(local_buffer, kmip_version=kmip_version) # TODO (ph) Add a new utility to avoid using TemplateAttributes temp_attr = objects.convert_attributes_to_template_attribute( attributes ) self._attributes = temp_attr.attributes else: raise exceptions.InvalidKmipEncoding( "The Locate request payload encoding is missing the " "attributes structure." )
[ "Read", "the", "data", "encoding", "the", "Locate", "request", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/locate.py#L192-L269
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "LocateRequestPayload", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "MAXIMUM_ITEMS", ",", "local_buffer", ")", ":", "self", ".", "_maximum_items", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "MAXIMUM_ITEMS", ")", "self", ".", "_maximum_items", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "OFFSET_ITEMS", ",", "local_buffer", ")", ":", "self", ".", "_offset_items", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "OFFSET_ITEMS", ")", "self", ".", "_offset_items", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "STORAGE_STATUS_MASK", ",", "local_buffer", ")", ":", "self", ".", "_storage_status_mask", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "STORAGE_STATUS_MASK", ")", "self", ".", "_storage_status_mask", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "OBJECT_GROUP_MEMBER", ",", "local_buffer", ")", ":", "self", ".", "_object_group_member", "=", "primitives", ".", "Enumeration", "(", "enums", ".", "ObjectGroupMember", ",", "tag", "=", "enums", ".", "Tags", ".", "OBJECT_GROUP_MEMBER", ")", "self", ".", "_object_group_member", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "while", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ATTRIBUTE", ",", "local_buffer", ")", ":", "attribute", "=", "objects", ".", "Attribute", "(", ")", "attribute", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_attributes", ".", "append", "(", "attribute", ")", "else", ":", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ATTRIBUTES", ",", "local_buffer", ")", ":", "attributes", "=", "objects", ".", "Attributes", "(", ")", "attributes", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "# TODO (ph) Add a new utility to avoid using TemplateAttributes", "temp_attr", "=", "objects", ".", "convert_attributes_to_template_attribute", "(", "attributes", ")", "self", ".", "_attributes", "=", "temp_attr", ".", "attributes", "else", ":", "raise", "exceptions", ".", "InvalidKmipEncoding", "(", "\"The Locate request payload encoding is missing the \"", "\"attributes structure.\"", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
LocateRequestPayload.write
Write the data encoding the Locate 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.
kmip/core/messages/payloads/locate.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Locate 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. """ local_buffer = utils.BytearrayStream() if self._maximum_items: self._maximum_items.write(local_buffer, kmip_version=kmip_version) if self._offset_items: self._offset_items.write(local_buffer, kmip_version=kmip_version) if self._storage_status_mask: self._storage_status_mask.write( local_buffer, kmip_version=kmip_version ) if self._object_group_member: self._object_group_member.write( local_buffer, kmip_version=kmip_version ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._attributes: for attribute in self.attributes: attribute.write( local_buffer, kmip_version=kmip_version ) else: if self._attributes: # TODO (ph) Add a new utility to avoid using TemplateAttributes template_attribute = objects.TemplateAttribute( attributes=self.attributes ) attributes = objects.convert_template_attribute_to_attributes( template_attribute ) attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Locate request payload is missing the attributes " "list." ) self.length = local_buffer.length() super(LocateRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Locate 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. """ local_buffer = utils.BytearrayStream() if self._maximum_items: self._maximum_items.write(local_buffer, kmip_version=kmip_version) if self._offset_items: self._offset_items.write(local_buffer, kmip_version=kmip_version) if self._storage_status_mask: self._storage_status_mask.write( local_buffer, kmip_version=kmip_version ) if self._object_group_member: self._object_group_member.write( local_buffer, kmip_version=kmip_version ) if kmip_version < enums.KMIPVersion.KMIP_2_0: if self._attributes: for attribute in self.attributes: attribute.write( local_buffer, kmip_version=kmip_version ) else: if self._attributes: # TODO (ph) Add a new utility to avoid using TemplateAttributes template_attribute = objects.TemplateAttribute( attributes=self.attributes ) attributes = objects.convert_template_attribute_to_attributes( template_attribute ) attributes.write(local_buffer, kmip_version=kmip_version) else: raise exceptions.InvalidField( "The Locate request payload is missing the attributes " "list." ) self.length = local_buffer.length() super(LocateRequestPayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "data", "encoding", "the", "Locate", "request", "payload", "to", "a", "buffer", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/locate.py#L271-L330
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_maximum_items", ":", "self", ".", "_maximum_items", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_offset_items", ":", "self", ".", "_offset_items", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_storage_status_mask", ":", "self", ".", "_storage_status_mask", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_object_group_member", ":", "self", ".", "_object_group_member", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "kmip_version", "<", "enums", ".", "KMIPVersion", ".", "KMIP_2_0", ":", "if", "self", ".", "_attributes", ":", "for", "attribute", "in", "self", ".", "attributes", ":", "attribute", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "if", "self", ".", "_attributes", ":", "# TODO (ph) Add a new utility to avoid using TemplateAttributes", "template_attribute", "=", "objects", ".", "TemplateAttribute", "(", "attributes", "=", "self", ".", "attributes", ")", "attributes", "=", "objects", ".", "convert_template_attribute_to_attributes", "(", "template_attribute", ")", "attributes", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The Locate request payload is missing the attributes \"", "\"list.\"", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "LocateRequestPayload", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
LocateResponsePayload.read
Read the data encoding the Locate 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.
kmip/core/messages/payloads/locate.py
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Locate 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. """ super(LocateResponsePayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.LOCATED_ITEMS, local_buffer): self._located_items = primitives.Integer( tag=enums.Tags.LOCATED_ITEMS ) self._located_items.read( local_buffer, kmip_version=kmip_version ) self._unique_identifiers = [] while self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer): unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) unique_identifier.read(local_buffer, kmip_version=kmip_version) self._unique_identifiers.append(unique_identifier) self.is_oversized(local_buffer)
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Locate 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. """ super(LocateResponsePayload, self).read( input_buffer, kmip_version=kmip_version ) local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) if self.is_tag_next(enums.Tags.LOCATED_ITEMS, local_buffer): self._located_items = primitives.Integer( tag=enums.Tags.LOCATED_ITEMS ) self._located_items.read( local_buffer, kmip_version=kmip_version ) self._unique_identifiers = [] while self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer): unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) unique_identifier.read(local_buffer, kmip_version=kmip_version) self._unique_identifiers.append(unique_identifier) self.is_oversized(local_buffer)
[ "Read", "the", "data", "encoding", "the", "Locate", "response", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/locate.py#L459-L494
[ "def", "read", "(", "self", ",", "input_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "LocateResponsePayload", ",", "self", ")", ".", "read", "(", "input_buffer", ",", "kmip_version", "=", "kmip_version", ")", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", "input_buffer", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "LOCATED_ITEMS", ",", "local_buffer", ")", ":", "self", ".", "_located_items", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "LOCATED_ITEMS", ")", "self", ".", "_located_items", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_unique_identifiers", "=", "[", "]", "while", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_buffer", ")", ":", "unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "unique_identifier", ".", "read", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "_unique_identifiers", ".", "append", "(", "unique_identifier", ")", "self", ".", "is_oversized", "(", "local_buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
LocateResponsePayload.write
Write the data encoding the Locate 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.
kmip/core/messages/payloads/locate.py
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Locate 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. """ local_buffer = utils.BytearrayStream() if self._located_items: self._located_items.write(local_buffer, kmip_version=kmip_version) if self._unique_identifiers: for unique_identifier in self._unique_identifiers: unique_identifier.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(LocateResponsePayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Locate 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. """ local_buffer = utils.BytearrayStream() if self._located_items: self._located_items.write(local_buffer, kmip_version=kmip_version) if self._unique_identifiers: for unique_identifier in self._unique_identifiers: unique_identifier.write( local_buffer, kmip_version=kmip_version ) self.length = local_buffer.length() super(LocateResponsePayload, self).write( output_buffer, kmip_version=kmip_version ) output_buffer.write(local_buffer.buffer)
[ "Write", "the", "data", "encoding", "the", "Locate", "response", "payload", "to", "a", "buffer", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/locate.py#L496-L524
[ "def", "write", "(", "self", ",", "output_buffer", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_buffer", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_located_items", ":", "self", ".", "_located_items", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_unique_identifiers", ":", "for", "unique_identifier", "in", "self", ".", "_unique_identifiers", ":", "unique_identifier", ".", "write", "(", "local_buffer", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_buffer", ".", "length", "(", ")", "super", "(", "LocateResponsePayload", ",", "self", ")", ".", "write", "(", "output_buffer", ",", "kmip_version", "=", "kmip_version", ")", "output_buffer", ".", "write", "(", "local_buffer", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine.create_symmetric_key
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)
kmip/services/server/crypto/engine.py
def create_symmetric_key(self, algorithm, length): """ 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) """ if algorithm not in self._symmetric_key_algorithms.keys(): raise exceptions.InvalidField( "The cryptographic algorithm {0} is not a supported symmetric " "key algorithm.".format(algorithm) ) cryptography_algorithm = self._symmetric_key_algorithms.get(algorithm) if length not in cryptography_algorithm.key_sizes: raise exceptions.InvalidField( "The cryptographic length ({0}) is not valid for " "the cryptographic algorithm ({1}).".format( length, algorithm.name ) ) self.logger.info( "Generating a {0} symmetric key with length: {1}".format( algorithm.name, length ) ) key_bytes = os.urandom(length // 8) try: cryptography_algorithm(key_bytes) except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "Invalid bytes for the provided cryptographic algorithm.") return {'value': key_bytes, 'format': enums.KeyFormatType.RAW}
def create_symmetric_key(self, algorithm, length): """ 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) """ if algorithm not in self._symmetric_key_algorithms.keys(): raise exceptions.InvalidField( "The cryptographic algorithm {0} is not a supported symmetric " "key algorithm.".format(algorithm) ) cryptography_algorithm = self._symmetric_key_algorithms.get(algorithm) if length not in cryptography_algorithm.key_sizes: raise exceptions.InvalidField( "The cryptographic length ({0}) is not valid for " "the cryptographic algorithm ({1}).".format( length, algorithm.name ) ) self.logger.info( "Generating a {0} symmetric key with length: {1}".format( algorithm.name, length ) ) key_bytes = os.urandom(length // 8) try: cryptography_algorithm(key_bytes) except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "Invalid bytes for the provided cryptographic algorithm.") return {'value': key_bytes, 'format': enums.KeyFormatType.RAW}
[ "Create", "a", "symmetric", "key", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L125-L182
[ "def", "create_symmetric_key", "(", "self", ",", "algorithm", ",", "length", ")", ":", "if", "algorithm", "not", "in", "self", ".", "_symmetric_key_algorithms", ".", "keys", "(", ")", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The cryptographic algorithm {0} is not a supported symmetric \"", "\"key algorithm.\"", ".", "format", "(", "algorithm", ")", ")", "cryptography_algorithm", "=", "self", ".", "_symmetric_key_algorithms", ".", "get", "(", "algorithm", ")", "if", "length", "not", "in", "cryptography_algorithm", ".", "key_sizes", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The cryptographic length ({0}) is not valid for \"", "\"the cryptographic algorithm ({1}).\"", ".", "format", "(", "length", ",", "algorithm", ".", "name", ")", ")", "self", ".", "logger", ".", "info", "(", "\"Generating a {0} symmetric key with length: {1}\"", ".", "format", "(", "algorithm", ".", "name", ",", "length", ")", ")", "key_bytes", "=", "os", ".", "urandom", "(", "length", "//", "8", ")", "try", ":", "cryptography_algorithm", "(", "key_bytes", ")", "except", "Exception", "as", "e", ":", "self", ".", "logger", ".", "exception", "(", "e", ")", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"Invalid bytes for the provided cryptographic algorithm.\"", ")", "return", "{", "'value'", ":", "key_bytes", ",", "'format'", ":", "enums", ".", "KeyFormatType", ".", "RAW", "}" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine.create_asymmetric_key_pair
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)
kmip/services/server/crypto/engine.py
def create_asymmetric_key_pair(self, algorithm, length): """ 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) """ if algorithm not in self._asymmetric_key_algorithms.keys(): raise exceptions.InvalidField( "The cryptographic algorithm ({0}) is not a supported " "asymmetric key algorithm.".format(algorithm) ) engine_method = self._asymmetric_key_algorithms.get(algorithm) return engine_method(length)
def create_asymmetric_key_pair(self, algorithm, length): """ 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) """ if algorithm not in self._asymmetric_key_algorithms.keys(): raise exceptions.InvalidField( "The cryptographic algorithm ({0}) is not a supported " "asymmetric key algorithm.".format(algorithm) ) engine_method = self._asymmetric_key_algorithms.get(algorithm) return engine_method(length)
[ "Create", "an", "asymmetric", "key", "pair", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L184-L220
[ "def", "create_asymmetric_key_pair", "(", "self", ",", "algorithm", ",", "length", ")", ":", "if", "algorithm", "not", "in", "self", ".", "_asymmetric_key_algorithms", ".", "keys", "(", ")", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The cryptographic algorithm ({0}) is not a supported \"", "\"asymmetric key algorithm.\"", ".", "format", "(", "algorithm", ")", ")", "engine_method", "=", "self", ".", "_asymmetric_key_algorithms", ".", "get", "(", "algorithm", ")", "return", "engine_method", "(", "length", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine.mac
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')
kmip/services/server/crypto/engine.py
def mac(self, algorithm, key, data): """ 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') """ mac_data = None if algorithm in self._hash_algorithms.keys(): self.logger.info( "Generating a hash-based message authentication code using " "{0}".format(algorithm.name) ) hash_algorithm = self._hash_algorithms.get(algorithm) try: h = hmac.HMAC(key, hash_algorithm(), backend=default_backend()) h.update(data) mac_data = h.finalize() except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "An error occurred while computing an HMAC. " "See the server log for more information." ) elif algorithm in self._symmetric_key_algorithms.keys(): self.logger.info( "Generating a cipher-based message authentication code using " "{0}".format(algorithm.name) ) cipher_algorithm = self._symmetric_key_algorithms.get(algorithm) try: # ARC4 and IDEA algorithms will raise exception as CMAC # requires block ciphers c = cmac.CMAC(cipher_algorithm(key), backend=default_backend()) c.update(data) mac_data = c.finalize() except Exception as e: raise exceptions.CryptographicFailure( "An error occurred while computing a CMAC. " "See the server log for more information." ) else: raise exceptions.InvalidField( "The cryptographic algorithm ({0}) is not a supported " "for a MAC operation.".format(algorithm) ) return mac_data
def mac(self, algorithm, key, data): """ 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') """ mac_data = None if algorithm in self._hash_algorithms.keys(): self.logger.info( "Generating a hash-based message authentication code using " "{0}".format(algorithm.name) ) hash_algorithm = self._hash_algorithms.get(algorithm) try: h = hmac.HMAC(key, hash_algorithm(), backend=default_backend()) h.update(data) mac_data = h.finalize() except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "An error occurred while computing an HMAC. " "See the server log for more information." ) elif algorithm in self._symmetric_key_algorithms.keys(): self.logger.info( "Generating a cipher-based message authentication code using " "{0}".format(algorithm.name) ) cipher_algorithm = self._symmetric_key_algorithms.get(algorithm) try: # ARC4 and IDEA algorithms will raise exception as CMAC # requires block ciphers c = cmac.CMAC(cipher_algorithm(key), backend=default_backend()) c.update(data) mac_data = c.finalize() except Exception as e: raise exceptions.CryptographicFailure( "An error occurred while computing a CMAC. " "See the server log for more information." ) else: raise exceptions.InvalidField( "The cryptographic algorithm ({0}) is not a supported " "for a MAC operation.".format(algorithm) ) return mac_data
[ "Generate", "message", "authentication", "code", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L222-L288
[ "def", "mac", "(", "self", ",", "algorithm", ",", "key", ",", "data", ")", ":", "mac_data", "=", "None", "if", "algorithm", "in", "self", ".", "_hash_algorithms", ".", "keys", "(", ")", ":", "self", ".", "logger", ".", "info", "(", "\"Generating a hash-based message authentication code using \"", "\"{0}\"", ".", "format", "(", "algorithm", ".", "name", ")", ")", "hash_algorithm", "=", "self", ".", "_hash_algorithms", ".", "get", "(", "algorithm", ")", "try", ":", "h", "=", "hmac", ".", "HMAC", "(", "key", ",", "hash_algorithm", "(", ")", ",", "backend", "=", "default_backend", "(", ")", ")", "h", ".", "update", "(", "data", ")", "mac_data", "=", "h", ".", "finalize", "(", ")", "except", "Exception", "as", "e", ":", "self", ".", "logger", ".", "exception", "(", "e", ")", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"An error occurred while computing an HMAC. \"", "\"See the server log for more information.\"", ")", "elif", "algorithm", "in", "self", ".", "_symmetric_key_algorithms", ".", "keys", "(", ")", ":", "self", ".", "logger", ".", "info", "(", "\"Generating a cipher-based message authentication code using \"", "\"{0}\"", ".", "format", "(", "algorithm", ".", "name", ")", ")", "cipher_algorithm", "=", "self", ".", "_symmetric_key_algorithms", ".", "get", "(", "algorithm", ")", "try", ":", "# ARC4 and IDEA algorithms will raise exception as CMAC", "# requires block ciphers", "c", "=", "cmac", ".", "CMAC", "(", "cipher_algorithm", "(", "key", ")", ",", "backend", "=", "default_backend", "(", ")", ")", "c", ".", "update", "(", "data", ")", "mac_data", "=", "c", ".", "finalize", "(", ")", "except", "Exception", "as", "e", ":", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"An error occurred while computing a CMAC. \"", "\"See the server log for more information.\"", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The cryptographic algorithm ({0}) is not a supported \"", "\"for a MAC operation.\"", ".", "format", "(", "algorithm", ")", ")", "return", "mac_data" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine.encrypt
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'
kmip/services/server/crypto/engine.py
def encrypt(self, encryption_algorithm, encryption_key, plain_text, cipher_mode=None, padding_method=None, iv_nonce=None, hashing_algorithm=None): """ 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' """ if encryption_algorithm is None: raise exceptions.InvalidField("Encryption algorithm is required.") if encryption_algorithm == enums.CryptographicAlgorithm.RSA: return self._encrypt_asymmetric( encryption_algorithm, encryption_key, plain_text, padding_method, hashing_algorithm=hashing_algorithm ) else: return self._encrypt_symmetric( encryption_algorithm, encryption_key, plain_text, cipher_mode=cipher_mode, padding_method=padding_method, iv_nonce=iv_nonce )
def encrypt(self, encryption_algorithm, encryption_key, plain_text, cipher_mode=None, padding_method=None, iv_nonce=None, hashing_algorithm=None): """ 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' """ if encryption_algorithm is None: raise exceptions.InvalidField("Encryption algorithm is required.") if encryption_algorithm == enums.CryptographicAlgorithm.RSA: return self._encrypt_asymmetric( encryption_algorithm, encryption_key, plain_text, padding_method, hashing_algorithm=hashing_algorithm ) else: return self._encrypt_symmetric( encryption_algorithm, encryption_key, plain_text, cipher_mode=cipher_mode, padding_method=padding_method, iv_nonce=iv_nonce )
[ "Encrypt", "data", "using", "symmetric", "or", "asymmetric", "encryption", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L290-L377
[ "def", "encrypt", "(", "self", ",", "encryption_algorithm", ",", "encryption_key", ",", "plain_text", ",", "cipher_mode", "=", "None", ",", "padding_method", "=", "None", ",", "iv_nonce", "=", "None", ",", "hashing_algorithm", "=", "None", ")", ":", "if", "encryption_algorithm", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Encryption algorithm is required.\"", ")", "if", "encryption_algorithm", "==", "enums", ".", "CryptographicAlgorithm", ".", "RSA", ":", "return", "self", ".", "_encrypt_asymmetric", "(", "encryption_algorithm", ",", "encryption_key", ",", "plain_text", ",", "padding_method", ",", "hashing_algorithm", "=", "hashing_algorithm", ")", "else", ":", "return", "self", ".", "_encrypt_symmetric", "(", "encryption_algorithm", ",", "encryption_key", ",", "plain_text", ",", "cipher_mode", "=", "cipher_mode", ",", "padding_method", "=", "padding_method", ",", "iv_nonce", "=", "iv_nonce", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine._encrypt_symmetric
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.
kmip/services/server/crypto/engine.py
def _encrypt_symmetric( self, encryption_algorithm, encryption_key, plain_text, cipher_mode=None, padding_method=None, iv_nonce=None): """ 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. """ # Set up the algorithm algorithm = self._symmetric_key_algorithms.get( encryption_algorithm, None ) if algorithm is None: raise exceptions.InvalidField( "Encryption algorithm '{0}' is not a supported symmetric " "encryption algorithm.".format(encryption_algorithm) ) try: algorithm = algorithm(encryption_key) except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "Invalid key bytes for the specified encryption algorithm." ) # Set up the cipher mode if needed return_iv_nonce = False if encryption_algorithm == enums.CryptographicAlgorithm.RC4: mode = None else: if cipher_mode is None: raise exceptions.InvalidField("Cipher mode is required.") mode = self._modes.get(cipher_mode, None) if mode is None: raise exceptions.InvalidField( "Cipher mode '{0}' is not a supported mode.".format( cipher_mode ) ) if hasattr(mode, 'initialization_vector') or \ hasattr(mode, 'nonce'): if iv_nonce is None: iv_nonce = os.urandom(algorithm.block_size // 8) return_iv_nonce = True mode = mode(iv_nonce) else: mode = mode() # Pad the plain text if needed (separate methods for testing purposes) if cipher_mode in [ enums.BlockCipherMode.CBC, enums.BlockCipherMode.ECB ]: plain_text = self._handle_symmetric_padding( self._symmetric_key_algorithms.get(encryption_algorithm), plain_text, padding_method ) # Encrypt the plain text cipher = ciphers.Cipher(algorithm, mode, backend=default_backend()) encryptor = cipher.encryptor() cipher_text = encryptor.update(plain_text) + encryptor.finalize() if return_iv_nonce: return { 'cipher_text': cipher_text, 'iv_nonce': iv_nonce } else: return {'cipher_text': cipher_text}
def _encrypt_symmetric( self, encryption_algorithm, encryption_key, plain_text, cipher_mode=None, padding_method=None, iv_nonce=None): """ 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. """ # Set up the algorithm algorithm = self._symmetric_key_algorithms.get( encryption_algorithm, None ) if algorithm is None: raise exceptions.InvalidField( "Encryption algorithm '{0}' is not a supported symmetric " "encryption algorithm.".format(encryption_algorithm) ) try: algorithm = algorithm(encryption_key) except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "Invalid key bytes for the specified encryption algorithm." ) # Set up the cipher mode if needed return_iv_nonce = False if encryption_algorithm == enums.CryptographicAlgorithm.RC4: mode = None else: if cipher_mode is None: raise exceptions.InvalidField("Cipher mode is required.") mode = self._modes.get(cipher_mode, None) if mode is None: raise exceptions.InvalidField( "Cipher mode '{0}' is not a supported mode.".format( cipher_mode ) ) if hasattr(mode, 'initialization_vector') or \ hasattr(mode, 'nonce'): if iv_nonce is None: iv_nonce = os.urandom(algorithm.block_size // 8) return_iv_nonce = True mode = mode(iv_nonce) else: mode = mode() # Pad the plain text if needed (separate methods for testing purposes) if cipher_mode in [ enums.BlockCipherMode.CBC, enums.BlockCipherMode.ECB ]: plain_text = self._handle_symmetric_padding( self._symmetric_key_algorithms.get(encryption_algorithm), plain_text, padding_method ) # Encrypt the plain text cipher = ciphers.Cipher(algorithm, mode, backend=default_backend()) encryptor = cipher.encryptor() cipher_text = encryptor.update(plain_text) + encryptor.finalize() if return_iv_nonce: return { 'cipher_text': cipher_text, 'iv_nonce': iv_nonce } else: return {'cipher_text': cipher_text}
[ "Encrypt", "data", "using", "symmetric", "encryption", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L379-L488
[ "def", "_encrypt_symmetric", "(", "self", ",", "encryption_algorithm", ",", "encryption_key", ",", "plain_text", ",", "cipher_mode", "=", "None", ",", "padding_method", "=", "None", ",", "iv_nonce", "=", "None", ")", ":", "# Set up the algorithm", "algorithm", "=", "self", ".", "_symmetric_key_algorithms", ".", "get", "(", "encryption_algorithm", ",", "None", ")", "if", "algorithm", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Encryption algorithm '{0}' is not a supported symmetric \"", "\"encryption algorithm.\"", ".", "format", "(", "encryption_algorithm", ")", ")", "try", ":", "algorithm", "=", "algorithm", "(", "encryption_key", ")", "except", "Exception", "as", "e", ":", "self", ".", "logger", ".", "exception", "(", "e", ")", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"Invalid key bytes for the specified encryption algorithm.\"", ")", "# Set up the cipher mode if needed", "return_iv_nonce", "=", "False", "if", "encryption_algorithm", "==", "enums", ".", "CryptographicAlgorithm", ".", "RC4", ":", "mode", "=", "None", "else", ":", "if", "cipher_mode", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Cipher mode is required.\"", ")", "mode", "=", "self", ".", "_modes", ".", "get", "(", "cipher_mode", ",", "None", ")", "if", "mode", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Cipher mode '{0}' is not a supported mode.\"", ".", "format", "(", "cipher_mode", ")", ")", "if", "hasattr", "(", "mode", ",", "'initialization_vector'", ")", "or", "hasattr", "(", "mode", ",", "'nonce'", ")", ":", "if", "iv_nonce", "is", "None", ":", "iv_nonce", "=", "os", ".", "urandom", "(", "algorithm", ".", "block_size", "//", "8", ")", "return_iv_nonce", "=", "True", "mode", "=", "mode", "(", "iv_nonce", ")", "else", ":", "mode", "=", "mode", "(", ")", "# Pad the plain text if needed (separate methods for testing purposes)", "if", "cipher_mode", "in", "[", "enums", ".", "BlockCipherMode", ".", "CBC", ",", "enums", ".", "BlockCipherMode", ".", "ECB", "]", ":", "plain_text", "=", "self", ".", "_handle_symmetric_padding", "(", "self", ".", "_symmetric_key_algorithms", ".", "get", "(", "encryption_algorithm", ")", ",", "plain_text", ",", "padding_method", ")", "# Encrypt the plain text", "cipher", "=", "ciphers", ".", "Cipher", "(", "algorithm", ",", "mode", ",", "backend", "=", "default_backend", "(", ")", ")", "encryptor", "=", "cipher", ".", "encryptor", "(", ")", "cipher_text", "=", "encryptor", ".", "update", "(", "plain_text", ")", "+", "encryptor", ".", "finalize", "(", ")", "if", "return_iv_nonce", ":", "return", "{", "'cipher_text'", ":", "cipher_text", ",", "'iv_nonce'", ":", "iv_nonce", "}", "else", ":", "return", "{", "'cipher_text'", ":", "cipher_text", "}" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine._encrypt_asymmetric
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.
kmip/services/server/crypto/engine.py
def _encrypt_asymmetric(self, encryption_algorithm, encryption_key, plain_text, padding_method, hashing_algorithm=None): """ 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. """ if encryption_algorithm == enums.CryptographicAlgorithm.RSA: if padding_method == enums.PaddingMethod.OAEP: hash_algorithm = self._encryption_hash_algorithms.get( hashing_algorithm ) if hash_algorithm is None: raise exceptions.InvalidField( "The hashing algorithm '{0}' is not supported for " "asymmetric encryption.".format(hashing_algorithm) ) padding_method = asymmetric_padding.OAEP( mgf=asymmetric_padding.MGF1( algorithm=hash_algorithm() ), algorithm=hash_algorithm(), label=None ) elif padding_method == enums.PaddingMethod.PKCS1v15: padding_method = asymmetric_padding.PKCS1v15() else: raise exceptions.InvalidField( "The padding method '{0}' is not supported for asymmetric " "encryption.".format(padding_method) ) backend = default_backend() try: public_key = backend.load_der_public_key(encryption_key) except Exception: try: public_key = backend.load_pem_public_key(encryption_key) except Exception: raise exceptions.CryptographicFailure( "The public key bytes could not be loaded." ) cipher_text = public_key.encrypt( plain_text, padding_method ) return {'cipher_text': cipher_text} else: raise exceptions.InvalidField( "The cryptographic algorithm '{0}' is not supported for " "asymmetric encryption.".format(encryption_algorithm) )
def _encrypt_asymmetric(self, encryption_algorithm, encryption_key, plain_text, padding_method, hashing_algorithm=None): """ 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. """ if encryption_algorithm == enums.CryptographicAlgorithm.RSA: if padding_method == enums.PaddingMethod.OAEP: hash_algorithm = self._encryption_hash_algorithms.get( hashing_algorithm ) if hash_algorithm is None: raise exceptions.InvalidField( "The hashing algorithm '{0}' is not supported for " "asymmetric encryption.".format(hashing_algorithm) ) padding_method = asymmetric_padding.OAEP( mgf=asymmetric_padding.MGF1( algorithm=hash_algorithm() ), algorithm=hash_algorithm(), label=None ) elif padding_method == enums.PaddingMethod.PKCS1v15: padding_method = asymmetric_padding.PKCS1v15() else: raise exceptions.InvalidField( "The padding method '{0}' is not supported for asymmetric " "encryption.".format(padding_method) ) backend = default_backend() try: public_key = backend.load_der_public_key(encryption_key) except Exception: try: public_key = backend.load_pem_public_key(encryption_key) except Exception: raise exceptions.CryptographicFailure( "The public key bytes could not be loaded." ) cipher_text = public_key.encrypt( plain_text, padding_method ) return {'cipher_text': cipher_text} else: raise exceptions.InvalidField( "The cryptographic algorithm '{0}' is not supported for " "asymmetric encryption.".format(encryption_algorithm) )
[ "Encrypt", "data", "using", "asymmetric", "encryption", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L490-L571
[ "def", "_encrypt_asymmetric", "(", "self", ",", "encryption_algorithm", ",", "encryption_key", ",", "plain_text", ",", "padding_method", ",", "hashing_algorithm", "=", "None", ")", ":", "if", "encryption_algorithm", "==", "enums", ".", "CryptographicAlgorithm", ".", "RSA", ":", "if", "padding_method", "==", "enums", ".", "PaddingMethod", ".", "OAEP", ":", "hash_algorithm", "=", "self", ".", "_encryption_hash_algorithms", ".", "get", "(", "hashing_algorithm", ")", "if", "hash_algorithm", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The hashing algorithm '{0}' is not supported for \"", "\"asymmetric encryption.\"", ".", "format", "(", "hashing_algorithm", ")", ")", "padding_method", "=", "asymmetric_padding", ".", "OAEP", "(", "mgf", "=", "asymmetric_padding", ".", "MGF1", "(", "algorithm", "=", "hash_algorithm", "(", ")", ")", ",", "algorithm", "=", "hash_algorithm", "(", ")", ",", "label", "=", "None", ")", "elif", "padding_method", "==", "enums", ".", "PaddingMethod", ".", "PKCS1v15", ":", "padding_method", "=", "asymmetric_padding", ".", "PKCS1v15", "(", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The padding method '{0}' is not supported for asymmetric \"", "\"encryption.\"", ".", "format", "(", "padding_method", ")", ")", "backend", "=", "default_backend", "(", ")", "try", ":", "public_key", "=", "backend", ".", "load_der_public_key", "(", "encryption_key", ")", "except", "Exception", ":", "try", ":", "public_key", "=", "backend", ".", "load_pem_public_key", "(", "encryption_key", ")", "except", "Exception", ":", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"The public key bytes could not be loaded.\"", ")", "cipher_text", "=", "public_key", ".", "encrypt", "(", "plain_text", ",", "padding_method", ")", "return", "{", "'cipher_text'", ":", "cipher_text", "}", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The cryptographic algorithm '{0}' is not supported for \"", "\"asymmetric encryption.\"", ".", "format", "(", "encryption_algorithm", ")", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine.decrypt
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'
kmip/services/server/crypto/engine.py
def decrypt(self, decryption_algorithm, decryption_key, cipher_text, cipher_mode=None, padding_method=None, iv_nonce=None, hashing_algorithm=None): """ 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' """ if decryption_algorithm is None: raise exceptions.InvalidField("Decryption algorithm is required.") if decryption_algorithm == enums.CryptographicAlgorithm.RSA: return self._decrypt_asymmetric( decryption_algorithm, decryption_key, cipher_text, padding_method, hashing_algorithm=hashing_algorithm ) else: return self._decrypt_symmetric( decryption_algorithm, decryption_key, cipher_text, cipher_mode=cipher_mode, padding_method=padding_method, iv_nonce=iv_nonce )
def decrypt(self, decryption_algorithm, decryption_key, cipher_text, cipher_mode=None, padding_method=None, iv_nonce=None, hashing_algorithm=None): """ 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' """ if decryption_algorithm is None: raise exceptions.InvalidField("Decryption algorithm is required.") if decryption_algorithm == enums.CryptographicAlgorithm.RSA: return self._decrypt_asymmetric( decryption_algorithm, decryption_key, cipher_text, padding_method, hashing_algorithm=hashing_algorithm ) else: return self._decrypt_symmetric( decryption_algorithm, decryption_key, cipher_text, cipher_mode=cipher_mode, padding_method=padding_method, iv_nonce=iv_nonce )
[ "Decrypt", "data", "using", "symmetric", "decryption", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L608-L691
[ "def", "decrypt", "(", "self", ",", "decryption_algorithm", ",", "decryption_key", ",", "cipher_text", ",", "cipher_mode", "=", "None", ",", "padding_method", "=", "None", ",", "iv_nonce", "=", "None", ",", "hashing_algorithm", "=", "None", ")", ":", "if", "decryption_algorithm", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Decryption algorithm is required.\"", ")", "if", "decryption_algorithm", "==", "enums", ".", "CryptographicAlgorithm", ".", "RSA", ":", "return", "self", ".", "_decrypt_asymmetric", "(", "decryption_algorithm", ",", "decryption_key", ",", "cipher_text", ",", "padding_method", ",", "hashing_algorithm", "=", "hashing_algorithm", ")", "else", ":", "return", "self", ".", "_decrypt_symmetric", "(", "decryption_algorithm", ",", "decryption_key", ",", "cipher_text", ",", "cipher_mode", "=", "cipher_mode", ",", "padding_method", "=", "padding_method", ",", "iv_nonce", "=", "iv_nonce", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine._decrypt_symmetric
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.
kmip/services/server/crypto/engine.py
def _decrypt_symmetric( self, decryption_algorithm, decryption_key, cipher_text, cipher_mode=None, padding_method=None, iv_nonce=None): """ 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. """ # Set up the algorithm algorithm = self._symmetric_key_algorithms.get( decryption_algorithm, None ) if algorithm is None: raise exceptions.InvalidField( "Decryption algorithm '{0}' is not a supported symmetric " "decryption algorithm.".format(decryption_algorithm) ) try: algorithm = algorithm(decryption_key) except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "Invalid key bytes for the specified decryption algorithm." ) # Set up the cipher mode if needed if decryption_algorithm == enums.CryptographicAlgorithm.RC4: mode = None else: if cipher_mode is None: raise exceptions.InvalidField("Cipher mode is required.") mode = self._modes.get(cipher_mode, None) if mode is None: raise exceptions.InvalidField( "Cipher mode '{0}' is not a supported mode.".format( cipher_mode ) ) if hasattr(mode, 'initialization_vector') or \ hasattr(mode, 'nonce'): if iv_nonce is None: raise exceptions.InvalidField( "IV/nonce is required." ) mode = mode(iv_nonce) else: mode = mode() # Decrypt the plain text cipher = ciphers.Cipher(algorithm, mode, backend=default_backend()) decryptor = cipher.decryptor() plain_text = decryptor.update(cipher_text) + decryptor.finalize() # Unpad the plain text if needed (separate methods for testing # purposes) if cipher_mode in [ enums.BlockCipherMode.CBC, enums.BlockCipherMode.ECB ]: plain_text = self._handle_symmetric_padding( self._symmetric_key_algorithms.get(decryption_algorithm), plain_text, padding_method, undo_padding=True ) return plain_text
def _decrypt_symmetric( self, decryption_algorithm, decryption_key, cipher_text, cipher_mode=None, padding_method=None, iv_nonce=None): """ 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. """ # Set up the algorithm algorithm = self._symmetric_key_algorithms.get( decryption_algorithm, None ) if algorithm is None: raise exceptions.InvalidField( "Decryption algorithm '{0}' is not a supported symmetric " "decryption algorithm.".format(decryption_algorithm) ) try: algorithm = algorithm(decryption_key) except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "Invalid key bytes for the specified decryption algorithm." ) # Set up the cipher mode if needed if decryption_algorithm == enums.CryptographicAlgorithm.RC4: mode = None else: if cipher_mode is None: raise exceptions.InvalidField("Cipher mode is required.") mode = self._modes.get(cipher_mode, None) if mode is None: raise exceptions.InvalidField( "Cipher mode '{0}' is not a supported mode.".format( cipher_mode ) ) if hasattr(mode, 'initialization_vector') or \ hasattr(mode, 'nonce'): if iv_nonce is None: raise exceptions.InvalidField( "IV/nonce is required." ) mode = mode(iv_nonce) else: mode = mode() # Decrypt the plain text cipher = ciphers.Cipher(algorithm, mode, backend=default_backend()) decryptor = cipher.decryptor() plain_text = decryptor.update(cipher_text) + decryptor.finalize() # Unpad the plain text if needed (separate methods for testing # purposes) if cipher_mode in [ enums.BlockCipherMode.CBC, enums.BlockCipherMode.ECB ]: plain_text = self._handle_symmetric_padding( self._symmetric_key_algorithms.get(decryption_algorithm), plain_text, padding_method, undo_padding=True ) return plain_text
[ "Decrypt", "data", "using", "symmetric", "decryption", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L693-L790
[ "def", "_decrypt_symmetric", "(", "self", ",", "decryption_algorithm", ",", "decryption_key", ",", "cipher_text", ",", "cipher_mode", "=", "None", ",", "padding_method", "=", "None", ",", "iv_nonce", "=", "None", ")", ":", "# Set up the algorithm", "algorithm", "=", "self", ".", "_symmetric_key_algorithms", ".", "get", "(", "decryption_algorithm", ",", "None", ")", "if", "algorithm", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Decryption algorithm '{0}' is not a supported symmetric \"", "\"decryption algorithm.\"", ".", "format", "(", "decryption_algorithm", ")", ")", "try", ":", "algorithm", "=", "algorithm", "(", "decryption_key", ")", "except", "Exception", "as", "e", ":", "self", ".", "logger", ".", "exception", "(", "e", ")", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"Invalid key bytes for the specified decryption algorithm.\"", ")", "# Set up the cipher mode if needed", "if", "decryption_algorithm", "==", "enums", ".", "CryptographicAlgorithm", ".", "RC4", ":", "mode", "=", "None", "else", ":", "if", "cipher_mode", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Cipher mode is required.\"", ")", "mode", "=", "self", ".", "_modes", ".", "get", "(", "cipher_mode", ",", "None", ")", "if", "mode", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Cipher mode '{0}' is not a supported mode.\"", ".", "format", "(", "cipher_mode", ")", ")", "if", "hasattr", "(", "mode", ",", "'initialization_vector'", ")", "or", "hasattr", "(", "mode", ",", "'nonce'", ")", ":", "if", "iv_nonce", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"IV/nonce is required.\"", ")", "mode", "=", "mode", "(", "iv_nonce", ")", "else", ":", "mode", "=", "mode", "(", ")", "# Decrypt the plain text", "cipher", "=", "ciphers", ".", "Cipher", "(", "algorithm", ",", "mode", ",", "backend", "=", "default_backend", "(", ")", ")", "decryptor", "=", "cipher", ".", "decryptor", "(", ")", "plain_text", "=", "decryptor", ".", "update", "(", "cipher_text", ")", "+", "decryptor", ".", "finalize", "(", ")", "# Unpad the plain text if needed (separate methods for testing", "# purposes)", "if", "cipher_mode", "in", "[", "enums", ".", "BlockCipherMode", ".", "CBC", ",", "enums", ".", "BlockCipherMode", ".", "ECB", "]", ":", "plain_text", "=", "self", ".", "_handle_symmetric_padding", "(", "self", ".", "_symmetric_key_algorithms", ".", "get", "(", "decryption_algorithm", ")", ",", "plain_text", ",", "padding_method", ",", "undo_padding", "=", "True", ")", "return", "plain_text" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine._decrypt_asymmetric
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.
kmip/services/server/crypto/engine.py
def _decrypt_asymmetric( self, decryption_algorithm, decryption_key, cipher_text, padding_method, hashing_algorithm=None): """ 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. """ if decryption_algorithm == enums.CryptographicAlgorithm.RSA: if padding_method == enums.PaddingMethod.OAEP: hash_algorithm = self._encryption_hash_algorithms.get( hashing_algorithm ) if hash_algorithm is None: raise exceptions.InvalidField( "The hashing algorithm '{0}' is not supported for " "asymmetric decryption.".format(hashing_algorithm) ) padding_method = asymmetric_padding.OAEP( mgf=asymmetric_padding.MGF1( algorithm=hash_algorithm() ), algorithm=hash_algorithm(), label=None ) elif padding_method == enums.PaddingMethod.PKCS1v15: padding_method = asymmetric_padding.PKCS1v15() else: raise exceptions.InvalidField( "The padding method '{0}' is not supported for asymmetric " "decryption.".format(padding_method) ) backend = default_backend() try: private_key = backend.load_der_private_key( decryption_key, None ) except Exception: try: private_key = backend.load_pem_private_key( decryption_key, None ) except Exception: raise exceptions.CryptographicFailure( "The private key bytes could not be loaded." ) plain_text = private_key.decrypt( cipher_text, padding_method ) return plain_text else: raise exceptions.InvalidField( "The cryptographic algorithm '{0}' is not supported for " "asymmetric decryption.".format(decryption_algorithm) )
def _decrypt_asymmetric( self, decryption_algorithm, decryption_key, cipher_text, padding_method, hashing_algorithm=None): """ 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. """ if decryption_algorithm == enums.CryptographicAlgorithm.RSA: if padding_method == enums.PaddingMethod.OAEP: hash_algorithm = self._encryption_hash_algorithms.get( hashing_algorithm ) if hash_algorithm is None: raise exceptions.InvalidField( "The hashing algorithm '{0}' is not supported for " "asymmetric decryption.".format(hashing_algorithm) ) padding_method = asymmetric_padding.OAEP( mgf=asymmetric_padding.MGF1( algorithm=hash_algorithm() ), algorithm=hash_algorithm(), label=None ) elif padding_method == enums.PaddingMethod.PKCS1v15: padding_method = asymmetric_padding.PKCS1v15() else: raise exceptions.InvalidField( "The padding method '{0}' is not supported for asymmetric " "decryption.".format(padding_method) ) backend = default_backend() try: private_key = backend.load_der_private_key( decryption_key, None ) except Exception: try: private_key = backend.load_pem_private_key( decryption_key, None ) except Exception: raise exceptions.CryptographicFailure( "The private key bytes could not be loaded." ) plain_text = private_key.decrypt( cipher_text, padding_method ) return plain_text else: raise exceptions.InvalidField( "The cryptographic algorithm '{0}' is not supported for " "asymmetric decryption.".format(decryption_algorithm) )
[ "Encrypt", "data", "using", "asymmetric", "decryption", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L792-L880
[ "def", "_decrypt_asymmetric", "(", "self", ",", "decryption_algorithm", ",", "decryption_key", ",", "cipher_text", ",", "padding_method", ",", "hashing_algorithm", "=", "None", ")", ":", "if", "decryption_algorithm", "==", "enums", ".", "CryptographicAlgorithm", ".", "RSA", ":", "if", "padding_method", "==", "enums", ".", "PaddingMethod", ".", "OAEP", ":", "hash_algorithm", "=", "self", ".", "_encryption_hash_algorithms", ".", "get", "(", "hashing_algorithm", ")", "if", "hash_algorithm", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The hashing algorithm '{0}' is not supported for \"", "\"asymmetric decryption.\"", ".", "format", "(", "hashing_algorithm", ")", ")", "padding_method", "=", "asymmetric_padding", ".", "OAEP", "(", "mgf", "=", "asymmetric_padding", ".", "MGF1", "(", "algorithm", "=", "hash_algorithm", "(", ")", ")", ",", "algorithm", "=", "hash_algorithm", "(", ")", ",", "label", "=", "None", ")", "elif", "padding_method", "==", "enums", ".", "PaddingMethod", ".", "PKCS1v15", ":", "padding_method", "=", "asymmetric_padding", ".", "PKCS1v15", "(", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The padding method '{0}' is not supported for asymmetric \"", "\"decryption.\"", ".", "format", "(", "padding_method", ")", ")", "backend", "=", "default_backend", "(", ")", "try", ":", "private_key", "=", "backend", ".", "load_der_private_key", "(", "decryption_key", ",", "None", ")", "except", "Exception", ":", "try", ":", "private_key", "=", "backend", ".", "load_pem_private_key", "(", "decryption_key", ",", "None", ")", "except", "Exception", ":", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"The private key bytes could not be loaded.\"", ")", "plain_text", "=", "private_key", ".", "decrypt", "(", "cipher_text", ",", "padding_method", ")", "return", "plain_text", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The cryptographic algorithm '{0}' is not supported for \"", "\"asymmetric decryption.\"", ".", "format", "(", "decryption_algorithm", ")", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine._create_rsa_key_pair
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.
kmip/services/server/crypto/engine.py
def _create_rsa_key_pair(self, length, public_exponent=65537): """ 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. """ self.logger.info( "Generating an RSA key pair with length: {0}, and " "public_exponent: {1}".format( length, public_exponent ) ) try: private_key = rsa.generate_private_key( public_exponent=public_exponent, key_size=length, backend=default_backend()) public_key = private_key.public_key() private_bytes = private_key.private_bytes( serialization.Encoding.DER, serialization.PrivateFormat.PKCS8, serialization.NoEncryption()) public_bytes = public_key.public_bytes( serialization.Encoding.DER, serialization.PublicFormat.PKCS1) except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "An error occurred while generating the RSA key pair. " "See the server log for more information." ) public_key = { 'value': public_bytes, 'format': enums.KeyFormatType.PKCS_1, 'public_exponent': public_exponent } private_key = { 'value': private_bytes, 'format': enums.KeyFormatType.PKCS_8, 'public_exponent': public_exponent } return public_key, private_key
def _create_rsa_key_pair(self, length, public_exponent=65537): """ 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. """ self.logger.info( "Generating an RSA key pair with length: {0}, and " "public_exponent: {1}".format( length, public_exponent ) ) try: private_key = rsa.generate_private_key( public_exponent=public_exponent, key_size=length, backend=default_backend()) public_key = private_key.public_key() private_bytes = private_key.private_bytes( serialization.Encoding.DER, serialization.PrivateFormat.PKCS8, serialization.NoEncryption()) public_bytes = public_key.public_bytes( serialization.Encoding.DER, serialization.PublicFormat.PKCS1) except Exception as e: self.logger.exception(e) raise exceptions.CryptographicFailure( "An error occurred while generating the RSA key pair. " "See the server log for more information." ) public_key = { 'value': public_bytes, 'format': enums.KeyFormatType.PKCS_1, 'public_exponent': public_exponent } private_key = { 'value': private_bytes, 'format': enums.KeyFormatType.PKCS_8, 'public_exponent': public_exponent } return public_key, private_key
[ "Create", "an", "RSA", "key", "pair", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L882-L944
[ "def", "_create_rsa_key_pair", "(", "self", ",", "length", ",", "public_exponent", "=", "65537", ")", ":", "self", ".", "logger", ".", "info", "(", "\"Generating an RSA key pair with length: {0}, and \"", "\"public_exponent: {1}\"", ".", "format", "(", "length", ",", "public_exponent", ")", ")", "try", ":", "private_key", "=", "rsa", ".", "generate_private_key", "(", "public_exponent", "=", "public_exponent", ",", "key_size", "=", "length", ",", "backend", "=", "default_backend", "(", ")", ")", "public_key", "=", "private_key", ".", "public_key", "(", ")", "private_bytes", "=", "private_key", ".", "private_bytes", "(", "serialization", ".", "Encoding", ".", "DER", ",", "serialization", ".", "PrivateFormat", ".", "PKCS8", ",", "serialization", ".", "NoEncryption", "(", ")", ")", "public_bytes", "=", "public_key", ".", "public_bytes", "(", "serialization", ".", "Encoding", ".", "DER", ",", "serialization", ".", "PublicFormat", ".", "PKCS1", ")", "except", "Exception", "as", "e", ":", "self", ".", "logger", ".", "exception", "(", "e", ")", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"An error occurred while generating the RSA key pair. \"", "\"See the server log for more information.\"", ")", "public_key", "=", "{", "'value'", ":", "public_bytes", ",", "'format'", ":", "enums", ".", "KeyFormatType", ".", "PKCS_1", ",", "'public_exponent'", ":", "public_exponent", "}", "private_key", "=", "{", "'value'", ":", "private_bytes", ",", "'format'", ":", "enums", ".", "KeyFormatType", ".", "PKCS_8", ",", "'public_exponent'", ":", "public_exponent", "}", "return", "public_key", ",", "private_key" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine.derive_key
Derive key data using a variety of key derivation functions. Args: derivation_method (DerivationMethod): An enumeration specifying the key derivation method to use. Required. derivation_length (int): An integer specifying the size of the derived key data in bytes. Required. derivation_data (bytes): The non-cryptographic bytes to be used in the key derivation process (e.g., the data to be encrypted, hashed, HMACed). Required in the general case. Optional if the derivation method is Hash and the key material is provided. Optional, defaults to None. key_material (bytes): The bytes of the key material to use for key derivation. Required in the general case. Optional if the derivation_method is HASH and derivation_data is provided. Optional, defaults to None. hash_algorithm (HashingAlgorithm): An enumeration specifying the hashing algorithm to use with the key derivation method. Required in the general case, optional if the derivation method specifies encryption. Optional, defaults to None. salt (bytes): Bytes representing a randomly generated salt. Required if the derivation method is PBKDF2. Optional, defaults to None. iteration_count (int): An integer representing the number of iterations to use when deriving key material. Required if the derivation method is PBKDF2. Optional, defaults to None. encryption_algorithm (CryptographicAlgorithm): An enumeration specifying the symmetric encryption algorithm to use for encryption-based key derivation. Required if the derivation method specifies encryption. Optional, defaults to None. cipher_mode (BlockCipherMode): An enumeration specifying the block cipher mode to use with the encryption algorithm. Required in in the general case if the derivation method specifies encryption and the encryption algorithm is specified. Optional if the encryption algorithm is RC4 (aka ARC4). Optional, defaults to None. padding_method (PaddingMethod): An enumeration specifying the padding method to use on the data before encryption. Required in in the general case if the derivation method specifies encryption and the encryption algorithm is specified. 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. Required in the general case if the derivation method specifies encryption and the encryption algorithm is specified. Optional, defaults to None. If required and not provided, it will be autogenerated. Returns: bytes: the bytes of the derived data Raises: InvalidField: Raised when cryptographic data and/or settings are unsupported or incompatible with the derivation method. Example: >>> engine = CryptographyEngine() >>> result = engine.derive_key( ... derivation_method=enums.DerivationMethod.HASH, ... derivation_length=16, ... derivation_data=b'abc', ... hash_algorithm=enums.HashingAlgorithm.MD5 ... ) >>> result b'\x90\x01P\x98<\xd2O\xb0\xd6\x96?}(\xe1\x7fr'
kmip/services/server/crypto/engine.py
def derive_key(self, derivation_method, derivation_length, derivation_data=None, key_material=None, hash_algorithm=None, salt=None, iteration_count=None, encryption_algorithm=None, cipher_mode=None, padding_method=None, iv_nonce=None): """ Derive key data using a variety of key derivation functions. Args: derivation_method (DerivationMethod): An enumeration specifying the key derivation method to use. Required. derivation_length (int): An integer specifying the size of the derived key data in bytes. Required. derivation_data (bytes): The non-cryptographic bytes to be used in the key derivation process (e.g., the data to be encrypted, hashed, HMACed). Required in the general case. Optional if the derivation method is Hash and the key material is provided. Optional, defaults to None. key_material (bytes): The bytes of the key material to use for key derivation. Required in the general case. Optional if the derivation_method is HASH and derivation_data is provided. Optional, defaults to None. hash_algorithm (HashingAlgorithm): An enumeration specifying the hashing algorithm to use with the key derivation method. Required in the general case, optional if the derivation method specifies encryption. Optional, defaults to None. salt (bytes): Bytes representing a randomly generated salt. Required if the derivation method is PBKDF2. Optional, defaults to None. iteration_count (int): An integer representing the number of iterations to use when deriving key material. Required if the derivation method is PBKDF2. Optional, defaults to None. encryption_algorithm (CryptographicAlgorithm): An enumeration specifying the symmetric encryption algorithm to use for encryption-based key derivation. Required if the derivation method specifies encryption. Optional, defaults to None. cipher_mode (BlockCipherMode): An enumeration specifying the block cipher mode to use with the encryption algorithm. Required in in the general case if the derivation method specifies encryption and the encryption algorithm is specified. Optional if the encryption algorithm is RC4 (aka ARC4). Optional, defaults to None. padding_method (PaddingMethod): An enumeration specifying the padding method to use on the data before encryption. Required in in the general case if the derivation method specifies encryption and the encryption algorithm is specified. 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. Required in the general case if the derivation method specifies encryption and the encryption algorithm is specified. Optional, defaults to None. If required and not provided, it will be autogenerated. Returns: bytes: the bytes of the derived data Raises: InvalidField: Raised when cryptographic data and/or settings are unsupported or incompatible with the derivation method. Example: >>> engine = CryptographyEngine() >>> result = engine.derive_key( ... derivation_method=enums.DerivationMethod.HASH, ... derivation_length=16, ... derivation_data=b'abc', ... hash_algorithm=enums.HashingAlgorithm.MD5 ... ) >>> result b'\x90\x01P\x98<\xd2O\xb0\xd6\x96?}(\xe1\x7fr' """ if derivation_method == enums.DerivationMethod.ENCRYPT: result = self.encrypt( encryption_algorithm=encryption_algorithm, encryption_key=key_material, plain_text=derivation_data, cipher_mode=cipher_mode, padding_method=padding_method, iv_nonce=iv_nonce ) return result.get('cipher_text') else: # Handle key derivation functions that use hash algorithms # Set up the hashing algorithm if hash_algorithm is None: raise exceptions.InvalidField("Hash algorithm is required.") hashing_algorithm = self._encryption_hash_algorithms.get( hash_algorithm, None ) if hashing_algorithm is None: raise exceptions.InvalidField( "Hash algorithm '{0}' is not a supported hashing " "algorithm.".format(hash_algorithm) ) if derivation_method == enums.DerivationMethod.HMAC: df = hkdf.HKDF( algorithm=hashing_algorithm(), length=derivation_length, salt=salt, info=derivation_data, backend=default_backend() ) derived_data = df.derive(key_material) return derived_data elif derivation_method == enums.DerivationMethod.HASH: if None not in [derivation_data, key_material]: raise exceptions.InvalidField( "For hash-based key derivation, specify only " "derivation data or key material, not both." ) elif derivation_data is not None: hashing_data = derivation_data elif key_material is not None: hashing_data = key_material else: raise exceptions.InvalidField( "For hash-based key derivation, derivation data or " "key material must be specified." ) df = hashes.Hash( algorithm=hashing_algorithm(), backend=default_backend() ) df.update(hashing_data) derived_data = df.finalize() return derived_data elif derivation_method == enums.DerivationMethod.PBKDF2: if salt is None: raise exceptions.InvalidField( "For PBKDF2 key derivation, salt must be specified." ) if iteration_count is None: raise exceptions.InvalidField( "For PBKDF2 key derivation, iteration count must be " "specified." ) df = pbkdf2.PBKDF2HMAC( algorithm=hashing_algorithm(), length=derivation_length, salt=salt, iterations=iteration_count, backend=default_backend() ) derived_data = df.derive(key_material) return derived_data elif derivation_method == enums.DerivationMethod.NIST800_108_C: df = kbkdf.KBKDFHMAC( algorithm=hashing_algorithm(), mode=kbkdf.Mode.CounterMode, length=derivation_length, rlen=4, llen=None, location=kbkdf.CounterLocation.BeforeFixed, label=None, context=None, fixed=derivation_data, backend=default_backend() ) derived_data = df.derive(key_material) return derived_data else: raise exceptions.InvalidField( "Derivation method '{0}' is not a supported key " "derivation method.".format(derivation_method) )
def derive_key(self, derivation_method, derivation_length, derivation_data=None, key_material=None, hash_algorithm=None, salt=None, iteration_count=None, encryption_algorithm=None, cipher_mode=None, padding_method=None, iv_nonce=None): """ Derive key data using a variety of key derivation functions. Args: derivation_method (DerivationMethod): An enumeration specifying the key derivation method to use. Required. derivation_length (int): An integer specifying the size of the derived key data in bytes. Required. derivation_data (bytes): The non-cryptographic bytes to be used in the key derivation process (e.g., the data to be encrypted, hashed, HMACed). Required in the general case. Optional if the derivation method is Hash and the key material is provided. Optional, defaults to None. key_material (bytes): The bytes of the key material to use for key derivation. Required in the general case. Optional if the derivation_method is HASH and derivation_data is provided. Optional, defaults to None. hash_algorithm (HashingAlgorithm): An enumeration specifying the hashing algorithm to use with the key derivation method. Required in the general case, optional if the derivation method specifies encryption. Optional, defaults to None. salt (bytes): Bytes representing a randomly generated salt. Required if the derivation method is PBKDF2. Optional, defaults to None. iteration_count (int): An integer representing the number of iterations to use when deriving key material. Required if the derivation method is PBKDF2. Optional, defaults to None. encryption_algorithm (CryptographicAlgorithm): An enumeration specifying the symmetric encryption algorithm to use for encryption-based key derivation. Required if the derivation method specifies encryption. Optional, defaults to None. cipher_mode (BlockCipherMode): An enumeration specifying the block cipher mode to use with the encryption algorithm. Required in in the general case if the derivation method specifies encryption and the encryption algorithm is specified. Optional if the encryption algorithm is RC4 (aka ARC4). Optional, defaults to None. padding_method (PaddingMethod): An enumeration specifying the padding method to use on the data before encryption. Required in in the general case if the derivation method specifies encryption and the encryption algorithm is specified. 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. Required in the general case if the derivation method specifies encryption and the encryption algorithm is specified. Optional, defaults to None. If required and not provided, it will be autogenerated. Returns: bytes: the bytes of the derived data Raises: InvalidField: Raised when cryptographic data and/or settings are unsupported or incompatible with the derivation method. Example: >>> engine = CryptographyEngine() >>> result = engine.derive_key( ... derivation_method=enums.DerivationMethod.HASH, ... derivation_length=16, ... derivation_data=b'abc', ... hash_algorithm=enums.HashingAlgorithm.MD5 ... ) >>> result b'\x90\x01P\x98<\xd2O\xb0\xd6\x96?}(\xe1\x7fr' """ if derivation_method == enums.DerivationMethod.ENCRYPT: result = self.encrypt( encryption_algorithm=encryption_algorithm, encryption_key=key_material, plain_text=derivation_data, cipher_mode=cipher_mode, padding_method=padding_method, iv_nonce=iv_nonce ) return result.get('cipher_text') else: # Handle key derivation functions that use hash algorithms # Set up the hashing algorithm if hash_algorithm is None: raise exceptions.InvalidField("Hash algorithm is required.") hashing_algorithm = self._encryption_hash_algorithms.get( hash_algorithm, None ) if hashing_algorithm is None: raise exceptions.InvalidField( "Hash algorithm '{0}' is not a supported hashing " "algorithm.".format(hash_algorithm) ) if derivation_method == enums.DerivationMethod.HMAC: df = hkdf.HKDF( algorithm=hashing_algorithm(), length=derivation_length, salt=salt, info=derivation_data, backend=default_backend() ) derived_data = df.derive(key_material) return derived_data elif derivation_method == enums.DerivationMethod.HASH: if None not in [derivation_data, key_material]: raise exceptions.InvalidField( "For hash-based key derivation, specify only " "derivation data or key material, not both." ) elif derivation_data is not None: hashing_data = derivation_data elif key_material is not None: hashing_data = key_material else: raise exceptions.InvalidField( "For hash-based key derivation, derivation data or " "key material must be specified." ) df = hashes.Hash( algorithm=hashing_algorithm(), backend=default_backend() ) df.update(hashing_data) derived_data = df.finalize() return derived_data elif derivation_method == enums.DerivationMethod.PBKDF2: if salt is None: raise exceptions.InvalidField( "For PBKDF2 key derivation, salt must be specified." ) if iteration_count is None: raise exceptions.InvalidField( "For PBKDF2 key derivation, iteration count must be " "specified." ) df = pbkdf2.PBKDF2HMAC( algorithm=hashing_algorithm(), length=derivation_length, salt=salt, iterations=iteration_count, backend=default_backend() ) derived_data = df.derive(key_material) return derived_data elif derivation_method == enums.DerivationMethod.NIST800_108_C: df = kbkdf.KBKDFHMAC( algorithm=hashing_algorithm(), mode=kbkdf.Mode.CounterMode, length=derivation_length, rlen=4, llen=None, location=kbkdf.CounterLocation.BeforeFixed, label=None, context=None, fixed=derivation_data, backend=default_backend() ) derived_data = df.derive(key_material) return derived_data else: raise exceptions.InvalidField( "Derivation method '{0}' is not a supported key " "derivation method.".format(derivation_method) )
[ "Derive", "key", "data", "using", "a", "variety", "of", "key", "derivation", "functions", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L946-L1123
[ "def", "derive_key", "(", "self", ",", "derivation_method", ",", "derivation_length", ",", "derivation_data", "=", "None", ",", "key_material", "=", "None", ",", "hash_algorithm", "=", "None", ",", "salt", "=", "None", ",", "iteration_count", "=", "None", ",", "encryption_algorithm", "=", "None", ",", "cipher_mode", "=", "None", ",", "padding_method", "=", "None", ",", "iv_nonce", "=", "None", ")", ":", "if", "derivation_method", "==", "enums", ".", "DerivationMethod", ".", "ENCRYPT", ":", "result", "=", "self", ".", "encrypt", "(", "encryption_algorithm", "=", "encryption_algorithm", ",", "encryption_key", "=", "key_material", ",", "plain_text", "=", "derivation_data", ",", "cipher_mode", "=", "cipher_mode", ",", "padding_method", "=", "padding_method", ",", "iv_nonce", "=", "iv_nonce", ")", "return", "result", ".", "get", "(", "'cipher_text'", ")", "else", ":", "# Handle key derivation functions that use hash algorithms", "# Set up the hashing algorithm", "if", "hash_algorithm", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Hash algorithm is required.\"", ")", "hashing_algorithm", "=", "self", ".", "_encryption_hash_algorithms", ".", "get", "(", "hash_algorithm", ",", "None", ")", "if", "hashing_algorithm", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Hash algorithm '{0}' is not a supported hashing \"", "\"algorithm.\"", ".", "format", "(", "hash_algorithm", ")", ")", "if", "derivation_method", "==", "enums", ".", "DerivationMethod", ".", "HMAC", ":", "df", "=", "hkdf", ".", "HKDF", "(", "algorithm", "=", "hashing_algorithm", "(", ")", ",", "length", "=", "derivation_length", ",", "salt", "=", "salt", ",", "info", "=", "derivation_data", ",", "backend", "=", "default_backend", "(", ")", ")", "derived_data", "=", "df", ".", "derive", "(", "key_material", ")", "return", "derived_data", "elif", "derivation_method", "==", "enums", ".", "DerivationMethod", ".", "HASH", ":", "if", "None", "not", "in", "[", "derivation_data", ",", "key_material", "]", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"For hash-based key derivation, specify only \"", "\"derivation data or key material, not both.\"", ")", "elif", "derivation_data", "is", "not", "None", ":", "hashing_data", "=", "derivation_data", "elif", "key_material", "is", "not", "None", ":", "hashing_data", "=", "key_material", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"For hash-based key derivation, derivation data or \"", "\"key material must be specified.\"", ")", "df", "=", "hashes", ".", "Hash", "(", "algorithm", "=", "hashing_algorithm", "(", ")", ",", "backend", "=", "default_backend", "(", ")", ")", "df", ".", "update", "(", "hashing_data", ")", "derived_data", "=", "df", ".", "finalize", "(", ")", "return", "derived_data", "elif", "derivation_method", "==", "enums", ".", "DerivationMethod", ".", "PBKDF2", ":", "if", "salt", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"For PBKDF2 key derivation, salt must be specified.\"", ")", "if", "iteration_count", "is", "None", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"For PBKDF2 key derivation, iteration count must be \"", "\"specified.\"", ")", "df", "=", "pbkdf2", ".", "PBKDF2HMAC", "(", "algorithm", "=", "hashing_algorithm", "(", ")", ",", "length", "=", "derivation_length", ",", "salt", "=", "salt", ",", "iterations", "=", "iteration_count", ",", "backend", "=", "default_backend", "(", ")", ")", "derived_data", "=", "df", ".", "derive", "(", "key_material", ")", "return", "derived_data", "elif", "derivation_method", "==", "enums", ".", "DerivationMethod", ".", "NIST800_108_C", ":", "df", "=", "kbkdf", ".", "KBKDFHMAC", "(", "algorithm", "=", "hashing_algorithm", "(", ")", ",", "mode", "=", "kbkdf", ".", "Mode", ".", "CounterMode", ",", "length", "=", "derivation_length", ",", "rlen", "=", "4", ",", "llen", "=", "None", ",", "location", "=", "kbkdf", ".", "CounterLocation", ".", "BeforeFixed", ",", "label", "=", "None", ",", "context", "=", "None", ",", "fixed", "=", "derivation_data", ",", "backend", "=", "default_backend", "(", ")", ")", "derived_data", "=", "df", ".", "derive", "(", "key_material", ")", "return", "derived_data", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Derivation method '{0}' is not a supported key \"", "\"derivation method.\"", ".", "format", "(", "derivation_method", ")", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine.wrap_key
Args: key_material (bytes): The bytes of the key to wrap. Required. wrapping_method (WrappingMethod): A WrappingMethod enumeration specifying what wrapping technique to use to wrap the key material. Required. key_wrap_algorithm (BlockCipherMode): A BlockCipherMode enumeration specifying the key wrapping algorithm to use to wrap the key material. Required. encryption_key (bytes): The bytes of the encryption key to use to encrypt the key material. Required. Returns: bytes: the bytes of the wrapped key Raises: CryptographicFailure: Raised when an error occurs during key wrapping. InvalidField: Raised when an unsupported wrapping or encryption algorithm is specified. Example: >>> engine = CryptographyEngine() >>> result = engine.wrap_key( ... key_material=( ... b'\x00\x11\x22\x33\x44\x55\x66\x77' ... b'\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF' ... ) ... wrapping_method=enums.WrappingMethod.ENCRYPT, ... key_wrap_algorithm=enums.BlockCipherMode.NIST_KEY_WRAP, ... encryption_key=( ... b'\x00\x01\x02\x03\x04\x05\x06\x07' ... b'\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F' ... ) ... ) >>> result b'\x1f\xa6\x8b\n\x81\x12\xb4G\xae\xf3K\xd8\xfbZ{\x82\x9d>\x86#q \xd2\xcf\xe5'
kmip/services/server/crypto/engine.py
def wrap_key(self, key_material, wrapping_method, key_wrap_algorithm, encryption_key): """ Args: key_material (bytes): The bytes of the key to wrap. Required. wrapping_method (WrappingMethod): A WrappingMethod enumeration specifying what wrapping technique to use to wrap the key material. Required. key_wrap_algorithm (BlockCipherMode): A BlockCipherMode enumeration specifying the key wrapping algorithm to use to wrap the key material. Required. encryption_key (bytes): The bytes of the encryption key to use to encrypt the key material. Required. Returns: bytes: the bytes of the wrapped key Raises: CryptographicFailure: Raised when an error occurs during key wrapping. InvalidField: Raised when an unsupported wrapping or encryption algorithm is specified. Example: >>> engine = CryptographyEngine() >>> result = engine.wrap_key( ... key_material=( ... b'\x00\x11\x22\x33\x44\x55\x66\x77' ... b'\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF' ... ) ... wrapping_method=enums.WrappingMethod.ENCRYPT, ... key_wrap_algorithm=enums.BlockCipherMode.NIST_KEY_WRAP, ... encryption_key=( ... b'\x00\x01\x02\x03\x04\x05\x06\x07' ... b'\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F' ... ) ... ) >>> result b'\x1f\xa6\x8b\n\x81\x12\xb4G\xae\xf3K\xd8\xfbZ{\x82\x9d>\x86#q \xd2\xcf\xe5' """ if wrapping_method == enums.WrappingMethod.ENCRYPT: if key_wrap_algorithm == enums.BlockCipherMode.NIST_KEY_WRAP: try: wrapped_key = keywrap.aes_key_wrap( encryption_key, key_material, default_backend() ) return wrapped_key except Exception as e: raise exceptions.CryptographicFailure(str(e)) else: raise exceptions.InvalidField( "Encryption algorithm '{0}' is not a supported key " "wrapping algorithm.".format(key_wrap_algorithm) ) else: raise exceptions.InvalidField( "Wrapping method '{0}' is not a supported key wrapping " "method.".format(wrapping_method) )
def wrap_key(self, key_material, wrapping_method, key_wrap_algorithm, encryption_key): """ Args: key_material (bytes): The bytes of the key to wrap. Required. wrapping_method (WrappingMethod): A WrappingMethod enumeration specifying what wrapping technique to use to wrap the key material. Required. key_wrap_algorithm (BlockCipherMode): A BlockCipherMode enumeration specifying the key wrapping algorithm to use to wrap the key material. Required. encryption_key (bytes): The bytes of the encryption key to use to encrypt the key material. Required. Returns: bytes: the bytes of the wrapped key Raises: CryptographicFailure: Raised when an error occurs during key wrapping. InvalidField: Raised when an unsupported wrapping or encryption algorithm is specified. Example: >>> engine = CryptographyEngine() >>> result = engine.wrap_key( ... key_material=( ... b'\x00\x11\x22\x33\x44\x55\x66\x77' ... b'\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF' ... ) ... wrapping_method=enums.WrappingMethod.ENCRYPT, ... key_wrap_algorithm=enums.BlockCipherMode.NIST_KEY_WRAP, ... encryption_key=( ... b'\x00\x01\x02\x03\x04\x05\x06\x07' ... b'\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F' ... ) ... ) >>> result b'\x1f\xa6\x8b\n\x81\x12\xb4G\xae\xf3K\xd8\xfbZ{\x82\x9d>\x86#q \xd2\xcf\xe5' """ if wrapping_method == enums.WrappingMethod.ENCRYPT: if key_wrap_algorithm == enums.BlockCipherMode.NIST_KEY_WRAP: try: wrapped_key = keywrap.aes_key_wrap( encryption_key, key_material, default_backend() ) return wrapped_key except Exception as e: raise exceptions.CryptographicFailure(str(e)) else: raise exceptions.InvalidField( "Encryption algorithm '{0}' is not a supported key " "wrapping algorithm.".format(key_wrap_algorithm) ) else: raise exceptions.InvalidField( "Wrapping method '{0}' is not a supported key wrapping " "method.".format(wrapping_method) )
[ "Args", ":", "key_material", "(", "bytes", ")", ":", "The", "bytes", "of", "the", "key", "to", "wrap", ".", "Required", ".", "wrapping_method", "(", "WrappingMethod", ")", ":", "A", "WrappingMethod", "enumeration", "specifying", "what", "wrapping", "technique", "to", "use", "to", "wrap", "the", "key", "material", ".", "Required", ".", "key_wrap_algorithm", "(", "BlockCipherMode", ")", ":", "A", "BlockCipherMode", "enumeration", "specifying", "the", "key", "wrapping", "algorithm", "to", "use", "to", "wrap", "the", "key", "material", ".", "Required", ".", "encryption_key", "(", "bytes", ")", ":", "The", "bytes", "of", "the", "encryption", "key", "to", "use", "to", "encrypt", "the", "key", "material", ".", "Required", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L1125-L1189
[ "def", "wrap_key", "(", "self", ",", "key_material", ",", "wrapping_method", ",", "key_wrap_algorithm", ",", "encryption_key", ")", ":", "if", "wrapping_method", "==", "enums", ".", "WrappingMethod", ".", "ENCRYPT", ":", "if", "key_wrap_algorithm", "==", "enums", ".", "BlockCipherMode", ".", "NIST_KEY_WRAP", ":", "try", ":", "wrapped_key", "=", "keywrap", ".", "aes_key_wrap", "(", "encryption_key", ",", "key_material", ",", "default_backend", "(", ")", ")", "return", "wrapped_key", "except", "Exception", "as", "e", ":", "raise", "exceptions", ".", "CryptographicFailure", "(", "str", "(", "e", ")", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Encryption algorithm '{0}' is not a supported key \"", "\"wrapping algorithm.\"", ".", "format", "(", "key_wrap_algorithm", ")", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Wrapping method '{0}' is not a supported key wrapping \"", "\"method.\"", ".", "format", "(", "wrapping_method", ")", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine._create_RSA_private_key
Instantiates an RSA key from bytes. Args: bytes (byte string): Bytes of RSA private key. Returns: private_key (cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey): RSA private key created from key bytes.
kmip/services/server/crypto/engine.py
def _create_RSA_private_key(self, bytes): """ Instantiates an RSA key from bytes. Args: bytes (byte string): Bytes of RSA private key. Returns: private_key (cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey): RSA private key created from key bytes. """ try: private_key = serialization.load_pem_private_key( bytes, password=None, backend=default_backend() ) return private_key except Exception: private_key = serialization.load_der_private_key( bytes, password=None, backend=default_backend() ) return private_key
def _create_RSA_private_key(self, bytes): """ Instantiates an RSA key from bytes. Args: bytes (byte string): Bytes of RSA private key. Returns: private_key (cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey): RSA private key created from key bytes. """ try: private_key = serialization.load_pem_private_key( bytes, password=None, backend=default_backend() ) return private_key except Exception: private_key = serialization.load_der_private_key( bytes, password=None, backend=default_backend() ) return private_key
[ "Instantiates", "an", "RSA", "key", "from", "bytes", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L1191-L1217
[ "def", "_create_RSA_private_key", "(", "self", ",", "bytes", ")", ":", "try", ":", "private_key", "=", "serialization", ".", "load_pem_private_key", "(", "bytes", ",", "password", "=", "None", ",", "backend", "=", "default_backend", "(", ")", ")", "return", "private_key", "except", "Exception", ":", "private_key", "=", "serialization", ".", "load_der_private_key", "(", "bytes", ",", "password", "=", "None", ",", "backend", "=", "default_backend", "(", ")", ")", "return", "private_key" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine.sign
Args: digital_signature_algorithm (DigitalSignatureAlgorithm): An enumeration specifying the asymmetric cryptographic algorithm and hashing algorithm to use for the signature operation. Can be None if cryptographic_algorithm and hash_algorithm are set. crypto_alg (CryptographicAlgorithm): An enumeration specifying the asymmetric cryptographic algorithm to use for the signature operation. Can be None if digital_signature_algorithm is set. hash_algorithm (HashingAlgorithm): An enumeration specifying the hash algorithm to use for the signature operation. Can be None if digital_signature_algorithm is set. padding (PaddingMethod): An enumeration specifying the asymmetric padding method to use for the signature operation. signing_key (bytes): The bytes of the private key to use for the signature operation. data (bytes): The data to be signed. Returns: signature (bytes): the bytes of the signature data Raises: CryptographicFailure: Raised when an error occurs during signature creation. InvalidField: Raised when an unsupported hashing or cryptographic algorithm is specified.
kmip/services/server/crypto/engine.py
def sign(self, digital_signature_algorithm, crypto_alg, hash_algorithm, padding, signing_key, data): """ Args: digital_signature_algorithm (DigitalSignatureAlgorithm): An enumeration specifying the asymmetric cryptographic algorithm and hashing algorithm to use for the signature operation. Can be None if cryptographic_algorithm and hash_algorithm are set. crypto_alg (CryptographicAlgorithm): An enumeration specifying the asymmetric cryptographic algorithm to use for the signature operation. Can be None if digital_signature_algorithm is set. hash_algorithm (HashingAlgorithm): An enumeration specifying the hash algorithm to use for the signature operation. Can be None if digital_signature_algorithm is set. padding (PaddingMethod): An enumeration specifying the asymmetric padding method to use for the signature operation. signing_key (bytes): The bytes of the private key to use for the signature operation. data (bytes): The data to be signed. Returns: signature (bytes): the bytes of the signature data Raises: CryptographicFailure: Raised when an error occurs during signature creation. InvalidField: Raised when an unsupported hashing or cryptographic algorithm is specified. """ if digital_signature_algorithm: (hash_alg, crypto_alg) = self._digital_signature_algorithms.get( digital_signature_algorithm, (None, None) ) elif crypto_alg and hash_algorithm: hash_alg = self._encryption_hash_algorithms.get( hash_algorithm, None ) else: raise exceptions.InvalidField( 'For signing, either a digital signature algorithm or a hash' ' algorithm and a cryptographic algorithm must be specified.' ) if crypto_alg == enums.CryptographicAlgorithm.RSA: try: key = self._create_RSA_private_key(signing_key) except Exception: raise exceptions.InvalidField('Unable to deserialize key ' 'bytes, unknown format.') else: raise exceptions.InvalidField( 'For signing, an RSA key must be used.' ) if padding: padding_method = self._asymmetric_padding_methods.get( padding, None ) else: raise exceptions.InvalidField( 'For signing, a padding method must be specified.' ) if padding == enums.PaddingMethod.PSS: signature = key.sign( data, asymmetric_padding.PSS( mgf=asymmetric_padding.MGF1(hash_alg()), salt_length=asymmetric_padding.PSS.MAX_LENGTH ), hash_alg() ) elif padding == enums.PaddingMethod.PKCS1v15: signature = key.sign( data, padding_method(), hash_alg() ) else: raise exceptions.InvalidField( "Padding method '{0}' is not a supported signature " "padding method.".format(padding) ) return signature
def sign(self, digital_signature_algorithm, crypto_alg, hash_algorithm, padding, signing_key, data): """ Args: digital_signature_algorithm (DigitalSignatureAlgorithm): An enumeration specifying the asymmetric cryptographic algorithm and hashing algorithm to use for the signature operation. Can be None if cryptographic_algorithm and hash_algorithm are set. crypto_alg (CryptographicAlgorithm): An enumeration specifying the asymmetric cryptographic algorithm to use for the signature operation. Can be None if digital_signature_algorithm is set. hash_algorithm (HashingAlgorithm): An enumeration specifying the hash algorithm to use for the signature operation. Can be None if digital_signature_algorithm is set. padding (PaddingMethod): An enumeration specifying the asymmetric padding method to use for the signature operation. signing_key (bytes): The bytes of the private key to use for the signature operation. data (bytes): The data to be signed. Returns: signature (bytes): the bytes of the signature data Raises: CryptographicFailure: Raised when an error occurs during signature creation. InvalidField: Raised when an unsupported hashing or cryptographic algorithm is specified. """ if digital_signature_algorithm: (hash_alg, crypto_alg) = self._digital_signature_algorithms.get( digital_signature_algorithm, (None, None) ) elif crypto_alg and hash_algorithm: hash_alg = self._encryption_hash_algorithms.get( hash_algorithm, None ) else: raise exceptions.InvalidField( 'For signing, either a digital signature algorithm or a hash' ' algorithm and a cryptographic algorithm must be specified.' ) if crypto_alg == enums.CryptographicAlgorithm.RSA: try: key = self._create_RSA_private_key(signing_key) except Exception: raise exceptions.InvalidField('Unable to deserialize key ' 'bytes, unknown format.') else: raise exceptions.InvalidField( 'For signing, an RSA key must be used.' ) if padding: padding_method = self._asymmetric_padding_methods.get( padding, None ) else: raise exceptions.InvalidField( 'For signing, a padding method must be specified.' ) if padding == enums.PaddingMethod.PSS: signature = key.sign( data, asymmetric_padding.PSS( mgf=asymmetric_padding.MGF1(hash_alg()), salt_length=asymmetric_padding.PSS.MAX_LENGTH ), hash_alg() ) elif padding == enums.PaddingMethod.PKCS1v15: signature = key.sign( data, padding_method(), hash_alg() ) else: raise exceptions.InvalidField( "Padding method '{0}' is not a supported signature " "padding method.".format(padding) ) return signature
[ "Args", ":", "digital_signature_algorithm", "(", "DigitalSignatureAlgorithm", ")", ":", "An", "enumeration", "specifying", "the", "asymmetric", "cryptographic", "algorithm", "and", "hashing", "algorithm", "to", "use", "for", "the", "signature", "operation", ".", "Can", "be", "None", "if", "cryptographic_algorithm", "and", "hash_algorithm", "are", "set", ".", "crypto_alg", "(", "CryptographicAlgorithm", ")", ":", "An", "enumeration", "specifying", "the", "asymmetric", "cryptographic", "algorithm", "to", "use", "for", "the", "signature", "operation", ".", "Can", "be", "None", "if", "digital_signature_algorithm", "is", "set", ".", "hash_algorithm", "(", "HashingAlgorithm", ")", ":", "An", "enumeration", "specifying", "the", "hash", "algorithm", "to", "use", "for", "the", "signature", "operation", ".", "Can", "be", "None", "if", "digital_signature_algorithm", "is", "set", ".", "padding", "(", "PaddingMethod", ")", ":", "An", "enumeration", "specifying", "the", "asymmetric", "padding", "method", "to", "use", "for", "the", "signature", "operation", ".", "signing_key", "(", "bytes", ")", ":", "The", "bytes", "of", "the", "private", "key", "to", "use", "for", "the", "signature", "operation", ".", "data", "(", "bytes", ")", ":", "The", "data", "to", "be", "signed", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L1219-L1311
[ "def", "sign", "(", "self", ",", "digital_signature_algorithm", ",", "crypto_alg", ",", "hash_algorithm", ",", "padding", ",", "signing_key", ",", "data", ")", ":", "if", "digital_signature_algorithm", ":", "(", "hash_alg", ",", "crypto_alg", ")", "=", "self", ".", "_digital_signature_algorithms", ".", "get", "(", "digital_signature_algorithm", ",", "(", "None", ",", "None", ")", ")", "elif", "crypto_alg", "and", "hash_algorithm", ":", "hash_alg", "=", "self", ".", "_encryption_hash_algorithms", ".", "get", "(", "hash_algorithm", ",", "None", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "'For signing, either a digital signature algorithm or a hash'", "' algorithm and a cryptographic algorithm must be specified.'", ")", "if", "crypto_alg", "==", "enums", ".", "CryptographicAlgorithm", ".", "RSA", ":", "try", ":", "key", "=", "self", ".", "_create_RSA_private_key", "(", "signing_key", ")", "except", "Exception", ":", "raise", "exceptions", ".", "InvalidField", "(", "'Unable to deserialize key '", "'bytes, unknown format.'", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "'For signing, an RSA key must be used.'", ")", "if", "padding", ":", "padding_method", "=", "self", ".", "_asymmetric_padding_methods", ".", "get", "(", "padding", ",", "None", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "'For signing, a padding method must be specified.'", ")", "if", "padding", "==", "enums", ".", "PaddingMethod", ".", "PSS", ":", "signature", "=", "key", ".", "sign", "(", "data", ",", "asymmetric_padding", ".", "PSS", "(", "mgf", "=", "asymmetric_padding", ".", "MGF1", "(", "hash_alg", "(", ")", ")", ",", "salt_length", "=", "asymmetric_padding", ".", "PSS", ".", "MAX_LENGTH", ")", ",", "hash_alg", "(", ")", ")", "elif", "padding", "==", "enums", ".", "PaddingMethod", ".", "PKCS1v15", ":", "signature", "=", "key", ".", "sign", "(", "data", ",", "padding_method", "(", ")", ",", "hash_alg", "(", ")", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"Padding method '{0}' is not a supported signature \"", "\"padding method.\"", ".", "format", "(", "padding", ")", ")", "return", "signature" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
CryptographyEngine.verify_signature
Verify a message signature. Args: signing_key (bytes): The bytes of the signing key to use for signature verification. Required. message (bytes): The bytes of the message that corresponds with the signature. Required. signature (bytes): The bytes of the signature to be verified. Required. padding_method (PaddingMethod): An enumeration specifying the padding method to use during signature verification. Required. signing_algorithm (CryptographicAlgorithm): An enumeration specifying the cryptographic algorithm to use for signature verification. Only RSA is supported. Optional, must match the algorithm specified by the digital signature algorithm if both are provided. Defaults to None. hashing_algorithm (HashingAlgorithm): An enumeration specifying the hashing algorithm to use with the cryptographic algortihm, if needed. Optional, must match the algorithm specified by the digital signature algorithm if both are provided. Defaults to None. digital_signature_algorithm (DigitalSignatureAlgorithm): An enumeration specifying both the cryptographic and hashing algorithms to use for signature verification. Optional, must match the cryptographic and hashing algorithms if both are provided. Defaults to None. Returns: boolean: the result of signature verification, True for valid signatures, False for invalid signatures Raises: InvalidField: Raised when various settings or values are invalid. CryptographicFailure: Raised when the signing key bytes cannot be loaded, or when the signature verification process fails unexpectedly.
kmip/services/server/crypto/engine.py
def verify_signature(self, signing_key, message, signature, padding_method, signing_algorithm=None, hashing_algorithm=None, digital_signature_algorithm=None): """ Verify a message signature. Args: signing_key (bytes): The bytes of the signing key to use for signature verification. Required. message (bytes): The bytes of the message that corresponds with the signature. Required. signature (bytes): The bytes of the signature to be verified. Required. padding_method (PaddingMethod): An enumeration specifying the padding method to use during signature verification. Required. signing_algorithm (CryptographicAlgorithm): An enumeration specifying the cryptographic algorithm to use for signature verification. Only RSA is supported. Optional, must match the algorithm specified by the digital signature algorithm if both are provided. Defaults to None. hashing_algorithm (HashingAlgorithm): An enumeration specifying the hashing algorithm to use with the cryptographic algortihm, if needed. Optional, must match the algorithm specified by the digital signature algorithm if both are provided. Defaults to None. digital_signature_algorithm (DigitalSignatureAlgorithm): An enumeration specifying both the cryptographic and hashing algorithms to use for signature verification. Optional, must match the cryptographic and hashing algorithms if both are provided. Defaults to None. Returns: boolean: the result of signature verification, True for valid signatures, False for invalid signatures Raises: InvalidField: Raised when various settings or values are invalid. CryptographicFailure: Raised when the signing key bytes cannot be loaded, or when the signature verification process fails unexpectedly. """ backend = default_backend() hash_algorithm = None dsa_hash_algorithm = None dsa_signing_algorithm = None if hashing_algorithm: hash_algorithm = self._encryption_hash_algorithms.get( hashing_algorithm ) if digital_signature_algorithm: algorithm_pair = self._digital_signature_algorithms.get( digital_signature_algorithm ) if algorithm_pair: dsa_hash_algorithm = algorithm_pair[0] dsa_signing_algorithm = algorithm_pair[1] if dsa_hash_algorithm and dsa_signing_algorithm: if hash_algorithm and (hash_algorithm != dsa_hash_algorithm): raise exceptions.InvalidField( "The hashing algorithm does not match the digital " "signature algorithm." ) if (signing_algorithm and (signing_algorithm != dsa_signing_algorithm)): raise exceptions.InvalidField( "The signing algorithm does not match the digital " "signature algorithm." ) signing_algorithm = dsa_signing_algorithm hash_algorithm = dsa_hash_algorithm if signing_algorithm == enums.CryptographicAlgorithm.RSA: if padding_method == enums.PaddingMethod.PSS: if hash_algorithm: padding = asymmetric_padding.PSS( mgf=asymmetric_padding.MGF1(hash_algorithm()), salt_length=asymmetric_padding.PSS.MAX_LENGTH ) else: raise exceptions.InvalidField( "A hashing algorithm must be specified for PSS " "padding." ) elif padding_method == enums.PaddingMethod.PKCS1v15: padding = asymmetric_padding.PKCS1v15() else: raise exceptions.InvalidField( "The padding method '{0}' is not supported for signature " "verification.".format(padding_method) ) try: public_key = backend.load_der_public_key(signing_key) except Exception: try: public_key = backend.load_pem_public_key(signing_key) except Exception: raise exceptions.CryptographicFailure( "The signing key bytes could not be loaded." ) try: public_key.verify( signature, message, padding, hash_algorithm() ) return True except errors.InvalidSignature: return False except Exception: raise exceptions.CryptographicFailure( "The signature verification process failed." ) else: raise exceptions.InvalidField( "The signing algorithm '{0}' is not supported for " "signature verification.".format(signing_algorithm) )
def verify_signature(self, signing_key, message, signature, padding_method, signing_algorithm=None, hashing_algorithm=None, digital_signature_algorithm=None): """ Verify a message signature. Args: signing_key (bytes): The bytes of the signing key to use for signature verification. Required. message (bytes): The bytes of the message that corresponds with the signature. Required. signature (bytes): The bytes of the signature to be verified. Required. padding_method (PaddingMethod): An enumeration specifying the padding method to use during signature verification. Required. signing_algorithm (CryptographicAlgorithm): An enumeration specifying the cryptographic algorithm to use for signature verification. Only RSA is supported. Optional, must match the algorithm specified by the digital signature algorithm if both are provided. Defaults to None. hashing_algorithm (HashingAlgorithm): An enumeration specifying the hashing algorithm to use with the cryptographic algortihm, if needed. Optional, must match the algorithm specified by the digital signature algorithm if both are provided. Defaults to None. digital_signature_algorithm (DigitalSignatureAlgorithm): An enumeration specifying both the cryptographic and hashing algorithms to use for signature verification. Optional, must match the cryptographic and hashing algorithms if both are provided. Defaults to None. Returns: boolean: the result of signature verification, True for valid signatures, False for invalid signatures Raises: InvalidField: Raised when various settings or values are invalid. CryptographicFailure: Raised when the signing key bytes cannot be loaded, or when the signature verification process fails unexpectedly. """ backend = default_backend() hash_algorithm = None dsa_hash_algorithm = None dsa_signing_algorithm = None if hashing_algorithm: hash_algorithm = self._encryption_hash_algorithms.get( hashing_algorithm ) if digital_signature_algorithm: algorithm_pair = self._digital_signature_algorithms.get( digital_signature_algorithm ) if algorithm_pair: dsa_hash_algorithm = algorithm_pair[0] dsa_signing_algorithm = algorithm_pair[1] if dsa_hash_algorithm and dsa_signing_algorithm: if hash_algorithm and (hash_algorithm != dsa_hash_algorithm): raise exceptions.InvalidField( "The hashing algorithm does not match the digital " "signature algorithm." ) if (signing_algorithm and (signing_algorithm != dsa_signing_algorithm)): raise exceptions.InvalidField( "The signing algorithm does not match the digital " "signature algorithm." ) signing_algorithm = dsa_signing_algorithm hash_algorithm = dsa_hash_algorithm if signing_algorithm == enums.CryptographicAlgorithm.RSA: if padding_method == enums.PaddingMethod.PSS: if hash_algorithm: padding = asymmetric_padding.PSS( mgf=asymmetric_padding.MGF1(hash_algorithm()), salt_length=asymmetric_padding.PSS.MAX_LENGTH ) else: raise exceptions.InvalidField( "A hashing algorithm must be specified for PSS " "padding." ) elif padding_method == enums.PaddingMethod.PKCS1v15: padding = asymmetric_padding.PKCS1v15() else: raise exceptions.InvalidField( "The padding method '{0}' is not supported for signature " "verification.".format(padding_method) ) try: public_key = backend.load_der_public_key(signing_key) except Exception: try: public_key = backend.load_pem_public_key(signing_key) except Exception: raise exceptions.CryptographicFailure( "The signing key bytes could not be loaded." ) try: public_key.verify( signature, message, padding, hash_algorithm() ) return True except errors.InvalidSignature: return False except Exception: raise exceptions.CryptographicFailure( "The signature verification process failed." ) else: raise exceptions.InvalidField( "The signing algorithm '{0}' is not supported for " "signature verification.".format(signing_algorithm) )
[ "Verify", "a", "message", "signature", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/crypto/engine.py#L1313-L1441
[ "def", "verify_signature", "(", "self", ",", "signing_key", ",", "message", ",", "signature", ",", "padding_method", ",", "signing_algorithm", "=", "None", ",", "hashing_algorithm", "=", "None", ",", "digital_signature_algorithm", "=", "None", ")", ":", "backend", "=", "default_backend", "(", ")", "hash_algorithm", "=", "None", "dsa_hash_algorithm", "=", "None", "dsa_signing_algorithm", "=", "None", "if", "hashing_algorithm", ":", "hash_algorithm", "=", "self", ".", "_encryption_hash_algorithms", ".", "get", "(", "hashing_algorithm", ")", "if", "digital_signature_algorithm", ":", "algorithm_pair", "=", "self", ".", "_digital_signature_algorithms", ".", "get", "(", "digital_signature_algorithm", ")", "if", "algorithm_pair", ":", "dsa_hash_algorithm", "=", "algorithm_pair", "[", "0", "]", "dsa_signing_algorithm", "=", "algorithm_pair", "[", "1", "]", "if", "dsa_hash_algorithm", "and", "dsa_signing_algorithm", ":", "if", "hash_algorithm", "and", "(", "hash_algorithm", "!=", "dsa_hash_algorithm", ")", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The hashing algorithm does not match the digital \"", "\"signature algorithm.\"", ")", "if", "(", "signing_algorithm", "and", "(", "signing_algorithm", "!=", "dsa_signing_algorithm", ")", ")", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The signing algorithm does not match the digital \"", "\"signature algorithm.\"", ")", "signing_algorithm", "=", "dsa_signing_algorithm", "hash_algorithm", "=", "dsa_hash_algorithm", "if", "signing_algorithm", "==", "enums", ".", "CryptographicAlgorithm", ".", "RSA", ":", "if", "padding_method", "==", "enums", ".", "PaddingMethod", ".", "PSS", ":", "if", "hash_algorithm", ":", "padding", "=", "asymmetric_padding", ".", "PSS", "(", "mgf", "=", "asymmetric_padding", ".", "MGF1", "(", "hash_algorithm", "(", ")", ")", ",", "salt_length", "=", "asymmetric_padding", ".", "PSS", ".", "MAX_LENGTH", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"A hashing algorithm must be specified for PSS \"", "\"padding.\"", ")", "elif", "padding_method", "==", "enums", ".", "PaddingMethod", ".", "PKCS1v15", ":", "padding", "=", "asymmetric_padding", ".", "PKCS1v15", "(", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The padding method '{0}' is not supported for signature \"", "\"verification.\"", ".", "format", "(", "padding_method", ")", ")", "try", ":", "public_key", "=", "backend", ".", "load_der_public_key", "(", "signing_key", ")", "except", "Exception", ":", "try", ":", "public_key", "=", "backend", ".", "load_pem_public_key", "(", "signing_key", ")", "except", "Exception", ":", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"The signing key bytes could not be loaded.\"", ")", "try", ":", "public_key", ".", "verify", "(", "signature", ",", "message", ",", "padding", ",", "hash_algorithm", "(", ")", ")", "return", "True", "except", "errors", ".", "InvalidSignature", ":", "return", "False", "except", "Exception", ":", "raise", "exceptions", ".", "CryptographicFailure", "(", "\"The signature verification process failed.\"", ")", "else", ":", "raise", "exceptions", ".", "InvalidField", "(", "\"The signing algorithm '{0}' is not supported for \"", "\"signature verification.\"", ".", "format", "(", "signing_algorithm", ")", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
SignResponsePayload.read
Read the data encoding the Sign response payload and decode it. 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 or signature attributes are missing from the encoded payload.
kmip/core/messages/payloads/sign.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Sign response payload and decode it. 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 or signature attributes are missing from the encoded payload. """ super(SignResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "invalid payload missing the unique identifier attribute" ) if self.is_tag_next(enums.Tags.SIGNATURE_DATA, local_stream): self._signature_data = primitives.ByteString( tag=enums.Tags.SIGNATURE_DATA ) self._signature_data.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "invalid payload missing the signature data attribute" )
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Sign response payload and decode it. 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 or signature attributes are missing from the encoded payload. """ super(SignResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "invalid payload missing the unique identifier attribute" ) if self.is_tag_next(enums.Tags.SIGNATURE_DATA, local_stream): self._signature_data = primitives.ByteString( tag=enums.Tags.SIGNATURE_DATA ) self._signature_data.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "invalid payload missing the signature data attribute" )
[ "Read", "the", "data", "encoding", "the", "Sign", "response", "payload", "and", "decode", "it", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/sign.py#L311-L355
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "SignResponsePayload", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "utils", ".", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "self", ".", "_unique_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"invalid payload missing the unique identifier attribute\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "SIGNATURE_DATA", ",", "local_stream", ")", ":", "self", ".", "_signature_data", "=", "primitives", ".", "ByteString", "(", "tag", "=", "enums", ".", "Tags", ".", "SIGNATURE_DATA", ")", "self", ".", "_signature_data", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"invalid payload missing the signature data attribute\"", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
SignResponsePayload.write
Write the data encoding the Sign response to a stream. Args: output_stream (stream): A data stream in which to encode object data, supporting a write method; usually a BytearrayStream object. Raises: ValueError: Raised if the unique_identifier or signature attributes are not defined.
kmip/core/messages/payloads/sign.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Sign response to a stream. Args: output_stream (stream): A data stream in which to encode object data, supporting a write method; usually a BytearrayStream object. Raises: ValueError: Raised if the unique_identifier or signature attributes are not defined. """ local_stream = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "invalid payload missing the unique identifier attribute" ) if self._signature_data: self._signature_data.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "invalid payload missing the signature attribute" ) self.length = local_stream.length() super(SignResponsePayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Sign response to a stream. Args: output_stream (stream): A data stream in which to encode object data, supporting a write method; usually a BytearrayStream object. Raises: ValueError: Raised if the unique_identifier or signature attributes are not defined. """ local_stream = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "invalid payload missing the unique identifier attribute" ) if self._signature_data: self._signature_data.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "invalid payload missing the signature attribute" ) self.length = local_stream.length() super(SignResponsePayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "Sign", "response", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/sign.py#L357-L398
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_unique_identifier", ":", "self", ".", "_unique_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"invalid payload missing the unique identifier attribute\"", ")", "if", "self", ".", "_signature_data", ":", "self", ".", "_signature_data", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"invalid payload missing the signature attribute\"", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "SignResponsePayload", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
GetUsageAllocationRequestPayload.read
Read the data encoding the GetUsageAllocation 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload.
kmip/core/messages/payloads/get_usage_allocation.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the GetUsageAllocation 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(GetUsageAllocationRequestPayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.USAGE_LIMITS_COUNT, local_stream): self._usage_limits_count = primitives.LongInteger( tag=enums.Tags.USAGE_LIMITS_COUNT ) self._usage_limits_count.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the GetUsageAllocation 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(GetUsageAllocationRequestPayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) if self.is_tag_next(enums.Tags.USAGE_LIMITS_COUNT, local_stream): self._usage_limits_count = primitives.LongInteger( tag=enums.Tags.USAGE_LIMITS_COUNT ) self._usage_limits_count.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "GetUsageAllocation", "request", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/get_usage_allocation.py#L93-L133
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "GetUsageAllocationRequestPayload", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "utils", ".", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "self", ".", "_unique_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "USAGE_LIMITS_COUNT", ",", "local_stream", ")", ":", "self", ".", "_usage_limits_count", "=", "primitives", ".", "LongInteger", "(", "tag", "=", "enums", ".", "Tags", ".", "USAGE_LIMITS_COUNT", ")", "self", ".", "_usage_limits_count", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
protocol_version_to_kmip_version
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.
kmip/core/messages/contents.py
def protocol_version_to_kmip_version(value): """ 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. """ if not isinstance(value, ProtocolVersion): return None if value.major == 1: if value.minor == 0: return enums.KMIPVersion.KMIP_1_0 elif value.minor == 1: return enums.KMIPVersion.KMIP_1_1 elif value.minor == 2: return enums.KMIPVersion.KMIP_1_2 elif value.minor == 3: return enums.KMIPVersion.KMIP_1_3 elif value.minor == 4: return enums.KMIPVersion.KMIP_1_4 else: return None else: return None
def protocol_version_to_kmip_version(value): """ 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. """ if not isinstance(value, ProtocolVersion): return None if value.major == 1: if value.minor == 0: return enums.KMIPVersion.KMIP_1_0 elif value.minor == 1: return enums.KMIPVersion.KMIP_1_1 elif value.minor == 2: return enums.KMIPVersion.KMIP_1_2 elif value.minor == 3: return enums.KMIPVersion.KMIP_1_3 elif value.minor == 4: return enums.KMIPVersion.KMIP_1_4 else: return None else: return None
[ "Convert", "a", "ProtocolVersion", "struct", "to", "its", "KMIPVersion", "enumeration", "equivalent", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/contents.py#L252-L281
[ "def", "protocol_version_to_kmip_version", "(", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "ProtocolVersion", ")", ":", "return", "None", "if", "value", ".", "major", "==", "1", ":", "if", "value", ".", "minor", "==", "0", ":", "return", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", "elif", "value", ".", "minor", "==", "1", ":", "return", "enums", ".", "KMIPVersion", ".", "KMIP_1_1", "elif", "value", ".", "minor", "==", "2", ":", "return", "enums", ".", "KMIPVersion", ".", "KMIP_1_2", "elif", "value", ".", "minor", "==", "3", ":", "return", "enums", ".", "KMIPVersion", ".", "KMIP_1_3", "elif", "value", ".", "minor", "==", "4", ":", "return", "enums", ".", "KMIPVersion", ".", "KMIP_1_4", "else", ":", "return", "None", "else", ":", "return", "None" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ProtocolVersion.read
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.
kmip/core/messages/contents.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ super(ProtocolVersion, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MAJOR, local_stream): self._major = primitives.Integer( tag=enums.Tags.PROTOCOL_VERSION_MAJOR ) self._major.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Invalid encoding missing the major protocol version number." ) if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MINOR, local_stream): self._minor = primitives.Integer( tag=enums.Tags.PROTOCOL_VERSION_MINOR ) self._minor.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Invalid encoding missing the minor protocol version number." ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ super(ProtocolVersion, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MAJOR, local_stream): self._major = primitives.Integer( tag=enums.Tags.PROTOCOL_VERSION_MAJOR ) self._major.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Invalid encoding missing the major protocol version number." ) if self.is_tag_next(enums.Tags.PROTOCOL_VERSION_MINOR, local_stream): self._minor = primitives.Integer( tag=enums.Tags.PROTOCOL_VERSION_MINOR ) self._minor.read(local_stream, kmip_version=kmip_version) else: raise ValueError( "Invalid encoding missing the minor protocol version number." ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "ProtocolVersion", "struct", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/contents.py#L101-L144
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "ProtocolVersion", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "utils", ".", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "PROTOCOL_VERSION_MAJOR", ",", "local_stream", ")", ":", "self", ".", "_major", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "PROTOCOL_VERSION_MAJOR", ")", "self", ".", "_major", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid encoding missing the major protocol version number.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "PROTOCOL_VERSION_MINOR", ",", "local_stream", ")", ":", "self", ".", "_minor", "=", "primitives", ".", "Integer", "(", "tag", "=", "enums", ".", "Tags", ".", "PROTOCOL_VERSION_MINOR", ")", "self", ".", "_minor", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid encoding missing the minor protocol version number.\"", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ProtocolVersion.write
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.
kmip/core/messages/contents.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if self._major: self._major.write(local_stream, kmip_version=kmip_version) else: raise ValueError( "Invalid struct missing the major protocol version number." ) if self._minor: self._minor.write(local_stream, kmip_version=kmip_version) else: raise ValueError( "Invalid struct missing the minor protocol version number." ) self.length = local_stream.length() super(ProtocolVersion, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if self._major: self._major.write(local_stream, kmip_version=kmip_version) else: raise ValueError( "Invalid struct missing the major protocol version number." ) if self._minor: self._minor.write(local_stream, kmip_version=kmip_version) else: raise ValueError( "Invalid struct missing the minor protocol version number." ) self.length = local_stream.length() super(ProtocolVersion, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "ProtocolVersion", "struct", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/contents.py#L146-L182
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_major", ":", "self", ".", "_major", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid struct missing the major protocol version number.\"", ")", "if", "self", ".", "_minor", ":", "self", ".", "_minor", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"Invalid struct missing the minor protocol version number.\"", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "ProtocolVersion", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Authentication.read
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.
kmip/core/messages/contents.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ super(Authentication, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) credentials = [] while self.is_tag_next(enums.Tags.CREDENTIAL, local_stream): credential = objects.Credential() credential.read(local_stream, kmip_version=kmip_version) credentials.append(credential) if len(credentials) == 0: raise ValueError("Authentication encoding missing credentials.") self._credentials = credentials self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ super(Authentication, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) credentials = [] while self.is_tag_next(enums.Tags.CREDENTIAL, local_stream): credential = objects.Credential() credential.read(local_stream, kmip_version=kmip_version) credentials.append(credential) if len(credentials) == 0: raise ValueError("Authentication encoding missing credentials.") self._credentials = credentials self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "Authentication", "struct", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/contents.py#L358-L386
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "Authentication", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "utils", ".", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "credentials", "=", "[", "]", "while", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "CREDENTIAL", ",", "local_stream", ")", ":", "credential", "=", "objects", ".", "Credential", "(", ")", "credential", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "credentials", ".", "append", "(", "credential", ")", "if", "len", "(", "credentials", ")", "==", "0", ":", "raise", "ValueError", "(", "\"Authentication encoding missing credentials.\"", ")", "self", ".", "_credentials", "=", "credentials", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Authentication.write
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.
kmip/core/messages/contents.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if len(self._credentials) == 0: raise ValueError("Authentication struct missing credentials.") for credential in self._credentials: credential.write(local_stream, kmip_version=kmip_version) self.length = local_stream.length() super(Authentication, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if len(self._credentials) == 0: raise ValueError("Authentication struct missing credentials.") for credential in self._credentials: credential.write(local_stream, kmip_version=kmip_version) self.length = local_stream.length() super(Authentication, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "Authentication", "struct", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/contents.py#L388-L412
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "len", "(", "self", ".", "_credentials", ")", "==", "0", ":", "raise", "ValueError", "(", "\"Authentication struct missing credentials.\"", ")", "for", "credential", "in", "self", ".", "_credentials", ":", "credential", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "Authentication", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
PollRequestPayload.read
Read the data encoding the Poll 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload.
kmip/core/messages/payloads/poll.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Poll 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(PollRequestPayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next( enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE, local_stream ): self._asynchronous_correlation_value = primitives.ByteString( tag=enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE ) self._asynchronous_correlation_value.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Poll 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. Raises: ValueError: Raised if the data attribute is missing from the encoded payload. """ super(PollRequestPayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next( enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE, local_stream ): self._asynchronous_correlation_value = primitives.ByteString( tag=enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE ) self._asynchronous_correlation_value.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "Poll", "request", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/poll.py#L67-L102
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "PollRequestPayload", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "utils", ".", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "ASYNCHRONOUS_CORRELATION_VALUE", ",", "local_stream", ")", ":", "self", ".", "_asynchronous_correlation_value", "=", "primitives", ".", "ByteString", "(", "tag", "=", "enums", ".", "Tags", ".", "ASYNCHRONOUS_CORRELATION_VALUE", ")", "self", ".", "_asynchronous_correlation_value", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Certificate.read
Read the data encoding the Certificate 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.
kmip/core/secrets.py
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Certificate 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. """ super(Certificate, self).read(istream, kmip_version=kmip_version) tstream = BytearrayStream(istream.read(self.length)) self.certificate_type = CertificateType() self.certificate_value = CertificateValue() self.certificate_type.read(tstream, kmip_version=kmip_version) self.certificate_value.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream)
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Certificate 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. """ super(Certificate, self).read(istream, kmip_version=kmip_version) tstream = BytearrayStream(istream.read(self.length)) self.certificate_type = CertificateType() self.certificate_value = CertificateValue() self.certificate_type.read(tstream, kmip_version=kmip_version) self.certificate_value.read(tstream, kmip_version=kmip_version) self.is_oversized(tstream)
[ "Read", "the", "data", "encoding", "the", "Certificate", "object", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/secrets.py#L72-L93
[ "def", "read", "(", "self", ",", "istream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "Certificate", ",", "self", ")", ".", "read", "(", "istream", ",", "kmip_version", "=", "kmip_version", ")", "tstream", "=", "BytearrayStream", "(", "istream", ".", "read", "(", "self", ".", "length", ")", ")", "self", ".", "certificate_type", "=", "CertificateType", "(", ")", "self", ".", "certificate_value", "=", "CertificateValue", "(", ")", "self", ".", "certificate_type", ".", "read", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "certificate_value", ".", "read", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "tstream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
Certificate.write
Write the data encoding the Certificate 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.
kmip/core/secrets.py
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Certificate 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. """ tstream = BytearrayStream() self.certificate_type.write(tstream, kmip_version=kmip_version) self.certificate_value.write(tstream, kmip_version=kmip_version) self.length = tstream.length() super(Certificate, self).write(ostream, kmip_version=kmip_version) ostream.write(tstream.buffer)
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Certificate 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. """ tstream = BytearrayStream() self.certificate_type.write(tstream, kmip_version=kmip_version) self.certificate_value.write(tstream, kmip_version=kmip_version) self.length = tstream.length() super(Certificate, self).write(ostream, kmip_version=kmip_version) ostream.write(tstream.buffer)
[ "Write", "the", "data", "encoding", "the", "Certificate", "object", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/secrets.py#L95-L113
[ "def", "write", "(", "self", ",", "ostream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "tstream", "=", "BytearrayStream", "(", ")", "self", ".", "certificate_type", ".", "write", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "certificate_value", ".", "write", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "tstream", ".", "length", "(", ")", "super", "(", "Certificate", ",", "self", ")", ".", "write", "(", "ostream", ",", "kmip_version", "=", "kmip_version", ")", "ostream", ".", "write", "(", "tstream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
SLUGSConnector.authenticate
Query the configured SLUGS service with the provided credentials. Args: connection_certificate (cryptography.x509.Certificate): An X.509 certificate object obtained from the connection being authenticated. Required for SLUGS authentication. connection_info (tuple): A tuple of information pertaining to the connection being authenticated, including the source IP address and a timestamp (e.g., ('127.0.0.1', 1519759267.467451)). Optional, defaults to None. Ignored for SLUGS authentication. request_credentials (list): A list of KMIP Credential structures containing credential information to use for authentication. Optional, defaults to None. Ignored for SLUGS authentication.
kmip/services/server/auth/slugs.py
def authenticate(self, connection_certificate=None, connection_info=None, request_credentials=None): """ Query the configured SLUGS service with the provided credentials. Args: connection_certificate (cryptography.x509.Certificate): An X.509 certificate object obtained from the connection being authenticated. Required for SLUGS authentication. connection_info (tuple): A tuple of information pertaining to the connection being authenticated, including the source IP address and a timestamp (e.g., ('127.0.0.1', 1519759267.467451)). Optional, defaults to None. Ignored for SLUGS authentication. request_credentials (list): A list of KMIP Credential structures containing credential information to use for authentication. Optional, defaults to None. Ignored for SLUGS authentication. """ if (self.users_url is None) or (self.groups_url is None): raise exceptions.ConfigurationError( "The SLUGS URL must be specified." ) user_id = utils.get_client_identity_from_certificate( connection_certificate ) try: response = requests.get(self.users_url.format(user_id)) except Exception: raise exceptions.ConfigurationError( "A connection could not be established using the SLUGS URL." ) if response.status_code == 404: raise exceptions.PermissionDenied( "Unrecognized user ID: {}".format(user_id) ) response = requests.get(self.groups_url.format(user_id)) if response.status_code == 404: raise exceptions.PermissionDenied( "Group information could not be retrieved for user ID: " "{}".format(user_id) ) return user_id, response.json().get('groups')
def authenticate(self, connection_certificate=None, connection_info=None, request_credentials=None): """ Query the configured SLUGS service with the provided credentials. Args: connection_certificate (cryptography.x509.Certificate): An X.509 certificate object obtained from the connection being authenticated. Required for SLUGS authentication. connection_info (tuple): A tuple of information pertaining to the connection being authenticated, including the source IP address and a timestamp (e.g., ('127.0.0.1', 1519759267.467451)). Optional, defaults to None. Ignored for SLUGS authentication. request_credentials (list): A list of KMIP Credential structures containing credential information to use for authentication. Optional, defaults to None. Ignored for SLUGS authentication. """ if (self.users_url is None) or (self.groups_url is None): raise exceptions.ConfigurationError( "The SLUGS URL must be specified." ) user_id = utils.get_client_identity_from_certificate( connection_certificate ) try: response = requests.get(self.users_url.format(user_id)) except Exception: raise exceptions.ConfigurationError( "A connection could not be established using the SLUGS URL." ) if response.status_code == 404: raise exceptions.PermissionDenied( "Unrecognized user ID: {}".format(user_id) ) response = requests.get(self.groups_url.format(user_id)) if response.status_code == 404: raise exceptions.PermissionDenied( "Group information could not be retrieved for user ID: " "{}".format(user_id) ) return user_id, response.json().get('groups')
[ "Query", "the", "configured", "SLUGS", "service", "with", "the", "provided", "credentials", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/auth/slugs.py#L62-L108
[ "def", "authenticate", "(", "self", ",", "connection_certificate", "=", "None", ",", "connection_info", "=", "None", ",", "request_credentials", "=", "None", ")", ":", "if", "(", "self", ".", "users_url", "is", "None", ")", "or", "(", "self", ".", "groups_url", "is", "None", ")", ":", "raise", "exceptions", ".", "ConfigurationError", "(", "\"The SLUGS URL must be specified.\"", ")", "user_id", "=", "utils", ".", "get_client_identity_from_certificate", "(", "connection_certificate", ")", "try", ":", "response", "=", "requests", ".", "get", "(", "self", ".", "users_url", ".", "format", "(", "user_id", ")", ")", "except", "Exception", ":", "raise", "exceptions", ".", "ConfigurationError", "(", "\"A connection could not be established using the SLUGS URL.\"", ")", "if", "response", ".", "status_code", "==", "404", ":", "raise", "exceptions", ".", "PermissionDenied", "(", "\"Unrecognized user ID: {}\"", ".", "format", "(", "user_id", ")", ")", "response", "=", "requests", ".", "get", "(", "self", ".", "groups_url", ".", "format", "(", "user_id", ")", ")", "if", "response", ".", "status_code", "==", "404", ":", "raise", "exceptions", ".", "PermissionDenied", "(", "\"Group information could not be retrieved for user ID: \"", "\"{}\"", ".", "format", "(", "user_id", ")", ")", "return", "user_id", ",", "response", ".", "json", "(", ")", ".", "get", "(", "'groups'", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ArchiveResponsePayload.read
Read the data encoding the Archive 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 data attribute is missing from the encoded payload.
kmip/core/messages/payloads/archive.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Archive 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 data attribute is missing from the encoded payload. """ super(ArchiveResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Read the data encoding the Archive 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 data attribute is missing from the encoded payload. """ super(ArchiveResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "Archive", "response", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/archive.py#L196-L228
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "ArchiveResponsePayload", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "utils", ".", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "self", ".", "_unique_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ArchiveResponsePayload.write
Write the data encoding the Archive 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 decoded. Optional, defaults to KMIP 1.0. Raises: ValueError: Raised if the data attribute is not defined.
kmip/core/messages/payloads/archive.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Archive 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 decoded. Optional, defaults to KMIP 1.0. Raises: ValueError: Raised if the data attribute is not defined. """ local_stream = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(ArchiveResponsePayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ Write the data encoding the Archive 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 decoded. Optional, defaults to KMIP 1.0. Raises: ValueError: Raised if the data attribute is not defined. """ local_stream = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(ArchiveResponsePayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "Archive", "response", "payload", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/archive.py#L230-L258
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_unique_identifier", ":", "self", ".", "_unique_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "ArchiveResponsePayload", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KmipSession.run
The main thread routine executed by invoking thread.start. This method manages the new client connection, running a message handling loop. Once this method completes, the thread is finished.
kmip/services/server/session.py
def run(self): """ The main thread routine executed by invoking thread.start. This method manages the new client connection, running a message handling loop. Once this method completes, the thread is finished. """ self._logger.info("Starting session: {0}".format(self.name)) try: self._connection.do_handshake() except Exception as e: self._logger.info("Failure running TLS handshake") self._logger.exception(e) else: while True: try: self._handle_message_loop() except exceptions.ConnectionClosed as e: break except Exception as e: self._logger.info("Failure handling message loop") self._logger.exception(e) self._connection.shutdown(socket.SHUT_RDWR) self._connection.close() self._logger.info("Stopping session: {0}".format(self.name))
def run(self): """ The main thread routine executed by invoking thread.start. This method manages the new client connection, running a message handling loop. Once this method completes, the thread is finished. """ self._logger.info("Starting session: {0}".format(self.name)) try: self._connection.do_handshake() except Exception as e: self._logger.info("Failure running TLS handshake") self._logger.exception(e) else: while True: try: self._handle_message_loop() except exceptions.ConnectionClosed as e: break except Exception as e: self._logger.info("Failure handling message loop") self._logger.exception(e) self._connection.shutdown(socket.SHUT_RDWR) self._connection.close() self._logger.info("Stopping session: {0}".format(self.name))
[ "The", "main", "thread", "routine", "executed", "by", "invoking", "thread", ".", "start", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/session.py#L91-L117
[ "def", "run", "(", "self", ")", ":", "self", ".", "_logger", ".", "info", "(", "\"Starting session: {0}\"", ".", "format", "(", "self", ".", "name", ")", ")", "try", ":", "self", ".", "_connection", ".", "do_handshake", "(", ")", "except", "Exception", "as", "e", ":", "self", ".", "_logger", ".", "info", "(", "\"Failure running TLS handshake\"", ")", "self", ".", "_logger", ".", "exception", "(", "e", ")", "else", ":", "while", "True", ":", "try", ":", "self", ".", "_handle_message_loop", "(", ")", "except", "exceptions", ".", "ConnectionClosed", "as", "e", ":", "break", "except", "Exception", "as", "e", ":", "self", ".", "_logger", ".", "info", "(", "\"Failure handling message loop\"", ")", "self", ".", "_logger", ".", "exception", "(", "e", ")", "self", ".", "_connection", ".", "shutdown", "(", "socket", ".", "SHUT_RDWR", ")", "self", ".", "_connection", ".", "close", "(", ")", "self", ".", "_logger", ".", "info", "(", "\"Stopping session: {0}\"", ".", "format", "(", "self", ".", "name", ")", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
RekeyRequestPayload.write
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.
kmip/core/messages/payloads/rekey.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if self._unique_identifier is not None: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) if self._offset is not None: self._offset.write(local_stream, kmip_version=kmip_version) if self._template_attribute is not None: self._template_attribute.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(RekeyRequestPayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if self._unique_identifier is not None: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) if self._offset is not None: self._offset.write(local_stream, kmip_version=kmip_version) if self._template_attribute is not None: self._template_attribute.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(RekeyRequestPayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "Rekey", "request", "payload", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/rekey.py#L161-L193
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_unique_identifier", "is", "not", "None", ":", "self", ".", "_unique_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_offset", "is", "not", "None", ":", "self", ".", "_offset", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "if", "self", ".", "_template_attribute", "is", "not", "None", ":", "self", ".", "_template_attribute", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "RekeyRequestPayload", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
RekeyResponsePayload.read
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.
kmip/core/messages/payloads/rekey.py
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ super(RekeyResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "The Rekey response payload encoding is missing the unique " "identifier." ) if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_stream): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ super(RekeyResponsePayload, self).read( input_stream, kmip_version=kmip_version ) local_stream = utils.BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream): self._unique_identifier = primitives.TextString( tag=enums.Tags.UNIQUE_IDENTIFIER ) self._unique_identifier.read( local_stream, kmip_version=kmip_version ) else: raise ValueError( "The Rekey response payload encoding is missing the unique " "identifier." ) if self.is_tag_next(enums.Tags.TEMPLATE_ATTRIBUTE, local_stream): self._template_attribute = objects.TemplateAttribute() self._template_attribute.read( local_stream, kmip_version=kmip_version ) self.is_oversized(local_stream)
[ "Read", "the", "data", "encoding", "the", "Rekey", "response", "payload", "and", "decode", "it", "into", "its", "constituent", "parts", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/rekey.py#L300-L344
[ "def", "read", "(", "self", ",", "input_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "super", "(", "RekeyResponsePayload", ",", "self", ")", ".", "read", "(", "input_stream", ",", "kmip_version", "=", "kmip_version", ")", "local_stream", "=", "utils", ".", "BytearrayStream", "(", "input_stream", ".", "read", "(", "self", ".", "length", ")", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ",", "local_stream", ")", ":", "self", ".", "_unique_identifier", "=", "primitives", ".", "TextString", "(", "tag", "=", "enums", ".", "Tags", ".", "UNIQUE_IDENTIFIER", ")", "self", ".", "_unique_identifier", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"The Rekey response payload encoding is missing the unique \"", "\"identifier.\"", ")", "if", "self", ".", "is_tag_next", "(", "enums", ".", "Tags", ".", "TEMPLATE_ATTRIBUTE", ",", "local_stream", ")", ":", "self", ".", "_template_attribute", "=", "objects", ".", "TemplateAttribute", "(", ")", "self", ".", "_template_attribute", ".", "read", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "is_oversized", "(", "local_stream", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
RekeyResponsePayload.write
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.
kmip/core/messages/payloads/rekey.py
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if self._unique_identifier is not None: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "The Rekey response payload is missing the unique identifier." ) if self._template_attribute is not None: self._template_attribute.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(RekeyResponsePayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ local_stream = utils.BytearrayStream() if self._unique_identifier is not None: self._unique_identifier.write( local_stream, kmip_version=kmip_version ) else: raise ValueError( "The Rekey response payload is missing the unique identifier." ) if self._template_attribute is not None: self._template_attribute.write( local_stream, kmip_version=kmip_version ) self.length = local_stream.length() super(RekeyResponsePayload, self).write( output_stream, kmip_version=kmip_version ) output_stream.write(local_stream.buffer)
[ "Write", "the", "data", "encoding", "the", "Rekey", "request", "payload", "to", "a", "stream", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/rekey.py#L346-L383
[ "def", "write", "(", "self", ",", "output_stream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "local_stream", "=", "utils", ".", "BytearrayStream", "(", ")", "if", "self", ".", "_unique_identifier", "is", "not", "None", ":", "self", ".", "_unique_identifier", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "else", ":", "raise", "ValueError", "(", "\"The Rekey response payload is missing the unique identifier.\"", ")", "if", "self", ".", "_template_attribute", "is", "not", "None", ":", "self", ".", "_template_attribute", ".", "write", "(", "local_stream", ",", "kmip_version", "=", "kmip_version", ")", "self", ".", "length", "=", "local_stream", ".", "length", "(", ")", "super", "(", "RekeyResponsePayload", ",", "self", ")", ".", "write", "(", "output_stream", ",", "kmip_version", "=", "kmip_version", ")", "output_stream", ".", "write", "(", "local_stream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ActivateRequestPayload.write
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.
kmip/core/messages/payloads/activate.py
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ tstream = BytearrayStream() # Write the contents of the request payload if self.unique_identifier is not None: self.unique_identifier.write(tstream, kmip_version=kmip_version) # Write the length and value of the request payload self.length = tstream.length() super(ActivateRequestPayload, self).write( ostream, kmip_version=kmip_version ) ostream.write(tstream.buffer)
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0): """ 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. """ tstream = BytearrayStream() # Write the contents of the request payload if self.unique_identifier is not None: self.unique_identifier.write(tstream, kmip_version=kmip_version) # Write the length and value of the request payload self.length = tstream.length() super(ActivateRequestPayload, self).write( ostream, kmip_version=kmip_version ) ostream.write(tstream.buffer)
[ "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", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/activate.py#L71-L93
[ "def", "write", "(", "self", ",", "ostream", ",", "kmip_version", "=", "enums", ".", "KMIPVersion", ".", "KMIP_1_0", ")", ":", "tstream", "=", "BytearrayStream", "(", ")", "# Write the contents of the request payload", "if", "self", ".", "unique_identifier", "is", "not", "None", ":", "self", ".", "unique_identifier", ".", "write", "(", "tstream", ",", "kmip_version", "=", "kmip_version", ")", "# Write the length and value of the request payload", "self", ".", "length", "=", "tstream", ".", "length", "(", ")", "super", "(", "ActivateRequestPayload", ",", "self", ")", ".", "write", "(", "ostream", ",", "kmip_version", "=", "kmip_version", ")", "ostream", ".", "write", "(", "tstream", ".", "buffer", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
ActivateRequestPayload.validate
Error check the attributes of the ActivateRequestPayload object.
kmip/core/messages/payloads/activate.py
def validate(self): """ Error check the attributes of the ActivateRequestPayload object. """ if self.unique_identifier is not None: if not isinstance(self.unique_identifier, attributes.UniqueIdentifier): msg = "invalid unique identifier" raise TypeError(msg)
def validate(self): """ Error check the attributes of the ActivateRequestPayload object. """ if self.unique_identifier is not None: if not isinstance(self.unique_identifier, attributes.UniqueIdentifier): msg = "invalid unique identifier" raise TypeError(msg)
[ "Error", "check", "the", "attributes", "of", "the", "ActivateRequestPayload", "object", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/activate.py#L95-L103
[ "def", "validate", "(", "self", ")", ":", "if", "self", ".", "unique_identifier", "is", "not", "None", ":", "if", "not", "isinstance", "(", "self", ".", "unique_identifier", ",", "attributes", ".", "UniqueIdentifier", ")", ":", "msg", "=", "\"invalid unique identifier\"", "raise", "TypeError", "(", "msg", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KMIPProxy.kmip_version
Set the KMIP version for the client. Args: value (KMIPVersion): A KMIPVersion enumeration Return: None Raises: ValueError: if value is not a KMIPVersion enumeration Example: >>> client.kmip_version = enums.KMIPVersion.KMIP_1_1 >>>
kmip/services/kmip_client.py
def kmip_version(self, value): """ Set the KMIP version for the client. Args: value (KMIPVersion): A KMIPVersion enumeration Return: None Raises: ValueError: if value is not a KMIPVersion enumeration Example: >>> client.kmip_version = enums.KMIPVersion.KMIP_1_1 >>> """ if isinstance(value, enums.KMIPVersion): self._kmip_version = value else: raise ValueError("KMIP version must be a KMIPVersion enumeration")
def kmip_version(self, value): """ Set the KMIP version for the client. Args: value (KMIPVersion): A KMIPVersion enumeration Return: None Raises: ValueError: if value is not a KMIPVersion enumeration Example: >>> client.kmip_version = enums.KMIPVersion.KMIP_1_1 >>> """ if isinstance(value, enums.KMIPVersion): self._kmip_version = value else: raise ValueError("KMIP version must be a KMIPVersion enumeration")
[ "Set", "the", "KMIP", "version", "for", "the", "client", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/kmip_client.py#L133-L153
[ "def", "kmip_version", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "enums", ".", "KMIPVersion", ")", ":", "self", ".", "_kmip_version", "=", "value", "else", ":", "raise", "ValueError", "(", "\"KMIP version must be a KMIPVersion enumeration\"", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KMIPProxy.is_profile_supported
Check if a profile is supported by the client. Args: conformance_clause (ConformanceClause): authentication_suite (AuthenticationSuite): Returns: bool: True if the profile is supported, False otherwise. Example: >>> client.is_profile_supported( ... ConformanceClause.DISCOVER_VERSIONS, ... AuthenticationSuite.BASIC) True
kmip/services/kmip_client.py
def is_profile_supported(self, conformance_clause, authentication_suite): """ Check if a profile is supported by the client. Args: conformance_clause (ConformanceClause): authentication_suite (AuthenticationSuite): Returns: bool: True if the profile is supported, False otherwise. Example: >>> client.is_profile_supported( ... ConformanceClause.DISCOVER_VERSIONS, ... AuthenticationSuite.BASIC) True """ return (self.is_conformance_clause_supported(conformance_clause) and self.is_authentication_suite_supported(authentication_suite))
def is_profile_supported(self, conformance_clause, authentication_suite): """ Check if a profile is supported by the client. Args: conformance_clause (ConformanceClause): authentication_suite (AuthenticationSuite): Returns: bool: True if the profile is supported, False otherwise. Example: >>> client.is_profile_supported( ... ConformanceClause.DISCOVER_VERSIONS, ... AuthenticationSuite.BASIC) True """ return (self.is_conformance_clause_supported(conformance_clause) and self.is_authentication_suite_supported(authentication_suite))
[ "Check", "if", "a", "profile", "is", "supported", "by", "the", "client", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/kmip_client.py#L227-L245
[ "def", "is_profile_supported", "(", "self", ",", "conformance_clause", ",", "authentication_suite", ")", ":", "return", "(", "self", ".", "is_conformance_clause_supported", "(", "conformance_clause", ")", "and", "self", ".", "is_authentication_suite_supported", "(", "authentication_suite", ")", ")" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
test
KMIPProxy.rekey
Check object usage according to specific constraints. Args: uuid (string): The unique identifier of a managed cryptographic object that should be checked. Optional, defaults to None. offset (int): An integer specifying, in seconds, the difference between the rekeyed objects initialization date and activation date. Optional, defaults to None. template_attribute (TemplateAttribute): A TemplateAttribute struct containing the attributes to set on the newly rekeyed object. Optional, defaults to None. credential (Credential): A Credential struct containing a set of authorization parameters for the operation. Optional, defaults to None. Returns: dict: The results of the check operation, containing the following key/value pairs: Key | Value ---------------------------|----------------------------------- 'unique_identifier' | (string) The unique ID of the | checked cryptographic object. 'template_attribute' | (TemplateAttribute) A struct | containing attribute set by the | server. Optional. 'result_status' | (ResultStatus) An enumeration | indicating the status of the | operation result. 'result_reason' | (ResultReason) An enumeration | providing context for the result | status. 'result_message' | (string) A message providing | additional context for the | operation result.
kmip/services/kmip_client.py
def rekey(self, uuid=None, offset=None, template_attribute=None, credential=None): """ Check object usage according to specific constraints. Args: uuid (string): The unique identifier of a managed cryptographic object that should be checked. Optional, defaults to None. offset (int): An integer specifying, in seconds, the difference between the rekeyed objects initialization date and activation date. Optional, defaults to None. template_attribute (TemplateAttribute): A TemplateAttribute struct containing the attributes to set on the newly rekeyed object. Optional, defaults to None. credential (Credential): A Credential struct containing a set of authorization parameters for the operation. Optional, defaults to None. Returns: dict: The results of the check operation, containing the following key/value pairs: Key | Value ---------------------------|----------------------------------- 'unique_identifier' | (string) The unique ID of the | checked cryptographic object. 'template_attribute' | (TemplateAttribute) A struct | containing attribute set by the | server. Optional. 'result_status' | (ResultStatus) An enumeration | indicating the status of the | operation result. 'result_reason' | (ResultReason) An enumeration | providing context for the result | status. 'result_message' | (string) A message providing | additional context for the | operation result. """ operation = Operation(OperationEnum.REKEY) request_payload = payloads.RekeyRequestPayload( unique_identifier=uuid, offset=offset, template_attribute=template_attribute ) batch_item = messages.RequestBatchItem( operation=operation, request_payload=request_payload ) request = self._build_request_message(credential, [batch_item]) response = self._send_and_receive_message(request) batch_item = response.batch_items[0] payload = batch_item.response_payload result = {} if payload: result['unique_identifier'] = payload.unique_identifier if payload.template_attribute is not None: result['template_attribute'] = payload.template_attribute result['result_status'] = batch_item.result_status.value try: result['result_reason'] = batch_item.result_reason.value except Exception: result['result_reason'] = batch_item.result_reason try: result['result_message'] = batch_item.result_message.value except Exception: result['result_message'] = batch_item.result_message return result
def rekey(self, uuid=None, offset=None, template_attribute=None, credential=None): """ Check object usage according to specific constraints. Args: uuid (string): The unique identifier of a managed cryptographic object that should be checked. Optional, defaults to None. offset (int): An integer specifying, in seconds, the difference between the rekeyed objects initialization date and activation date. Optional, defaults to None. template_attribute (TemplateAttribute): A TemplateAttribute struct containing the attributes to set on the newly rekeyed object. Optional, defaults to None. credential (Credential): A Credential struct containing a set of authorization parameters for the operation. Optional, defaults to None. Returns: dict: The results of the check operation, containing the following key/value pairs: Key | Value ---------------------------|----------------------------------- 'unique_identifier' | (string) The unique ID of the | checked cryptographic object. 'template_attribute' | (TemplateAttribute) A struct | containing attribute set by the | server. Optional. 'result_status' | (ResultStatus) An enumeration | indicating the status of the | operation result. 'result_reason' | (ResultReason) An enumeration | providing context for the result | status. 'result_message' | (string) A message providing | additional context for the | operation result. """ operation = Operation(OperationEnum.REKEY) request_payload = payloads.RekeyRequestPayload( unique_identifier=uuid, offset=offset, template_attribute=template_attribute ) batch_item = messages.RequestBatchItem( operation=operation, request_payload=request_payload ) request = self._build_request_message(credential, [batch_item]) response = self._send_and_receive_message(request) batch_item = response.batch_items[0] payload = batch_item.response_payload result = {} if payload: result['unique_identifier'] = payload.unique_identifier if payload.template_attribute is not None: result['template_attribute'] = payload.template_attribute result['result_status'] = batch_item.result_status.value try: result['result_reason'] = batch_item.result_reason.value except Exception: result['result_reason'] = batch_item.result_reason try: result['result_message'] = batch_item.result_message.value except Exception: result['result_message'] = batch_item.result_message return result
[ "Check", "object", "usage", "according", "to", "specific", "constraints", "." ]
OpenKMIP/PyKMIP
python
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/kmip_client.py#L345-L421
[ "def", "rekey", "(", "self", ",", "uuid", "=", "None", ",", "offset", "=", "None", ",", "template_attribute", "=", "None", ",", "credential", "=", "None", ")", ":", "operation", "=", "Operation", "(", "OperationEnum", ".", "REKEY", ")", "request_payload", "=", "payloads", ".", "RekeyRequestPayload", "(", "unique_identifier", "=", "uuid", ",", "offset", "=", "offset", ",", "template_attribute", "=", "template_attribute", ")", "batch_item", "=", "messages", ".", "RequestBatchItem", "(", "operation", "=", "operation", ",", "request_payload", "=", "request_payload", ")", "request", "=", "self", ".", "_build_request_message", "(", "credential", ",", "[", "batch_item", "]", ")", "response", "=", "self", ".", "_send_and_receive_message", "(", "request", ")", "batch_item", "=", "response", ".", "batch_items", "[", "0", "]", "payload", "=", "batch_item", ".", "response_payload", "result", "=", "{", "}", "if", "payload", ":", "result", "[", "'unique_identifier'", "]", "=", "payload", ".", "unique_identifier", "if", "payload", ".", "template_attribute", "is", "not", "None", ":", "result", "[", "'template_attribute'", "]", "=", "payload", ".", "template_attribute", "result", "[", "'result_status'", "]", "=", "batch_item", ".", "result_status", ".", "value", "try", ":", "result", "[", "'result_reason'", "]", "=", "batch_item", ".", "result_reason", ".", "value", "except", "Exception", ":", "result", "[", "'result_reason'", "]", "=", "batch_item", ".", "result_reason", "try", ":", "result", "[", "'result_message'", "]", "=", "batch_item", ".", "result_message", ".", "value", "except", "Exception", ":", "result", "[", "'result_message'", "]", "=", "batch_item", ".", "result_message", "return", "result" ]
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e