mirror of
https://github.com/OpenKMIP/PyKMIP.git
synced 2025-07-19 20:14:27 +02:00
Enumerations are Unsigned Integers
Enumerations are to be encoded as four byte unsigned integers. They were previously being sent as signed integers. This caused failures when trying to transmit values that are extensions. Extensions contain the value 8 hex in the first nibble of the first byte.
This commit is contained in:
parent
537c25ff6d
commit
1d3a8e462a
@ -164,7 +164,7 @@ class Struct(Base):
|
|||||||
class Integer(Base):
|
class Integer(Base):
|
||||||
LENGTH = 4
|
LENGTH = 4
|
||||||
|
|
||||||
def __init__(self, value=None, tag=Tags.DEFAULT):
|
def __init__(self, value=None, tag=Tags.DEFAULT, signed=True):
|
||||||
super(Integer, self).__init__(tag, type=Types.INTEGER)
|
super(Integer, self).__init__(tag, type=Types.INTEGER)
|
||||||
|
|
||||||
self.value = value
|
self.value = value
|
||||||
@ -173,6 +173,10 @@ class Integer(Base):
|
|||||||
|
|
||||||
self.length = self.LENGTH
|
self.length = self.LENGTH
|
||||||
self.padding_length = self.LENGTH
|
self.padding_length = self.LENGTH
|
||||||
|
if signed:
|
||||||
|
self.pack_string = '!i'
|
||||||
|
else:
|
||||||
|
self.pack_string = '!I'
|
||||||
|
|
||||||
self.validate()
|
self.validate()
|
||||||
|
|
||||||
@ -181,8 +185,8 @@ class Integer(Base):
|
|||||||
raise errors.ReadValueError(Integer.__name__, 'length',
|
raise errors.ReadValueError(Integer.__name__, 'length',
|
||||||
self.LENGTH, self.length)
|
self.LENGTH, self.length)
|
||||||
|
|
||||||
self.value = unpack('!i', istream.read(self.length))[0]
|
self.value = unpack(self.pack_string, istream.read(self.length))[0]
|
||||||
pad = unpack('!i', istream.read(self.padding_length))[0]
|
pad = unpack(self.pack_string, istream.read(self.padding_length))[0]
|
||||||
|
|
||||||
if pad is not 0:
|
if pad is not 0:
|
||||||
raise errors.ReadValueError(Integer.__name__, 'pad', 0,
|
raise errors.ReadValueError(Integer.__name__, 'pad', 0,
|
||||||
@ -194,8 +198,8 @@ class Integer(Base):
|
|||||||
self.read_value(istream)
|
self.read_value(istream)
|
||||||
|
|
||||||
def write_value(self, ostream):
|
def write_value(self, ostream):
|
||||||
ostream.write(pack('!i', self.value))
|
ostream.write(pack(self.pack_string, self.value))
|
||||||
ostream.write(pack('!i', 0))
|
ostream.write(pack(self.pack_string, 0))
|
||||||
|
|
||||||
def write(self, ostream):
|
def write(self, ostream):
|
||||||
super(Integer, self).write(ostream)
|
super(Integer, self).write(ostream)
|
||||||
@ -393,9 +397,9 @@ class Enumeration(Integer):
|
|||||||
self.validate()
|
self.validate()
|
||||||
|
|
||||||
if self.enum is None:
|
if self.enum is None:
|
||||||
super(Enumeration, self).__init__(None, tag)
|
super(Enumeration, self).__init__(None, tag, False)
|
||||||
else:
|
else:
|
||||||
super(Enumeration, self).__init__(self.enum.value, tag)
|
super(Enumeration, self).__init__(self.enum.value, tag, False)
|
||||||
self.type = Types.ENUMERATION
|
self.type = Types.ENUMERATION
|
||||||
|
|
||||||
def read(self, istream):
|
def read(self, istream):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user