mirror of
https://github.com/openkmip/pykmip
synced 2025-12-16 08:13:56 +00:00
Block Attributes encoding and decoding on non KMIP 2.0 calls
This change adds a check to the read and write methods of the new Attributes object that raises a new VersionNotSupported exception if KMIP 2.0 is not the version used for encoding and decoding. The Attributes object is not defined for older versions of KMIP and therefore cannot be correctly encoded or decoded in those use cases.
This commit is contained in:
committed by
Peter Hamilton
parent
24f30d46b2
commit
54f3688a14
@@ -258,7 +258,16 @@ class Attributes(primitives.Struct):
|
||||
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))
|
||||
|
||||
@@ -297,7 +306,16 @@ class Attributes(primitives.Struct):
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user