2
0
mirror of https://github.com/openkmip/pykmip synced 2026-01-04 09:33:37 +00:00

Update object hierarchy read/write to support the KMIP version

This change updates the PyKMIP object hierarchy's read/write
method signatures to support propagation of the KMIP version. The
introduction of KMIP 2.0 introduces future KMIP message encodings
that break backwards compatibility; to support this, PyKMIP must
know what KMIP version is being used when encoding or decoding an
object; the KMIP version residing in the client or server alone
is now insufficient. Prior versions of KMIP, namely 1.0 - 1.4,
have been backwards compatible, obviating the need for the KMIP
version at encode/decode time. Going forward, this is no longer
true.

The PyKMIP client and server have been updated to include the
KMIP version when making calls to read/write, as have the
associated test cases covering this functionality.
This commit is contained in:
Peter Hamilton
2019-02-05 13:47:30 -05:00
committed by Peter Hamilton
parent c012a430aa
commit dcade2a264
40 changed files with 2527 additions and 946 deletions

View File

@@ -64,7 +64,7 @@ class PollRequestPayload(primitives.Struct):
else:
raise TypeError("Asynchronous correlation value must be bytes.")
def read(self, input_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.
@@ -73,12 +73,18 @@ class PollRequestPayload(primitives.Struct):
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)
super(PollRequestPayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(
@@ -88,11 +94,14 @@ class PollRequestPayload(primitives.Struct):
self._asynchronous_correlation_value = primitives.ByteString(
tag=enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE
)
self._asynchronous_correlation_value.read(local_stream)
self._asynchronous_correlation_value.read(
local_stream,
kmip_version=kmip_version
)
self.is_oversized(local_stream)
def write(self, output_stream):
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Poll request payload to a stream.
@@ -100,6 +109,9 @@ class PollRequestPayload(primitives.Struct):
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.
@@ -107,10 +119,16 @@ class PollRequestPayload(primitives.Struct):
local_stream = utils.BytearrayStream()
if self._asynchronous_correlation_value:
self._asynchronous_correlation_value.write(local_stream)
self._asynchronous_correlation_value.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(PollRequestPayload, self).write(output_stream)
super(PollRequestPayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
def __eq__(self, other):