mirror of https://github.com/OpenKMIP/PyKMIP.git
PyKMIP - Release v0.1.0
This change includes several new features to PyKMIP, including: * support for Python 3.3 and 3.4 * support for KMIP client/server SSL connections * removal of all Thrift library dependencies
This commit is contained in:
parent
f0e3c26170
commit
97ae864196
|
@ -1,4 +1,4 @@
|
||||||
include AUTHORS.txt CHANGES.txt LICENSE.txt README.txt
|
include AUTHORS.txt CHANGES.txt LICENSE.txt README.rst
|
||||||
global-include logconfig.ini
|
global-include logconfig.ini
|
||||||
recursive-include bin run_server.sh
|
recursive-include bin run_server.sh
|
||||||
recursive-include kmip *.py
|
recursive-include kmip *.py
|
||||||
|
|
|
@ -2,5 +2,4 @@
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
python ../kmip/demos/server.py
|
python3.3 ../kmip/demos/server.py
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import enums
|
from kmip.core import enums
|
||||||
|
|
||||||
from kmip.core.enums import Tags
|
from kmip.core.enums import Tags
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ from kmip.core.primitives import Integer
|
||||||
from kmip.core.primitives import Enumeration
|
from kmip.core.primitives import Enumeration
|
||||||
from kmip.core.primitives import TextString
|
from kmip.core.primitives import TextString
|
||||||
|
|
||||||
from utils import BytearrayStream
|
from kmip.core.utils import BytearrayStream
|
||||||
|
|
||||||
|
|
||||||
# 3.1
|
# 3.1
|
||||||
|
|
|
@ -23,7 +23,7 @@ class BaseError(Exception):
|
||||||
"""Base class for exceptions defined in this module."""
|
"""Base class for exceptions defined in this module."""
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
[setattr(self, k, v) for k, v in args.iteritems() if k is not 'self']
|
[setattr(self, k, v) for k, v in args.items() if k is not 'self']
|
||||||
|
|
||||||
|
|
||||||
class KMIPServerError(BaseError):
|
class KMIPServerError(BaseError):
|
||||||
|
|
|
@ -340,7 +340,7 @@ class RequestMessage(Struct):
|
||||||
self.request_header.read(istream)
|
self.request_header.read(istream)
|
||||||
|
|
||||||
self.batch_items = []
|
self.batch_items = []
|
||||||
for _ in xrange(self.request_header.batch_count.value):
|
for _ in range(self.request_header.batch_count.value):
|
||||||
batch_item = RequestBatchItem()
|
batch_item = RequestBatchItem()
|
||||||
batch_item.read(istream)
|
batch_item.read(istream)
|
||||||
self.batch_items.append(batch_item)
|
self.batch_items.append(batch_item)
|
||||||
|
@ -374,7 +374,7 @@ class ResponseMessage(Struct):
|
||||||
self.response_header.read(istream)
|
self.response_header.read(istream)
|
||||||
|
|
||||||
self.batch_items = []
|
self.batch_items = []
|
||||||
for _ in xrange(self.response_header.batch_count.value):
|
for _ in range(self.response_header.batch_count.value):
|
||||||
batch_item = ResponseBatchItem()
|
batch_item = ResponseBatchItem()
|
||||||
batch_item.read(istream)
|
batch_item.read(istream)
|
||||||
self.batch_items.append(batch_item)
|
self.batch_items.append(batch_item)
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import attributes
|
from kmip.core import attributes
|
||||||
from kmip.core.attributes import CryptographicParameters
|
from kmip.core.attributes import CryptographicParameters
|
||||||
|
|
||||||
from kmip.core.factories.attribute_values import AttributeValueFactory
|
from kmip.core.factories.attribute_values import AttributeValueFactory
|
||||||
|
@ -33,7 +33,7 @@ from kmip.core.primitives import ByteString
|
||||||
from kmip.core.primitives import Integer
|
from kmip.core.primitives import Integer
|
||||||
from kmip.core.primitives import Enumeration
|
from kmip.core.primitives import Enumeration
|
||||||
|
|
||||||
from utils import BytearrayStream
|
from kmip.core.utils import BytearrayStream
|
||||||
|
|
||||||
|
|
||||||
# 2.1
|
# 2.1
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
@ -21,8 +23,8 @@ from kmip.core.enums import Tags
|
||||||
|
|
||||||
from kmip.core.errors import ErrorStrings
|
from kmip.core.errors import ErrorStrings
|
||||||
|
|
||||||
import errors
|
from kmip.core import errors
|
||||||
import utils
|
from kmip.core import utils
|
||||||
|
|
||||||
|
|
||||||
class Base(object):
|
class Base(object):
|
||||||
|
@ -45,7 +47,7 @@ class Base(object):
|
||||||
def read_tag(self, istream):
|
def read_tag(self, istream):
|
||||||
# Read in the bytes for the tag
|
# Read in the bytes for the tag
|
||||||
tts = istream.read(self.TAG_SIZE)
|
tts = istream.read(self.TAG_SIZE)
|
||||||
tag = unpack('!I', '\x00' + tts[0:self.TAG_SIZE])[0]
|
tag = unpack('!I', b'\x00' + tts[0:self.TAG_SIZE])[0]
|
||||||
|
|
||||||
enum_tag = Tags(tag)
|
enum_tag = Tags(tag)
|
||||||
|
|
||||||
|
@ -134,7 +136,7 @@ class Base(object):
|
||||||
next_tag = stream.peek(Base.TAG_SIZE)
|
next_tag = stream.peek(Base.TAG_SIZE)
|
||||||
if len(next_tag) != Base.TAG_SIZE:
|
if len(next_tag) != Base.TAG_SIZE:
|
||||||
return False
|
return False
|
||||||
next_tag = unpack('!I', '\x00' + next_tag)[0]
|
next_tag = unpack('!I', b'\x00' + next_tag)[0]
|
||||||
if next_tag == tag.value:
|
if next_tag == tag.value:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -182,8 +184,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', str(istream.read(self.length)))[0]
|
self.value = unpack('!i', istream.read(self.length))[0]
|
||||||
pad = unpack('!i', str(istream.read(self.padding_length)))[0]
|
pad = unpack('!i', 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,
|
||||||
|
@ -236,7 +238,7 @@ class LongInteger(Base):
|
||||||
raise errors.ReadValueError(LongInteger.__name__, 'length',
|
raise errors.ReadValueError(LongInteger.__name__, 'length',
|
||||||
self.LENGTH, self.length)
|
self.LENGTH, self.length)
|
||||||
|
|
||||||
self.value = unpack('!q', str(istream.read(self.length)))[0]
|
self.value = unpack('!q', istream.read(self.length))[0]
|
||||||
self.validate()
|
self.validate()
|
||||||
|
|
||||||
def read(self, istream):
|
def read(self, istream):
|
||||||
|
@ -256,9 +258,15 @@ class LongInteger(Base):
|
||||||
def __validate(self):
|
def __validate(self):
|
||||||
if self.value is not None:
|
if self.value is not None:
|
||||||
data_type = type(self.value)
|
data_type = type(self.value)
|
||||||
if data_type not in (int, long):
|
if sys.version < '3':
|
||||||
|
valid_data_types = (int, long)
|
||||||
|
error_msg = '{0} or {1}'.format(int, long)
|
||||||
|
else:
|
||||||
|
valid_data_types = (int,)
|
||||||
|
error_msg = '{0}'.format(int)
|
||||||
|
if data_type not in valid_data_types:
|
||||||
raise errors.StateTypeError(LongInteger.__name__,
|
raise errors.StateTypeError(LongInteger.__name__,
|
||||||
'{0} or {1}'.format(int, long),
|
error_msg,
|
||||||
data_type)
|
data_type)
|
||||||
num_bytes = utils.count_bytes(self.value)
|
num_bytes = utils.count_bytes(self.value)
|
||||||
if num_bytes > self.length:
|
if num_bytes > self.length:
|
||||||
|
@ -303,7 +311,7 @@ class BigInteger(Base):
|
||||||
self.value = unpack('!q', str(istream.read(self.BLOCK_SIZE)))[0]
|
self.value = unpack('!q', str(istream.read(self.BLOCK_SIZE)))[0]
|
||||||
|
|
||||||
# Shift current value and add on next unsigned block
|
# Shift current value and add on next unsigned block
|
||||||
for _ in xrange(num_blocks - 1):
|
for _ in range(num_blocks - 1):
|
||||||
self.value = self.value << self.SHIFT_SIZE
|
self.value = self.value << self.SHIFT_SIZE
|
||||||
stream_data = istream.read(self.BLOCK_SIZE)
|
stream_data = istream.read(self.BLOCK_SIZE)
|
||||||
self.value += unpack('!Q', stream_data)[0]
|
self.value += unpack('!Q', stream_data)[0]
|
||||||
|
@ -330,7 +338,7 @@ class BigInteger(Base):
|
||||||
|
|
||||||
# Compose padding bytes
|
# Compose padding bytes
|
||||||
pad = ''
|
pad = ''
|
||||||
for _ in xrange(self.padding_length):
|
for _ in range(self.padding_length):
|
||||||
pad += hex(pad_byte)[2:]
|
pad += hex(pad_byte)[2:]
|
||||||
|
|
||||||
str_rep = hex(self.value).rstrip("Ll")[2:]
|
str_rep = hex(self.value).rstrip("Ll")[2:]
|
||||||
|
@ -346,7 +354,7 @@ class BigInteger(Base):
|
||||||
ostream.write(pack('!q', block))
|
ostream.write(pack('!q', block))
|
||||||
|
|
||||||
# Write remaining blocks as unsigned data
|
# Write remaining blocks as unsigned data
|
||||||
for i in xrange(1, num_blocks):
|
for i in range(1, num_blocks):
|
||||||
block = str_rep[(self.BLOCK_SIZE * i):(self.BLOCK_SIZE * (i + 1))]
|
block = str_rep[(self.BLOCK_SIZE * i):(self.BLOCK_SIZE * (i + 1))]
|
||||||
block = int(block, 16)
|
block = int(block, 16)
|
||||||
ostream.write(pack('!Q', block))
|
ostream.write(pack('!Q', block))
|
||||||
|
@ -425,7 +433,7 @@ class Boolean(Base):
|
||||||
raise errors.ReadValueError(Boolean.__name__, 'value',
|
raise errors.ReadValueError(Boolean.__name__, 'value',
|
||||||
value)
|
value)
|
||||||
|
|
||||||
for _ in xrange(self.length):
|
for _ in range(self.length):
|
||||||
istream.pop(0)
|
istream.pop(0)
|
||||||
|
|
||||||
def read(self, istream):
|
def read(self, istream):
|
||||||
|
@ -487,15 +495,18 @@ class TextString(Base):
|
||||||
def read_value(self, istream):
|
def read_value(self, istream):
|
||||||
# Read string text
|
# Read string text
|
||||||
self.value = ''
|
self.value = ''
|
||||||
for _ in xrange(self.length):
|
for _ in range(self.length):
|
||||||
self.value += unpack(self.BYTE_FORMAT, str(istream.read(1)))[0]
|
c = unpack(self.BYTE_FORMAT, istream.read(1))[0]
|
||||||
|
if sys.version >= '3':
|
||||||
|
c = c.decode()
|
||||||
|
self.value += c
|
||||||
|
|
||||||
# Read padding and check content
|
# Read padding and check content
|
||||||
self.padding_length = self.PADDING_SIZE - (self.length %
|
self.padding_length = self.PADDING_SIZE - (self.length %
|
||||||
self.PADDING_SIZE)
|
self.PADDING_SIZE)
|
||||||
if self.padding_length < self.PADDING_SIZE:
|
if self.padding_length < self.PADDING_SIZE:
|
||||||
for _ in xrange(self.padding_length):
|
for _ in range(self.padding_length):
|
||||||
pad = unpack('!B', str(istream.read(1)))[0]
|
pad = unpack('!B', istream.read(1))[0]
|
||||||
if pad is not 0:
|
if pad is not 0:
|
||||||
raise errors.ReadValueError(TextString.__name__, 'pad', 0,
|
raise errors.ReadValueError(TextString.__name__, 'pad', 0,
|
||||||
pad)
|
pad)
|
||||||
|
@ -508,10 +519,14 @@ class TextString(Base):
|
||||||
def write_value(self, ostream):
|
def write_value(self, ostream):
|
||||||
# Write string to stream
|
# Write string to stream
|
||||||
for char in self.value:
|
for char in self.value:
|
||||||
ostream.write(pack(self.BYTE_FORMAT, char))
|
if sys.version < '3':
|
||||||
|
c = char
|
||||||
|
else:
|
||||||
|
c = char.encode()
|
||||||
|
ostream.write(pack(self.BYTE_FORMAT, c))
|
||||||
|
|
||||||
# Write padding to stream
|
# Write padding to stream
|
||||||
for _ in xrange(self.padding_length):
|
for _ in range(self.padding_length):
|
||||||
ostream.write(pack('!B', 0))
|
ostream.write(pack('!B', 0))
|
||||||
|
|
||||||
def write(self, ostream):
|
def write(self, ostream):
|
||||||
|
@ -556,8 +571,8 @@ class ByteString(Base):
|
||||||
def read_value(self, istream):
|
def read_value(self, istream):
|
||||||
# Read bytes into bytearray
|
# Read bytes into bytearray
|
||||||
self.value = bytearray()
|
self.value = bytearray()
|
||||||
for _ in xrange(self.length):
|
for _ in range(self.length):
|
||||||
self.value.append(istream.read(1))
|
self.value.append(istream.read(1)[0])
|
||||||
|
|
||||||
# Read padding and check content
|
# Read padding and check content
|
||||||
self.padding_length = self.PADDING_SIZE - (self.length %
|
self.padding_length = self.PADDING_SIZE - (self.length %
|
||||||
|
@ -566,8 +581,8 @@ class ByteString(Base):
|
||||||
self.padding_length = 0
|
self.padding_length = 0
|
||||||
|
|
||||||
if self.padding_length < self.PADDING_SIZE:
|
if self.padding_length < self.PADDING_SIZE:
|
||||||
for _ in xrange(self.padding_length):
|
for _ in range(self.padding_length):
|
||||||
pad = unpack('!B', str(istream.read(1)))[0]
|
pad = unpack('!B', istream.read(1))[0]
|
||||||
if pad is not 0:
|
if pad is not 0:
|
||||||
raise errors.ReadValueError(TextString.__name__, 'pad', 0,
|
raise errors.ReadValueError(TextString.__name__, 'pad', 0,
|
||||||
pad)
|
pad)
|
||||||
|
@ -582,7 +597,7 @@ class ByteString(Base):
|
||||||
ostream.write(pack(self.BYTE_FORMAT, byte))
|
ostream.write(pack(self.BYTE_FORMAT, byte))
|
||||||
|
|
||||||
# Write padding to stream
|
# Write padding to stream
|
||||||
for _ in xrange(self.padding_length):
|
for _ in range(self.padding_length):
|
||||||
ostream.write(pack('!B', 0))
|
ostream.write(pack('!B', 0))
|
||||||
|
|
||||||
def write(self, ostream):
|
def write(self, ostream):
|
||||||
|
|
|
@ -304,7 +304,7 @@ class KMIPImpl(KMIP):
|
||||||
|
|
||||||
def _gen_symmetric_key(self, bit_length, crypto_alg):
|
def _gen_symmetric_key(self, bit_length, crypto_alg):
|
||||||
key_format_type = KeyBlock.KeyFormatType(KeyFormatTypeEnum.RAW)
|
key_format_type = KeyBlock.KeyFormatType(KeyFormatTypeEnum.RAW)
|
||||||
key_material = RawKey(bytearray(os.urandom(bit_length/8)))
|
key_material = RawKey(bytearray(os.urandom(int(bit_length/8))))
|
||||||
key_value = KeyValueStruct(key_format_type, key_material)
|
key_value = KeyValueStruct(key_format_type, key_material)
|
||||||
crypto_length = CryptographicLength(bit_length)
|
crypto_length = CryptographicLength(bit_length)
|
||||||
key_block = KeyBlock(key_format_type, None, key_value, crypto_alg,
|
key_block = KeyBlock(key_format_type, None, key_value, crypto_alg,
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
import io
|
||||||
|
|
||||||
from kmip.core.errors import ErrorStrings
|
from kmip.core.errors import ErrorStrings
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ def bit_length(num):
|
||||||
|
|
||||||
def count_bytes(num):
|
def count_bytes(num):
|
||||||
bits = bit_length(num)
|
bits = bit_length(num)
|
||||||
num_bytes = bits / 8
|
num_bytes = int(bits / 8)
|
||||||
if bits == 0 or bits % 8:
|
if bits == 0 or bits % 8:
|
||||||
num_bytes += 1
|
num_bytes += 1
|
||||||
return num_bytes
|
return num_bytes
|
||||||
|
@ -34,7 +35,7 @@ def count_bytes(num):
|
||||||
|
|
||||||
def print_bytearray(array):
|
def print_bytearray(array):
|
||||||
sbuffer = hexlify_bytearray(array)
|
sbuffer = hexlify_bytearray(array)
|
||||||
print 'buffer: {0}'.format(sbuffer)
|
print('buffer: {0}'.format(sbuffer))
|
||||||
|
|
||||||
|
|
||||||
def hexlify_bytearray(array):
|
def hexlify_bytearray(array):
|
||||||
|
@ -62,35 +63,46 @@ def build_er_error(class_object, descriptor, expected, received,
|
||||||
return msg.format(class_string, descriptor, expected, received)
|
return msg.format(class_string, descriptor, expected, received)
|
||||||
|
|
||||||
|
|
||||||
class BytearrayStream(object):
|
class BytearrayStream(io.RawIOBase):
|
||||||
def __init__(self, data=None):
|
def __init__(self, data=None):
|
||||||
if data is None:
|
if data is None:
|
||||||
self.buffer = bytearray()
|
self.buffer = b''
|
||||||
else:
|
else:
|
||||||
self.buffer = bytearray(data)
|
self.buffer = bytes(data)
|
||||||
|
|
||||||
def read(self, n=None):
|
def read(self, n=None):
|
||||||
if n is None:
|
if n is None or n == -1:
|
||||||
return str(self.buffer[0:])
|
return self.readall()
|
||||||
|
|
||||||
length = len(self.buffer)
|
length = len(self.buffer)
|
||||||
if n > length:
|
if n > length:
|
||||||
n = length
|
n = length
|
||||||
|
|
||||||
data = self.buffer[0:n]
|
data = self.buffer[0:n]
|
||||||
for _ in xrange(n):
|
self.buffer = self.buffer[n:]
|
||||||
self.buffer.pop(0)
|
return data
|
||||||
return str(data)
|
|
||||||
|
def readall(self):
|
||||||
|
data = self.buffer[0:]
|
||||||
|
self.buffer = self.buffer[len(self.buffer):]
|
||||||
|
return data
|
||||||
|
|
||||||
|
def readinto(self, b):
|
||||||
|
if len(b) <= len(self.buffer):
|
||||||
|
num_bytes_to_read = len(b)
|
||||||
|
else:
|
||||||
|
num_bytes_to_read = len(self.buffer)
|
||||||
|
b[:num_bytes_to_read] = self.buffer[:num_bytes_to_read]
|
||||||
|
self.buffer = self.buffer[num_bytes_to_read:]
|
||||||
|
return num_bytes_to_read
|
||||||
|
|
||||||
def peek(self, n=None):
|
def peek(self, n=None):
|
||||||
length = len(self.buffer)
|
length = len(self.buffer)
|
||||||
if n is None or n > length:
|
if n is None or n > length:
|
||||||
n = length
|
n = length
|
||||||
return str(self.buffer[0:n])
|
return self.buffer[0:n]
|
||||||
|
|
||||||
def write(self, b):
|
def write(self, b):
|
||||||
prev_bytes = len(self.buffer)
|
prev_bytes = len(self.buffer)
|
||||||
self.buffer.extend(b)
|
self.buffer += b
|
||||||
return len(self.buffer) - prev_bytes
|
return len(self.buffer) - prev_bytes
|
||||||
|
|
||||||
def length(self):
|
def length(self):
|
||||||
|
|
|
@ -64,8 +64,8 @@ if __name__ == '__main__':
|
||||||
secret_features.update([('key_format_type', key_format_type)])
|
secret_features.update([('key_format_type', key_format_type)])
|
||||||
|
|
||||||
# TODO (peter-hamilton) Replace with calls to crypto libraries
|
# TODO (peter-hamilton) Replace with calls to crypto libraries
|
||||||
key_data = {'bytes': bytearray('\x00\x00\x00\x00\x00\x00\x00\x00'
|
key_data = {'bytes': bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x00\x00\x00\x00\x00\x00\x00')}
|
b'\x00\x00\x00\x00\x00\x00\x00\x00')}
|
||||||
|
|
||||||
secret_features.update([('key_value', key_data)])
|
secret_features.update([('key_value', key_data)])
|
||||||
secret_features.update([('cryptographic_algorithm', algorithm_value)])
|
secret_features.update([('cryptographic_algorithm', algorithm_value)])
|
||||||
|
|
|
@ -14,28 +14,21 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import optparse
|
import optparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from thrift.server import TServer
|
from kmip.services.kmip_server import KMIPServer
|
||||||
from thrift.transport import TSocket
|
|
||||||
from thrift.transport import TTransport
|
|
||||||
|
|
||||||
from kmip.core.server import KMIPImpl
|
FILE_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
from kmip.services.kmip_protocol import KMIPProtocolFactory
|
|
||||||
from kmip.services.kmip_server import Processor
|
|
||||||
|
|
||||||
|
|
||||||
def run_server(host='127.0.0.1', port=5696):
|
def run_server(host='127.0.0.1', port=5696,
|
||||||
|
cert_file=FILE_PATH + '/../tests/utils/certs/server.crt',
|
||||||
|
key_file=FILE_PATH + '/../tests/utils/certs/server.key'):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
handler = KMIPImpl()
|
server = KMIPServer(host, port, cert_file, key_file)
|
||||||
processor = Processor(handler)
|
|
||||||
transport = TSocket.TServerSocket(host, port)
|
|
||||||
tfactory = TTransport.TBufferedTransportFactory()
|
|
||||||
pfactory = KMIPProtocolFactory()
|
|
||||||
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
|
|
||||||
|
|
||||||
logger.info('Starting the KMIP server')
|
logger.info('Starting the KMIP server')
|
||||||
|
|
||||||
|
@ -43,10 +36,10 @@ def run_server(host='127.0.0.1', port=5696):
|
||||||
server.serve()
|
server.serve()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.info('KeyboardInterrupt received while serving')
|
logger.info('KeyboardInterrupt received while serving')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.info('Exception received while serving: {0}'.format(e))
|
logger.info('Exception received while serving: {0}'.format(e))
|
||||||
finally:
|
finally:
|
||||||
transport.close()
|
server.close()
|
||||||
|
|
||||||
logger.info('Shutting down KMIP server')
|
logger.info('Shutting down KMIP server')
|
||||||
|
|
||||||
|
@ -60,6 +53,12 @@ def build_cli_parser():
|
||||||
"server (e.g., localhost, 127.0.0.1)")
|
"server (e.g., localhost, 127.0.0.1)")
|
||||||
parser.add_option("-p", "--port", action="store", default=5696,
|
parser.add_option("-p", "--port", action="store", default=5696,
|
||||||
dest="port", help="Port number for KMIP services")
|
dest="port", help="Port number for KMIP services")
|
||||||
|
parser.add_option("-c", "--cert_file", action="store",
|
||||||
|
default=FILE_PATH + '/../tests/utils/certs/server.crt',
|
||||||
|
dest="cert_file")
|
||||||
|
parser.add_option("-k", "--key_file", action="store",
|
||||||
|
default=FILE_PATH + '/../tests/utils/certs/server.key',
|
||||||
|
dest="key_file")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -67,4 +66,4 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
opts, args = parser.parse_args(sys.argv[1:])
|
opts, args = parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
run_server(opts.hostname, opts.port)
|
run_server(opts.hostname, opts.port, opts.cert_file, opts.key_file)
|
||||||
|
|
|
@ -37,28 +37,39 @@ from kmip.services.kmip_protocol import KMIPProtocol
|
||||||
|
|
||||||
from kmip.core.utils import BytearrayStream
|
from kmip.core.utils import BytearrayStream
|
||||||
|
|
||||||
from thrift.transport import TSocket
|
|
||||||
from thrift.transport import TTransport
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
|
import os
|
||||||
|
import socket
|
||||||
|
import ssl
|
||||||
|
|
||||||
|
FILE_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
class KMIPProxy(KMIP):
|
class KMIPProxy(KMIP):
|
||||||
|
|
||||||
# TODO (peter-hamilton) Move these defaults into config
|
# TODO (peter-hamilton) Move these defaults into config
|
||||||
def __init__(self, hostname='127.0.0.1', port=5696):
|
def __init__(self, hostname='127.0.0.1', port=5696,
|
||||||
|
ca_certs_file=FILE_PATH + '/../tests/utils/certs/server.crt'):
|
||||||
super(self.__class__, self).__init__()
|
super(self.__class__, self).__init__()
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
self.socket = TSocket.TSocket(hostname, port)
|
|
||||||
self.transport = TTransport.TBufferedTransport(self.socket)
|
self.hostname = hostname
|
||||||
self.protocol = KMIPProtocol(self.transport)
|
self.port = port
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
if ca_certs_file is not None:
|
||||||
|
self.socket = ssl.wrap_socket(sock,
|
||||||
|
ca_certs=ca_certs_file,
|
||||||
|
cert_reqs=ssl.CERT_REQUIRED)
|
||||||
|
else:
|
||||||
|
self.socket = sock
|
||||||
|
self.protocol = KMIPProtocol(self.socket)
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
self.transport.open()
|
self.socket.connect((self.hostname, self.port))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.transport.close()
|
self.socket.shutdown(socket.SHUT_RDWR)
|
||||||
|
|
||||||
def create(self, object_type, template_attribute, credential=None):
|
def create(self, object_type, template_attribute, credential=None):
|
||||||
object_type = attr.ObjectType(object_type)
|
object_type = attr.ObjectType(object_type)
|
||||||
|
|
|
@ -15,36 +15,47 @@
|
||||||
|
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
|
||||||
from thrift.protocol.TProtocol import TProtocolBase
|
|
||||||
|
|
||||||
import binascii
|
import binascii
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from kmip.core.utils import BytearrayStream
|
from kmip.core.utils import BytearrayStream
|
||||||
|
|
||||||
|
|
||||||
class KMIPProtocol(TProtocolBase):
|
class KMIPProtocol(object):
|
||||||
HEADER_SIZE = 8
|
HEADER_SIZE = 8
|
||||||
|
|
||||||
def __init__(self, trans, buffer_size=1024):
|
def __init__(self, socket, buffer_size=1024):
|
||||||
TProtocolBase.__init__(self, trans)
|
self.socket = socket
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
sbuffer = bytes(data)
|
sbuffer = bytes(data)
|
||||||
self.logger.debug('buffer: {0}'.format(binascii.hexlify(sbuffer)))
|
self.logger.debug('buffer: {0}'.format(binascii.hexlify(sbuffer)))
|
||||||
self.trans.write(sbuffer)
|
self.socket.sendall(sbuffer)
|
||||||
self.trans.flush()
|
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
header = self.trans.readAll(self.HEADER_SIZE)
|
header = self._recv_all(self.HEADER_SIZE)
|
||||||
msg_size = unpack('!I', header[4:])[0]
|
msg_size = unpack('!I', header[4:])[0]
|
||||||
payload = self.trans.readAll(msg_size)
|
payload = self._recv_all(msg_size)
|
||||||
return BytearrayStream(header + payload)
|
return BytearrayStream(header + payload)
|
||||||
|
|
||||||
|
def _recv_all(self, total_bytes_to_be_read):
|
||||||
|
bytes_read = 0
|
||||||
|
total_msg = b''
|
||||||
|
while bytes_read < total_bytes_to_be_read:
|
||||||
|
msg = self.socket.recv(total_bytes_to_be_read - bytes_read)
|
||||||
|
if not msg:
|
||||||
|
break
|
||||||
|
bytes_read += len(msg)
|
||||||
|
total_msg += msg
|
||||||
|
if bytes_read != total_bytes_to_be_read:
|
||||||
|
raise Exception("Expected {0} bytes, Received {1} bytes"
|
||||||
|
.format(total_bytes_to_be_read, bytes_read))
|
||||||
|
return total_msg
|
||||||
|
|
||||||
|
|
||||||
class KMIPProtocolFactory(object):
|
class KMIPProtocolFactory(object):
|
||||||
|
|
||||||
def getProtocol(self, trans):
|
def getProtocol(self, socket):
|
||||||
return KMIPProtocol(trans)
|
return KMIPProtocol(socket)
|
||||||
|
|
|
@ -13,241 +13,48 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import time
|
import os
|
||||||
|
import socket
|
||||||
|
import ssl
|
||||||
|
|
||||||
from thrift.Thrift import TProcessor
|
from kmip.core.server import KMIPImpl
|
||||||
|
|
||||||
from kmip.core.messages.messages import RequestMessage
|
from kmip.services.kmip_protocol import KMIPProtocolFactory
|
||||||
from kmip.core.messages.messages import ResponseMessage
|
from kmip.services.processor import Processor
|
||||||
from kmip.core.messages.messages import ResponseBatchItem
|
|
||||||
from kmip.core.messages.messages import ResponseHeader
|
|
||||||
|
|
||||||
from kmip.core.messages.contents import AsynchronousIndicator
|
FILE_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
from kmip.core.messages.contents import BatchErrorContinuationOption
|
|
||||||
from kmip.core.messages.contents import BatchCount
|
|
||||||
from kmip.core.messages.contents import TimeStamp
|
|
||||||
|
|
||||||
from kmip.core.primitives import Base
|
|
||||||
|
|
||||||
from kmip.core.messages.operations import CreateResponsePayload
|
|
||||||
from kmip.core.messages.operations import GetResponsePayload
|
|
||||||
from kmip.core.messages.operations import DestroyResponsePayload
|
|
||||||
from kmip.core.messages.operations import RegisterResponsePayload
|
|
||||||
|
|
||||||
from kmip.core.enums import Operation
|
|
||||||
from kmip.core.enums import ResultStatus as RS
|
|
||||||
from kmip.core.enums import Tags
|
|
||||||
from kmip.core.enums import BatchErrorContinuationOption as BECO
|
|
||||||
|
|
||||||
from kmip.core.utils import BytearrayStream
|
|
||||||
|
|
||||||
|
|
||||||
class Processor(TProcessor):
|
class KMIPServer(object):
|
||||||
def __init__(self, handler):
|
def __init__(self, host='127.0.0.1', port=5696,
|
||||||
self._handler = handler
|
cert_file=None, key_file=None):
|
||||||
|
handler = KMIPImpl()
|
||||||
|
self._processor = Processor(handler)
|
||||||
|
|
||||||
def process(self, istream, ostream):
|
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
stream = istream.read()
|
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
|
self.socket.bind((host, int(port)))
|
||||||
|
self.cert_file = cert_file
|
||||||
|
self.key_file = key_file
|
||||||
|
|
||||||
if Base.is_tag_next(Tags.REQUEST_MESSAGE, stream):
|
def close(self):
|
||||||
message = RequestMessage()
|
self.socket.shutdown(socket.SHUT_RDWR)
|
||||||
message.read(stream)
|
self.socket.close()
|
||||||
result = self._process_request(message)
|
|
||||||
tstream = BytearrayStream()
|
|
||||||
result.write(tstream)
|
|
||||||
ostream.write(tstream.buffer)
|
|
||||||
elif Base.is_tag_next(Tags.RESPONSE_MESSAGE, stream):
|
|
||||||
message = ResponseMessage()
|
|
||||||
message.read(stream)
|
|
||||||
self._process_response(message)
|
|
||||||
else:
|
|
||||||
raise ValueError('Processing error: stream contains unknown'
|
|
||||||
'message type')
|
|
||||||
|
|
||||||
def _process_request(self, message):
|
def serve(self):
|
||||||
header = message.request_header
|
self.socket.listen(0)
|
||||||
|
while True:
|
||||||
|
connection, address = self.socket.accept()
|
||||||
|
if self.cert_file and self.key_file:
|
||||||
|
connection = ssl.wrap_socket(connection,
|
||||||
|
server_side=True,
|
||||||
|
certfile=self.cert_file,
|
||||||
|
keyfile=self.key_file)
|
||||||
|
|
||||||
protocol_version = header.protocol_version
|
factory = KMIPProtocolFactory()
|
||||||
# maximum_response_size = header.maximum_response_size
|
protocol = factory.getProtocol(connection)
|
||||||
asynchronous_indicator = header.asynchronous_indicator
|
try:
|
||||||
# authentication = header.authentication
|
while True:
|
||||||
batch_error_cont_option = header.batch_error_cont_option
|
self._processor.process(protocol, protocol)
|
||||||
# batch_order_option = header.batch_order_option
|
except Exception:
|
||||||
# time_stamp = header.time_stamp
|
connection.close()
|
||||||
request_batch_count = header.batch_count.value
|
|
||||||
|
|
||||||
# TODO (peter-hamilton) Log receipt of message with time stamp
|
|
||||||
|
|
||||||
if asynchronous_indicator is None:
|
|
||||||
asynchronous_indicator = AsynchronousIndicator(False)
|
|
||||||
|
|
||||||
if batch_error_cont_option is None:
|
|
||||||
batch_error_cont_option = BatchErrorContinuationOption(BECO.STOP)
|
|
||||||
|
|
||||||
request_batch_items = message.batch_items
|
|
||||||
response_batch_items = []
|
|
||||||
|
|
||||||
for i in xrange(request_batch_count):
|
|
||||||
request_batch_item = request_batch_items[i]
|
|
||||||
failure_occurred = False
|
|
||||||
|
|
||||||
operation = request_batch_item.operation
|
|
||||||
ubi_id = request_batch_item.unique_batch_item_id
|
|
||||||
payload = request_batch_item.request_payload
|
|
||||||
message_extension = request_batch_item.message_extension
|
|
||||||
|
|
||||||
result = self._process_operation(operation, payload)
|
|
||||||
|
|
||||||
result_status = result[0]
|
|
||||||
result_reason = result[1]
|
|
||||||
result_message = result[2]
|
|
||||||
asyn_cv = None
|
|
||||||
response_payload = None
|
|
||||||
message_extension = None
|
|
||||||
|
|
||||||
if result_status.enum is RS.SUCCESS:
|
|
||||||
response_payload = result[3]
|
|
||||||
elif result_status.enum is RS.OPERATION_FAILED:
|
|
||||||
failure_occurred = True
|
|
||||||
result_reason = result[1]
|
|
||||||
elif result_status.enum is RS.OPERATION_PENDING:
|
|
||||||
# TODO (peter-hamilton) Need to add a way to track async
|
|
||||||
# TODO (peter-hamilton) operations.
|
|
||||||
asyn_cv = '\x00'
|
|
||||||
elif result_status.enum is RS.OPERATION_UNDONE:
|
|
||||||
result_reason = result[1]
|
|
||||||
else:
|
|
||||||
msg = 'Unrecognized operation result status: {}'
|
|
||||||
raise RuntimeError(msg.format(result_status))
|
|
||||||
|
|
||||||
resp_bi = ResponseBatchItem(operation=operation,
|
|
||||||
unique_batch_item_id=ubi_id,
|
|
||||||
result_status=result_status,
|
|
||||||
result_reason=result_reason,
|
|
||||||
result_message=result_message,
|
|
||||||
async_correlation_value=asyn_cv,
|
|
||||||
response_payload=response_payload,
|
|
||||||
message_extension=message_extension)
|
|
||||||
response_batch_items.append(resp_bi)
|
|
||||||
|
|
||||||
if failure_occurred:
|
|
||||||
if batch_error_cont_option.enum is BECO.STOP:
|
|
||||||
break
|
|
||||||
elif batch_error_cont_option.enum is BECO.UNDO:
|
|
||||||
# TODO (peter-hamilton) Tell client to undo operations.
|
|
||||||
# TODO (peter-hamilton) Unclear what response should be.
|
|
||||||
break
|
|
||||||
elif batch_error_cont_option.enum is BECO.CONTINUE:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
msg = 'Unrecognized batch error continuation option: {}'
|
|
||||||
raise RuntimeError(msg.format(batch_error_cont_option))
|
|
||||||
|
|
||||||
response_batch_count = BatchCount(len(response_batch_items))
|
|
||||||
response_time_stamp = TimeStamp(int(time.time()))
|
|
||||||
response_header = ResponseHeader(protocol_version=protocol_version,
|
|
||||||
time_stamp=response_time_stamp,
|
|
||||||
batch_count=response_batch_count)
|
|
||||||
|
|
||||||
response_message = ResponseMessage(response_header=response_header,
|
|
||||||
batch_items=response_batch_items)
|
|
||||||
return response_message
|
|
||||||
|
|
||||||
def _process_response(self, message):
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def _process_operation(self, operation, payload):
|
|
||||||
op = operation.enum
|
|
||||||
|
|
||||||
if op is Operation.CREATE:
|
|
||||||
return self._process_create_request(payload)
|
|
||||||
elif op is Operation.GET:
|
|
||||||
return self._process_get_request(payload)
|
|
||||||
elif op is Operation.DESTROY:
|
|
||||||
return self._process_destroy_request(payload)
|
|
||||||
elif op is Operation.REGISTER:
|
|
||||||
return self._process_register_request(payload)
|
|
||||||
else:
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def _process_create_request(self, payload):
|
|
||||||
object_type = payload.object_type
|
|
||||||
template_attribute = payload.template_attribute
|
|
||||||
result = self._handler.create(object_type, template_attribute)
|
|
||||||
|
|
||||||
result_status = result.result_status
|
|
||||||
result_reason = result.result_reason
|
|
||||||
result_message = result.result_message
|
|
||||||
created_type = result.object_type
|
|
||||||
uuid = result.uuid
|
|
||||||
template_attribute = result.template_attribute
|
|
||||||
|
|
||||||
resp_pl = CreateResponsePayload(object_type=created_type,
|
|
||||||
unique_identifier=uuid,
|
|
||||||
template_attribute=template_attribute)
|
|
||||||
|
|
||||||
return (result_status, result_reason, result_message, resp_pl)
|
|
||||||
|
|
||||||
def _process_get_request(self, payload):
|
|
||||||
uuid = None
|
|
||||||
kft = None
|
|
||||||
kct = None
|
|
||||||
|
|
||||||
unique_identifier = payload.unique_identifier
|
|
||||||
key_format_type = payload.key_format_type
|
|
||||||
key_compression_type = payload.key_compression_type
|
|
||||||
key_wrapping_specification = payload.key_wrapping_specification
|
|
||||||
|
|
||||||
if unique_identifier is not None:
|
|
||||||
uuid = unique_identifier
|
|
||||||
if key_format_type is not None:
|
|
||||||
kft = key_format_type
|
|
||||||
if key_compression_type is not None:
|
|
||||||
kct = key_compression_type
|
|
||||||
|
|
||||||
result = self._handler.get(uuid, kft, kct,
|
|
||||||
key_wrapping_specification)
|
|
||||||
|
|
||||||
result_status = result.result_status
|
|
||||||
result_reason = result.result_reason
|
|
||||||
result_message = result.result_message
|
|
||||||
retrieved_type = result.object_type
|
|
||||||
uuid = result.uuid
|
|
||||||
secret = result.secret
|
|
||||||
|
|
||||||
resp_pl = GetResponsePayload(object_type=retrieved_type,
|
|
||||||
unique_identifier=uuid,
|
|
||||||
secret=secret)
|
|
||||||
|
|
||||||
return (result_status, result_reason, result_message, resp_pl)
|
|
||||||
|
|
||||||
def _process_destroy_request(self, payload):
|
|
||||||
uuid = payload.unique_identifier
|
|
||||||
result = self._handler.destroy(uuid)
|
|
||||||
|
|
||||||
result_status = result.result_status
|
|
||||||
result_reason = result.result_reason
|
|
||||||
result_message = result.result_message
|
|
||||||
uuid = result.uuid
|
|
||||||
|
|
||||||
payload = DestroyResponsePayload(unique_identifier=uuid)
|
|
||||||
|
|
||||||
return (result_status, result_reason, result_message, payload)
|
|
||||||
|
|
||||||
def _process_register_request(self, payload):
|
|
||||||
object_type = payload.object_type
|
|
||||||
template_attribute = payload.template_attribute
|
|
||||||
secret = payload.secret
|
|
||||||
result = self._handler.register(object_type, template_attribute,
|
|
||||||
secret)
|
|
||||||
|
|
||||||
result_status = result.result_status
|
|
||||||
result_reason = result.result_reason
|
|
||||||
result_message = result.result_message
|
|
||||||
uuid = result.uuid
|
|
||||||
template_attr = result.template_attribute
|
|
||||||
|
|
||||||
resp_pl = RegisterResponsePayload(unique_identifier=uuid,
|
|
||||||
template_attribute=template_attr)
|
|
||||||
|
|
||||||
return (result_status, result_reason, result_message, resp_pl)
|
|
||||||
|
|
|
@ -0,0 +1,254 @@
|
||||||
|
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
from kmip.core.messages.messages import RequestMessage
|
||||||
|
from kmip.core.messages.messages import ResponseMessage
|
||||||
|
from kmip.core.messages.messages import ResponseBatchItem
|
||||||
|
from kmip.core.messages.messages import ResponseHeader
|
||||||
|
|
||||||
|
from kmip.core.messages.contents import AsynchronousIndicator
|
||||||
|
from kmip.core.messages.contents import BatchErrorContinuationOption
|
||||||
|
from kmip.core.messages.contents import BatchCount
|
||||||
|
from kmip.core.messages.contents import TimeStamp
|
||||||
|
|
||||||
|
from kmip.core.primitives import Base
|
||||||
|
|
||||||
|
from kmip.core.messages.operations import CreateResponsePayload
|
||||||
|
from kmip.core.messages.operations import GetResponsePayload
|
||||||
|
from kmip.core.messages.operations import DestroyResponsePayload
|
||||||
|
from kmip.core.messages.operations import RegisterResponsePayload
|
||||||
|
|
||||||
|
from kmip.core.enums import Operation
|
||||||
|
from kmip.core.enums import ResultStatus as RS
|
||||||
|
from kmip.core.enums import Tags
|
||||||
|
from kmip.core.enums import BatchErrorContinuationOption as BECO
|
||||||
|
|
||||||
|
from kmip.core.utils import BytearrayStream
|
||||||
|
|
||||||
|
|
||||||
|
class Processor(object):
|
||||||
|
def __init__(self, handler):
|
||||||
|
self._handler = handler
|
||||||
|
|
||||||
|
def process(self, istream, ostream):
|
||||||
|
stream = istream.read()
|
||||||
|
|
||||||
|
if Base.is_tag_next(Tags.REQUEST_MESSAGE, stream):
|
||||||
|
message = RequestMessage()
|
||||||
|
message.read(stream)
|
||||||
|
try:
|
||||||
|
result = self._process_request(message)
|
||||||
|
except Exception as e:
|
||||||
|
raise e
|
||||||
|
tstream = BytearrayStream()
|
||||||
|
result.write(tstream)
|
||||||
|
ostream.write(tstream.buffer)
|
||||||
|
elif Base.is_tag_next(Tags.RESPONSE_MESSAGE, stream):
|
||||||
|
message = ResponseMessage()
|
||||||
|
message.read(stream)
|
||||||
|
self._process_response(message)
|
||||||
|
else:
|
||||||
|
raise ValueError('Processing error: stream contains unknown '
|
||||||
|
'message type')
|
||||||
|
|
||||||
|
def _process_request(self, message):
|
||||||
|
header = message.request_header
|
||||||
|
|
||||||
|
protocol_version = header.protocol_version
|
||||||
|
# maximum_response_size = header.maximum_response_size
|
||||||
|
asynchronous_indicator = header.asynchronous_indicator
|
||||||
|
# authentication = header.authentication
|
||||||
|
batch_error_cont_option = header.batch_error_cont_option
|
||||||
|
# batch_order_option = header.batch_order_option
|
||||||
|
# time_stamp = header.time_stamp
|
||||||
|
request_batch_count = header.batch_count.value
|
||||||
|
|
||||||
|
# TODO (peter-hamilton) Log receipt of message with time stamp
|
||||||
|
|
||||||
|
if asynchronous_indicator is None:
|
||||||
|
asynchronous_indicator = AsynchronousIndicator(False)
|
||||||
|
|
||||||
|
if batch_error_cont_option is None:
|
||||||
|
batch_error_cont_option = BatchErrorContinuationOption(BECO.STOP)
|
||||||
|
|
||||||
|
request_batch_items = message.batch_items
|
||||||
|
response_batch_items = []
|
||||||
|
|
||||||
|
for i in range(request_batch_count):
|
||||||
|
request_batch_item = request_batch_items[i]
|
||||||
|
failure_occurred = False
|
||||||
|
|
||||||
|
operation = request_batch_item.operation
|
||||||
|
ubi_id = request_batch_item.unique_batch_item_id
|
||||||
|
payload = request_batch_item.request_payload
|
||||||
|
message_extension = request_batch_item.message_extension
|
||||||
|
|
||||||
|
result = self._process_operation(operation, payload)
|
||||||
|
|
||||||
|
result_status = result[0]
|
||||||
|
result_reason = result[1]
|
||||||
|
result_message = result[2]
|
||||||
|
asyn_cv = None
|
||||||
|
response_payload = None
|
||||||
|
message_extension = None
|
||||||
|
|
||||||
|
if result_status.enum is RS.SUCCESS:
|
||||||
|
response_payload = result[3]
|
||||||
|
elif result_status.enum is RS.OPERATION_FAILED:
|
||||||
|
failure_occurred = True
|
||||||
|
result_reason = result[1]
|
||||||
|
elif result_status.enum is RS.OPERATION_PENDING:
|
||||||
|
# TODO (peter-hamilton) Need to add a way to track async
|
||||||
|
# TODO (peter-hamilton) operations.
|
||||||
|
asyn_cv = b'\x00'
|
||||||
|
elif result_status.enum is RS.OPERATION_UNDONE:
|
||||||
|
result_reason = result[1]
|
||||||
|
else:
|
||||||
|
msg = 'Unrecognized operation result status: {}'
|
||||||
|
raise RuntimeError(msg.format(result_status))
|
||||||
|
|
||||||
|
resp_bi = ResponseBatchItem(operation=operation,
|
||||||
|
unique_batch_item_id=ubi_id,
|
||||||
|
result_status=result_status,
|
||||||
|
result_reason=result_reason,
|
||||||
|
result_message=result_message,
|
||||||
|
async_correlation_value=asyn_cv,
|
||||||
|
response_payload=response_payload,
|
||||||
|
message_extension=message_extension)
|
||||||
|
response_batch_items.append(resp_bi)
|
||||||
|
|
||||||
|
if failure_occurred:
|
||||||
|
if batch_error_cont_option.enum is BECO.STOP:
|
||||||
|
break
|
||||||
|
elif batch_error_cont_option.enum is BECO.UNDO:
|
||||||
|
# TODO (peter-hamilton) Tell client to undo operations.
|
||||||
|
# TODO (peter-hamilton) Unclear what response should be.
|
||||||
|
break
|
||||||
|
elif batch_error_cont_option.enum is BECO.CONTINUE:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
msg = 'Unrecognized batch error continuation option: {}'
|
||||||
|
raise RuntimeError(msg.format(batch_error_cont_option))
|
||||||
|
|
||||||
|
response_batch_count = BatchCount(len(response_batch_items))
|
||||||
|
response_time_stamp = TimeStamp(int(time.time()))
|
||||||
|
response_header = ResponseHeader(protocol_version=protocol_version,
|
||||||
|
time_stamp=response_time_stamp,
|
||||||
|
batch_count=response_batch_count)
|
||||||
|
|
||||||
|
response_message = ResponseMessage(response_header=response_header,
|
||||||
|
batch_items=response_batch_items)
|
||||||
|
return response_message
|
||||||
|
|
||||||
|
def _process_response(self, message):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def _process_operation(self, operation, payload):
|
||||||
|
op = operation.enum
|
||||||
|
|
||||||
|
if op is Operation.CREATE:
|
||||||
|
return self._process_create_request(payload)
|
||||||
|
elif op is Operation.GET:
|
||||||
|
return self._process_get_request(payload)
|
||||||
|
elif op is Operation.DESTROY:
|
||||||
|
return self._process_destroy_request(payload)
|
||||||
|
elif op is Operation.REGISTER:
|
||||||
|
return self._process_register_request(payload)
|
||||||
|
else:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def _process_create_request(self, payload):
|
||||||
|
object_type = payload.object_type
|
||||||
|
template_attribute = payload.template_attribute
|
||||||
|
result = self._handler.create(object_type, template_attribute)
|
||||||
|
|
||||||
|
result_status = result.result_status
|
||||||
|
result_reason = result.result_reason
|
||||||
|
result_message = result.result_message
|
||||||
|
created_type = result.object_type
|
||||||
|
uuid = result.uuid
|
||||||
|
template_attribute = result.template_attribute
|
||||||
|
|
||||||
|
resp_pl = CreateResponsePayload(object_type=created_type,
|
||||||
|
unique_identifier=uuid,
|
||||||
|
template_attribute=template_attribute)
|
||||||
|
|
||||||
|
return (result_status, result_reason, result_message, resp_pl)
|
||||||
|
|
||||||
|
def _process_get_request(self, payload):
|
||||||
|
uuid = None
|
||||||
|
kft = None
|
||||||
|
kct = None
|
||||||
|
|
||||||
|
unique_identifier = payload.unique_identifier
|
||||||
|
key_format_type = payload.key_format_type
|
||||||
|
key_compression_type = payload.key_compression_type
|
||||||
|
key_wrapping_specification = payload.key_wrapping_specification
|
||||||
|
|
||||||
|
if unique_identifier is not None:
|
||||||
|
uuid = unique_identifier
|
||||||
|
if key_format_type is not None:
|
||||||
|
kft = key_format_type
|
||||||
|
if key_compression_type is not None:
|
||||||
|
kct = key_compression_type
|
||||||
|
|
||||||
|
result = self._handler.get(uuid, kft, kct,
|
||||||
|
key_wrapping_specification)
|
||||||
|
|
||||||
|
result_status = result.result_status
|
||||||
|
result_reason = result.result_reason
|
||||||
|
result_message = result.result_message
|
||||||
|
retrieved_type = result.object_type
|
||||||
|
uuid = result.uuid
|
||||||
|
secret = result.secret
|
||||||
|
|
||||||
|
resp_pl = GetResponsePayload(object_type=retrieved_type,
|
||||||
|
unique_identifier=uuid,
|
||||||
|
secret=secret)
|
||||||
|
|
||||||
|
return (result_status, result_reason, result_message, resp_pl)
|
||||||
|
|
||||||
|
def _process_destroy_request(self, payload):
|
||||||
|
uuid = payload.unique_identifier
|
||||||
|
result = self._handler.destroy(uuid)
|
||||||
|
|
||||||
|
result_status = result.result_status
|
||||||
|
result_reason = result.result_reason
|
||||||
|
result_message = result.result_message
|
||||||
|
uuid = result.uuid
|
||||||
|
|
||||||
|
payload = DestroyResponsePayload(unique_identifier=uuid)
|
||||||
|
|
||||||
|
return (result_status, result_reason, result_message, payload)
|
||||||
|
|
||||||
|
def _process_register_request(self, payload):
|
||||||
|
object_type = payload.object_type
|
||||||
|
template_attribute = payload.template_attribute
|
||||||
|
secret = payload.secret
|
||||||
|
result = self._handler.register(object_type, template_attribute,
|
||||||
|
secret)
|
||||||
|
|
||||||
|
result_status = result.result_status
|
||||||
|
result_reason = result.result_reason
|
||||||
|
result_message = result.result_message
|
||||||
|
uuid = result.uuid
|
||||||
|
template_attr = result.template_attribute
|
||||||
|
|
||||||
|
resp_pl = RegisterResponsePayload(unique_identifier=uuid,
|
||||||
|
template_attribute=template_attr)
|
||||||
|
|
||||||
|
return (result_status, result_reason, result_message, resp_pl)
|
|
@ -65,77 +65,78 @@ class TestRequestMessage(TestCase):
|
||||||
self.attribute_factory = AttributeFactory()
|
self.attribute_factory = AttributeFactory()
|
||||||
self.msg = errors.ErrorStrings.BAD_EXP_RECV
|
self.msg = errors.ErrorStrings.BAD_EXP_RECV
|
||||||
self.create = (
|
self.create = (
|
||||||
'\x42\x00\x78\x01\x00\x00\x01\x20\x42\x00\x77\x01\x00\x00\x00\x38'
|
b'\x42\x00\x78\x01\x00\x00\x01\x20\x42\x00\x77\x01\x00\x00\x00\x38'
|
||||||
'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0D\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0D\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\xD8'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\xD8'
|
||||||
'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
|
b'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
|
||||||
'\x42\x00\x79\x01\x00\x00\x00\xC0\x42\x00\x57\x05\x00\x00\x00\x04'
|
b'\x42\x00\x79\x01\x00\x00\x00\xC0\x42\x00\x57\x05\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x02\x00\x00\x00\x00\x42\x00\x91\x01\x00\x00\x00\xA8'
|
b'\x00\x00\x00\x02\x00\x00\x00\x00\x42\x00\x91\x01\x00\x00\x00\xA8'
|
||||||
'\x42\x00\x08\x01\x00\x00\x00\x30\x42\x00\x0A\x07\x00\x00\x00\x17'
|
b'\x42\x00\x08\x01\x00\x00\x00\x30\x42\x00\x0A\x07\x00\x00\x00\x17'
|
||||||
'\x43\x72\x79\x70\x74\x6F\x67\x72\x61\x70\x68\x69\x63\x20\x41\x6C'
|
b'\x43\x72\x79\x70\x74\x6F\x67\x72\x61\x70\x68\x69\x63\x20\x41\x6C'
|
||||||
'\x67\x6F\x72\x69\x74\x68\x6D\x00\x42\x00\x0B\x05\x00\x00\x00\x04'
|
b'\x67\x6F\x72\x69\x74\x68\x6D\x00\x42\x00\x0B\x05\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x03\x00\x00\x00\x00\x42\x00\x08\x01\x00\x00\x00\x30'
|
b'\x00\x00\x00\x03\x00\x00\x00\x00\x42\x00\x08\x01\x00\x00\x00\x30'
|
||||||
'\x42\x00\x0A\x07\x00\x00\x00\x14\x43\x72\x79\x70\x74\x6F\x67\x72'
|
b'\x42\x00\x0A\x07\x00\x00\x00\x14\x43\x72\x79\x70\x74\x6F\x67\x72'
|
||||||
'\x61\x70\x68\x69\x63\x20\x4C\x65\x6E\x67\x74\x68\x00\x00\x00\x00'
|
b'\x61\x70\x68\x69\x63\x20\x4C\x65\x6E\x67\x74\x68\x00\x00\x00\x00'
|
||||||
'\x42\x00\x0B\x02\x00\x00\x00\x04\x00\x00\x00\x80\x00\x00\x00\x00'
|
b'\x42\x00\x0B\x02\x00\x00\x00\x04\x00\x00\x00\x80\x00\x00\x00\x00'
|
||||||
'\x42\x00\x08\x01\x00\x00\x00\x30\x42\x00\x0A\x07\x00\x00\x00\x18'
|
b'\x42\x00\x08\x01\x00\x00\x00\x30\x42\x00\x0A\x07\x00\x00\x00\x18'
|
||||||
'\x43\x72\x79\x70\x74\x6F\x67\x72\x61\x70\x68\x69\x63\x20\x55\x73'
|
b'\x43\x72\x79\x70\x74\x6F\x67\x72\x61\x70\x68\x69\x63\x20\x55\x73'
|
||||||
'\x61\x67\x65\x20\x4D\x61\x73\x6B\x42\x00\x0B\x02\x00\x00\x00\x04'
|
b'\x61\x67\x65\x20\x4D\x61\x73\x6B\x42\x00\x0B\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x0C\x00\x00\x00\x00')
|
b'\x00\x00\x00\x0C\x00\x00\x00\x00')
|
||||||
self.register = (
|
self.register = (
|
||||||
'\x42\x00\x78\x01\x00\x00\x01\xC8\x42\x00\x77\x01\x00\x00\x00\x38'
|
b'\x42\x00\x78\x01\x00\x00\x01\xC8\x42\x00\x77\x01\x00\x00\x00\x38'
|
||||||
'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0D\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0D\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x01\x80'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x01\x80'
|
||||||
'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00'
|
b'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00'
|
||||||
'\x42\x00\x79\x01\x00\x00\x01\x68\x42\x00\x57\x05\x00\x00\x00\x04'
|
b'\x42\x00\x79\x01\x00\x00\x01\x68\x42\x00\x57\x05\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x91\x01\x00\x00\x00\x00'
|
b'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x91\x01\x00\x00\x00\x00'
|
||||||
'\x42\x00\x90\x01\x00\x00\x01\x48\x42\x00\x08\x01\x00\x00\x00\x28'
|
b'\x42\x00\x90\x01\x00\x00\x01\x48\x42\x00\x08\x01\x00\x00\x00\x28'
|
||||||
'\x42\x00\x0A\x07\x00\x00\x00\x0C\x4F\x62\x6A\x65\x63\x74\x20\x47'
|
b'\x42\x00\x0A\x07\x00\x00\x00\x0C\x4F\x62\x6A\x65\x63\x74\x20\x47'
|
||||||
'\x72\x6F\x75\x70\x00\x00\x00\x00\x42\x00\x0B\x07\x00\x00\x00\x06'
|
b'\x72\x6F\x75\x70\x00\x00\x00\x00\x42\x00\x0B\x07\x00\x00\x00\x06'
|
||||||
'\x47\x72\x6F\x75\x70\x31\x00\x00\x42\x00\x08\x01\x00\x00\x00\x58'
|
b'\x47\x72\x6F\x75\x70\x31\x00\x00\x42\x00\x08\x01\x00\x00\x00\x58'
|
||||||
'\x42\x00\x0A\x07\x00\x00\x00\x20\x41\x70\x70\x6C\x69\x63\x61\x74'
|
b'\x42\x00\x0A\x07\x00\x00\x00\x20\x41\x70\x70\x6C\x69\x63\x61\x74'
|
||||||
'\x69\x6F\x6E\x20\x53\x70\x65\x63\x69\x66\x69\x63\x20\x49\x6E\x66'
|
b'\x69\x6F\x6E\x20\x53\x70\x65\x63\x69\x66\x69\x63\x20\x49\x6E\x66'
|
||||||
'\x6F\x72\x6D\x61\x74\x69\x6F\x6E\x42\x00\x0B\x01\x00\x00\x00\x28'
|
b'\x6F\x72\x6D\x61\x74\x69\x6F\x6E\x42\x00\x0B\x01\x00\x00\x00\x28'
|
||||||
'\x42\x00\x03\x07\x00\x00\x00\x03\x73\x73\x6C\x00\x00\x00\x00\x00'
|
b'\x42\x00\x03\x07\x00\x00\x00\x03\x73\x73\x6C\x00\x00\x00\x00\x00'
|
||||||
'\x42\x00\x02\x07\x00\x00\x00\x0F\x77\x77\x77\x2E\x65\x78\x61\x6D'
|
b'\x42\x00\x02\x07\x00\x00\x00\x0F\x77\x77\x77\x2E\x65\x78\x61\x6D'
|
||||||
'\x70\x6C\x65\x2E\x63\x6F\x6D\x00\x42\x00\x08\x01\x00\x00\x00\x30'
|
b'\x70\x6C\x65\x2E\x63\x6F\x6D\x00\x42\x00\x08\x01\x00\x00\x00\x30'
|
||||||
'\x42\x00\x0A\x07\x00\x00\x00\x13\x43\x6F\x6E\x74\x61\x63\x74\x20'
|
b'\x42\x00\x0A\x07\x00\x00\x00\x13\x43\x6F\x6E\x74\x61\x63\x74\x20'
|
||||||
'\x49\x6E\x66\x6F\x72\x6D\x61\x74\x69\x6F\x6E\x00\x00\x00\x00\x00'
|
b'\x49\x6E\x66\x6F\x72\x6D\x61\x74\x69\x6F\x6E\x00\x00\x00\x00\x00'
|
||||||
'\x42\x00\x0B\x07\x00\x00\x00\x03\x4A\x6F\x65\x00\x00\x00\x00\x00'
|
b'\x42\x00\x0B\x07\x00\x00\x00\x03\x4A\x6F\x65\x00\x00\x00\x00\x00'
|
||||||
'\x42\x00\x08\x01\x00\x00\x00\x30\x42\x00\x0A\x07\x00\x00\x00\x09'
|
b'\x42\x00\x08\x01\x00\x00\x00\x30\x42\x00\x0A\x07\x00\x00\x00\x09'
|
||||||
'\x78\x2D\x50\x75\x72\x70\x6F\x73\x65\x00\x00\x00\x00\x00\x00\x00'
|
b'\x78\x2D\x50\x75\x72\x70\x6F\x73\x65\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x42\x00\x0B\x07\x00\x00\x00\x0D\x64\x65\x6D\x6F\x6E\x73\x74\x72'
|
b'\x42\x00\x0B\x07\x00\x00\x00\x0D\x64\x65\x6D\x6F\x6E\x73\x74\x72'
|
||||||
'\x61\x74\x69\x6F\x6E\x00\x00\x00\x42\x00\x08\x01\x00\x00\x00\x40'
|
b'\x61\x74\x69\x6F\x6E\x00\x00\x00\x42\x00\x08\x01\x00\x00\x00\x40'
|
||||||
'\x42\x00\x0A\x07\x00\x00\x00\x04\x4E\x61\x6D\x65\x00\x00\x00\x00'
|
b'\x42\x00\x0A\x07\x00\x00\x00\x04\x4E\x61\x6D\x65\x00\x00\x00\x00'
|
||||||
'\x42\x00\x0B\x01\x00\x00\x00\x28\x42\x00\x55\x07\x00\x00\x00\x09'
|
b'\x42\x00\x0B\x01\x00\x00\x00\x28\x42\x00\x55\x07\x00\x00\x00\x09'
|
||||||
'\x54\x65\x6D\x70\x6C\x61\x74\x65\x31\x00\x00\x00\x00\x00\x00\x00'
|
b'\x54\x65\x6D\x70\x6C\x61\x74\x65\x31\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x42\x00\x54\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00')
|
b'\x42\x00\x54\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
|
||||||
|
)
|
||||||
self.get = (
|
self.get = (
|
||||||
'\x42\x00\x78\x01\x00\x00\x00\x90\x42\x00\x77\x01\x00\x00\x00\x38'
|
b'\x42\x00\x78\x01\x00\x00\x00\x90\x42\x00\x77\x01\x00\x00\x00\x38'
|
||||||
'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0D\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0D\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x48'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x48'
|
||||||
'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x0A\x00\x00\x00\x00'
|
b'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x0A\x00\x00\x00\x00'
|
||||||
'\x42\x00\x79\x01\x00\x00\x00\x30\x42\x00\x94\x07\x00\x00\x00\x24'
|
b'\x42\x00\x79\x01\x00\x00\x00\x30\x42\x00\x94\x07\x00\x00\x00\x24'
|
||||||
'\x34\x39\x61\x31\x63\x61\x38\x38\x2D\x36\x62\x65\x61\x2D\x34\x66'
|
b'\x34\x39\x61\x31\x63\x61\x38\x38\x2D\x36\x62\x65\x61\x2D\x34\x66'
|
||||||
'\x62\x32\x2D\x62\x34\x35\x30\x2D\x37\x65\x35\x38\x38\x30\x32\x63'
|
b'\x62\x32\x2D\x62\x34\x35\x30\x2D\x37\x65\x35\x38\x38\x30\x32\x63'
|
||||||
'\x33\x30\x33\x38\x00\x00\x00\x00')
|
b'\x33\x30\x33\x38\x00\x00\x00\x00')
|
||||||
self.destroy = (
|
self.destroy = (
|
||||||
'\x42\x00\x78\x01\x00\x00\x00\x90\x42\x00\x77\x01\x00\x00\x00\x38'
|
b'\x42\x00\x78\x01\x00\x00\x00\x90\x42\x00\x77\x01\x00\x00\x00\x38'
|
||||||
'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0D\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0D\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x48'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x48'
|
||||||
'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x14\x00\x00\x00\x00'
|
b'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x14\x00\x00\x00\x00'
|
||||||
'\x42\x00\x79\x01\x00\x00\x00\x30\x42\x00\x94\x07\x00\x00\x00\x24'
|
b'\x42\x00\x79\x01\x00\x00\x00\x30\x42\x00\x94\x07\x00\x00\x00\x24'
|
||||||
'\x66\x62\x34\x62\x35\x62\x39\x63\x2D\x36\x31\x38\x38\x2D\x34\x63'
|
b'\x66\x62\x34\x62\x35\x62\x39\x63\x2D\x36\x31\x38\x38\x2D\x34\x63'
|
||||||
'\x36\x33\x2D\x38\x31\x34\x32\x2D\x66\x65\x39\x63\x33\x32\x38\x31'
|
b'\x36\x33\x2D\x38\x31\x34\x32\x2D\x66\x65\x39\x63\x33\x32\x38\x31'
|
||||||
'\x32\x39\x66\x63\x00\x00\x00\x00')
|
b'\x32\x39\x66\x63\x00\x00\x00\x00')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestRequestMessage, self).tearDown()
|
super(TestRequestMessage, self).tearDown()
|
||||||
|
@ -811,71 +812,72 @@ class TestResponseMessage(TestCase):
|
||||||
self.secret_factory = SecretFactory()
|
self.secret_factory = SecretFactory()
|
||||||
self.msg = errors.ErrorStrings.BAD_EXP_RECV
|
self.msg = errors.ErrorStrings.BAD_EXP_RECV
|
||||||
self.create = (
|
self.create = (
|
||||||
'\x42\x00\x7B\x01\x00\x00\x00\xC0\x42\x00\x7A\x01\x00\x00\x00\x48'
|
b'\x42\x00\x7B\x01\x00\x00\x00\xC0\x42\x00\x7A\x01\x00\x00\x00\x48'
|
||||||
'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x92\x09\x00\x00\x00\x08'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x92\x09\x00\x00\x00\x08'
|
||||||
'\x00\x00\x00\x00\x4F\x9A\x54\xE5\x42\x00\x0D\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x00\x4F\x9A\x54\xE5\x42\x00\x0D\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x68'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x68'
|
||||||
'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
|
b'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x00'
|
||||||
'\x42\x00\x7F\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00'
|
b'\x42\x00\x7F\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x42\x00\x7C\x01\x00\x00\x00\x40\x42\x00\x57\x05\x00\x00\x00\x04'
|
b'\x42\x00\x7C\x01\x00\x00\x00\x40\x42\x00\x57\x05\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x02\x00\x00\x00\x00\x42\x00\x94\x07\x00\x00\x00\x24'
|
b'\x00\x00\x00\x02\x00\x00\x00\x00\x42\x00\x94\x07\x00\x00\x00\x24'
|
||||||
'\x66\x62\x34\x62\x35\x62\x39\x63\x2D\x36\x31\x38\x38\x2D\x34\x63'
|
b'\x66\x62\x34\x62\x35\x62\x39\x63\x2D\x36\x31\x38\x38\x2D\x34\x63'
|
||||||
'\x36\x33\x2D\x38\x31\x34\x32\x2D\x66\x65\x39\x63\x33\x32\x38\x31'
|
b'\x36\x33\x2D\x38\x31\x34\x32\x2D\x66\x65\x39\x63\x33\x32\x38\x31'
|
||||||
'\x32\x39\x66\x63\x00\x00\x00\x00')
|
b'\x32\x39\x66\x63\x00\x00\x00\x00')
|
||||||
self.register = (
|
self.register = (
|
||||||
'\x42\x00\x7B\x01\x00\x00\x00\xB0\x42\x00\x7A\x01\x00\x00\x00\x48'
|
b'\x42\x00\x7B\x01\x00\x00\x00\xB0\x42\x00\x7A\x01\x00\x00\x00\x48'
|
||||||
'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x92\x09\x00\x00\x00\x08'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x92\x09\x00\x00\x00\x08'
|
||||||
'\x00\x00\x00\x00\x4F\x9A\x54\xE5\x42\x00\x0D\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x00\x4F\x9A\x54\xE5\x42\x00\x0D\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x58'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x58'
|
||||||
'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00'
|
b'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x00'
|
||||||
'\x42\x00\x7F\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00'
|
b'\x42\x00\x7F\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x42\x00\x7C\x01\x00\x00\x00\x30\x42\x00\x94\x07\x00\x00\x00\x24'
|
b'\x42\x00\x7C\x01\x00\x00\x00\x30\x42\x00\x94\x07\x00\x00\x00\x24'
|
||||||
'\x35\x63\x39\x62\x38\x31\x65\x66\x2D\x34\x65\x65\x35\x2D\x34\x32'
|
b'\x35\x63\x39\x62\x38\x31\x65\x66\x2D\x34\x65\x65\x35\x2D\x34\x32'
|
||||||
'\x63\x64\x2D\x62\x61\x32\x64\x2D\x63\x30\x30\x32\x66\x64\x64\x30'
|
b'\x63\x64\x2D\x62\x61\x32\x64\x2D\x63\x30\x30\x32\x66\x64\x64\x30'
|
||||||
'\x63\x37\x62\x33\x00\x00\x00\x00')
|
b'\x63\x37\x62\x33\x00\x00\x00\x00')
|
||||||
self.get = (
|
self.get = (
|
||||||
'\x42\x00\x7B\x01\x00\x00\x01\x28\x42\x00\x7A\x01\x00\x00\x00\x48'
|
b'\x42\x00\x7B\x01\x00\x00\x01\x28\x42\x00\x7A\x01\x00\x00\x00\x48'
|
||||||
'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x92\x09\x00\x00\x00\x08'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x92\x09\x00\x00\x00\x08'
|
||||||
'\x00\x00\x00\x00\x4F\x9A\x54\xE7\x42\x00\x0D\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x00\x4F\x9A\x54\xE7\x42\x00\x0D\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\xD0'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\xD0'
|
||||||
'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x0A\x00\x00\x00\x00'
|
b'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x0A\x00\x00\x00\x00'
|
||||||
'\x42\x00\x7F\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00'
|
b'\x42\x00\x7F\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x42\x00\x7C\x01\x00\x00\x00\xA8\x42\x00\x57\x05\x00\x00\x00\x04'
|
b'\x42\x00\x7C\x01\x00\x00\x00\xA8\x42\x00\x57\x05\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x02\x00\x00\x00\x00\x42\x00\x94\x07\x00\x00\x00\x24'
|
b'\x00\x00\x00\x02\x00\x00\x00\x00\x42\x00\x94\x07\x00\x00\x00\x24'
|
||||||
'\x34\x39\x61\x31\x63\x61\x38\x38\x2D\x36\x62\x65\x61\x2D\x34\x66'
|
b'\x34\x39\x61\x31\x63\x61\x38\x38\x2D\x36\x62\x65\x61\x2D\x34\x66'
|
||||||
'\x62\x32\x2D\x62\x34\x35\x30\x2D\x37\x65\x35\x38\x38\x30\x32\x63'
|
b'\x62\x32\x2D\x62\x34\x35\x30\x2D\x37\x65\x35\x38\x38\x30\x32\x63'
|
||||||
'\x33\x30\x33\x38\x00\x00\x00\x00\x42\x00\x8F\x01\x00\x00\x00\x60'
|
b'\x33\x30\x33\x38\x00\x00\x00\x00\x42\x00\x8F\x01\x00\x00\x00\x60'
|
||||||
'\x42\x00\x40\x01\x00\x00\x00\x58\x42\x00\x42\x05\x00\x00\x00\x04'
|
b'\x42\x00\x40\x01\x00\x00\x00\x58\x42\x00\x42\x05\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x45\x01\x00\x00\x00\x20'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x45\x01\x00\x00\x00\x20'
|
||||||
'\x42\x00\x43\x08\x00\x00\x00\x18\x73\x67\x57\x80\x51\x01\x2A\x6D'
|
b'\x42\x00\x43\x08\x00\x00\x00\x18\x73\x67\x57\x80\x51\x01\x2A\x6D'
|
||||||
'\x13\x4A\x85\x5E\x25\xC8\xCD\x5E\x4C\xA1\x31\x45\x57\x29\xD3\xC8'
|
b'\x13\x4A\x85\x5E\x25\xC8\xCD\x5E\x4C\xA1\x31\x45\x57\x29\xD3\xC8'
|
||||||
'\x42\x00\x28\x05\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x00'
|
b'\x42\x00\x28\x05\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x00'
|
||||||
'\x42\x00\x2A\x02\x00\x00\x00\x04\x00\x00\x00\xA8\x00\x00\x00\x00')
|
b'\x42\x00\x2A\x02\x00\x00\x00\x04\x00\x00\x00\xA8\x00\x00\x00\x00'
|
||||||
|
)
|
||||||
self.destroy = (
|
self.destroy = (
|
||||||
'\x42\x00\x7B\x01\x00\x00\x00\xB0\x42\x00\x7A\x01\x00\x00\x00\x48'
|
b'\x42\x00\x7B\x01\x00\x00\x00\xB0\x42\x00\x7A\x01\x00\x00\x00\x48'
|
||||||
'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
b'\x42\x00\x69\x01\x00\x00\x00\x20\x42\x00\x6A\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x6B\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x92\x09\x00\x00\x00\x08'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x92\x09\x00\x00\x00\x08'
|
||||||
'\x00\x00\x00\x00\x4F\x9A\x54\xE5\x42\x00\x0D\x02\x00\x00\x00\x04'
|
b'\x00\x00\x00\x00\x4F\x9A\x54\xE5\x42\x00\x0D\x02\x00\x00\x00\x04'
|
||||||
'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x58'
|
b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x0F\x01\x00\x00\x00\x58'
|
||||||
'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x14\x00\x00\x00\x00'
|
b'\x42\x00\x5C\x05\x00\x00\x00\x04\x00\x00\x00\x14\x00\x00\x00\x00'
|
||||||
'\x42\x00\x7F\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00'
|
b'\x42\x00\x7F\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x42\x00\x7C\x01\x00\x00\x00\x30\x42\x00\x94\x07\x00\x00\x00\x24'
|
b'\x42\x00\x7C\x01\x00\x00\x00\x30\x42\x00\x94\x07\x00\x00\x00\x24'
|
||||||
'\x66\x62\x34\x62\x35\x62\x39\x63\x2D\x36\x31\x38\x38\x2D\x34\x63'
|
b'\x66\x62\x34\x62\x35\x62\x39\x63\x2D\x36\x31\x38\x38\x2D\x34\x63'
|
||||||
'\x36\x33\x2D\x38\x31\x34\x32\x2D\x66\x65\x39\x63\x33\x32\x38\x31'
|
b'\x36\x33\x2D\x38\x31\x34\x32\x2D\x66\x65\x39\x63\x33\x32\x38\x31'
|
||||||
'\x32\x39\x66\x63\x00\x00\x00\x00')
|
b'\x32\x39\x66\x63\x00\x00\x00\x00')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestResponseMessage, self).tearDown()
|
super(TestResponseMessage, self).tearDown()
|
||||||
|
|
||||||
def test_create_response_read(self):
|
def test_create_response_read(self):
|
||||||
self.stream = BytearrayStream(str(self.create))
|
self.stream = BytearrayStream(self.create)
|
||||||
|
|
||||||
response_message = messages.ResponseMessage()
|
response_message = messages.ResponseMessage()
|
||||||
response_message.read(self.stream)
|
response_message.read(self.stream)
|
||||||
|
@ -1025,7 +1027,7 @@ class TestResponseMessage(TestCase):
|
||||||
self.assertEqual(self.create, result, msg)
|
self.assertEqual(self.create, result, msg)
|
||||||
|
|
||||||
def test_get_response_read(self):
|
def test_get_response_read(self):
|
||||||
self.stream = BytearrayStream(str(self.get))
|
self.stream = BytearrayStream(self.get)
|
||||||
|
|
||||||
response_message = messages.ResponseMessage()
|
response_message = messages.ResponseMessage()
|
||||||
response_message.read(self.stream)
|
response_message.read(self.stream)
|
||||||
|
@ -1163,9 +1165,9 @@ class TestResponseMessage(TestCase):
|
||||||
type(key_value)))
|
type(key_value)))
|
||||||
|
|
||||||
key_material = key_value.key_value.key_material
|
key_material = key_value.key_value.key_material
|
||||||
value = bytearray('\x73\x67\x57\x80\x51\x01\x2A\x6D\x13\x4A\x85'
|
value = bytearray(b'\x73\x67\x57\x80\x51\x01\x2A\x6D\x13\x4A\x85'
|
||||||
'\x5E\x25\xC8\xCD\x5E\x4C\xA1\x31\x45\x57\x29'
|
b'\x5E\x25\xC8\xCD\x5E\x4C\xA1\x31\x45\x57\x29'
|
||||||
'\xD3\xC8')
|
b'\xD3\xC8')
|
||||||
self.assertIsInstance(key_material, RawKey,
|
self.assertIsInstance(key_material, RawKey,
|
||||||
self.msg.format('key_material', 'type',
|
self.msg.format('key_material', 'type',
|
||||||
RawKey,
|
RawKey,
|
||||||
|
@ -1217,8 +1219,8 @@ class TestResponseMessage(TestCase):
|
||||||
uniq_id = attr.UniqueIdentifier(uuid)
|
uniq_id = attr.UniqueIdentifier(uuid)
|
||||||
|
|
||||||
key_type = enums.KeyFormatType.RAW
|
key_type = enums.KeyFormatType.RAW
|
||||||
key = bytearray('\x73\x67\x57\x80\x51\x01\x2A\x6D\x13\x4A\x85\x5E\x25'
|
key = bytearray(b'\x73\x67\x57\x80\x51\x01\x2A\x6D\x13\x4A\x85\x5E\x25'
|
||||||
'\xC8\xCD\x5E\x4C\xA1\x31\x45\x57\x29\xD3\xC8')
|
b'\xC8\xCD\x5E\x4C\xA1\x31\x45\x57\x29\xD3\xC8')
|
||||||
|
|
||||||
crypto_algorithm = enums.CryptographicAlgorithm.TRIPLE_DES
|
crypto_algorithm = enums.CryptographicAlgorithm.TRIPLE_DES
|
||||||
cryptographic_length = 168
|
cryptographic_length = 168
|
||||||
|
@ -1246,8 +1248,8 @@ class TestResponseMessage(TestCase):
|
||||||
len_exp, len_rcv))
|
len_exp, len_rcv))
|
||||||
|
|
||||||
msg = "Bad get response message write: encoding mismatch"
|
msg = "Bad get response message write: encoding mismatch"
|
||||||
print self.get
|
print(self.get)
|
||||||
print result
|
print(result)
|
||||||
self.assertEqual(self.get, result, msg)
|
self.assertEqual(self.get, result, msg)
|
||||||
|
|
||||||
def test_destroy_response_read(self):
|
def test_destroy_response_read(self):
|
||||||
|
|
|
@ -56,36 +56,36 @@ class TestBase(TestCase):
|
||||||
base.is_oversized(self.stream)
|
base.is_oversized(self.stream)
|
||||||
|
|
||||||
def test_is_oversized_error(self):
|
def test_is_oversized_error(self):
|
||||||
self.stream.write('\x00')
|
self.stream.write(b'\x00')
|
||||||
base = Base()
|
base = Base()
|
||||||
|
|
||||||
self.assertRaises(errors.StreamNotEmptyError, base.is_oversized,
|
self.assertRaises(errors.StreamNotEmptyError, base.is_oversized,
|
||||||
self.stream)
|
self.stream)
|
||||||
|
|
||||||
def test_read_tag(self):
|
def test_read_tag(self):
|
||||||
encoding = ('\x42\x00\x00')
|
encoding = (b'\x42\x00\x00')
|
||||||
base = Base()
|
base = Base()
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
|
|
||||||
# Check no exception thrown
|
# Check no exception thrown
|
||||||
base.read_tag(self.stream)
|
base.read_tag(self.stream)
|
||||||
|
|
||||||
def test_read_tag_invalid(self):
|
def test_read_tag_invalid(self):
|
||||||
encoding = ('\x42\x00\x01')
|
encoding = (b'\x42\x00\x01')
|
||||||
base = Base()
|
base = Base()
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
|
|
||||||
self.assertRaises(errors.ReadValueError, base.read_tag, self.stream)
|
self.assertRaises(errors.ReadValueError, base.read_tag, self.stream)
|
||||||
|
|
||||||
def test_read_type(self):
|
def test_read_type(self):
|
||||||
self.stream.write('\x00')
|
self.stream.write(b'\x00')
|
||||||
base = Base()
|
base = Base()
|
||||||
|
|
||||||
# Check no exception thrown
|
# Check no exception thrown
|
||||||
base.read_type(self.stream)
|
base.read_type(self.stream)
|
||||||
|
|
||||||
def test_read_type_error(self):
|
def test_read_type_error(self):
|
||||||
self.stream.write('\x01')
|
self.stream.write(b'\x01')
|
||||||
base = Base()
|
base = Base()
|
||||||
|
|
||||||
self.assertRaises(errors.ReadValueError, base.read_type, self.stream)
|
self.assertRaises(errors.ReadValueError, base.read_type, self.stream)
|
||||||
|
@ -97,14 +97,14 @@ class TestBase(TestCase):
|
||||||
self.stream)
|
self.stream)
|
||||||
|
|
||||||
def test_read_type_overflow(self):
|
def test_read_type_overflow(self):
|
||||||
self.stream.write('\x00\x00')
|
self.stream.write(b'\x00\x00')
|
||||||
base = Base()
|
base = Base()
|
||||||
|
|
||||||
# Check no exception thrown
|
# Check no exception thrown
|
||||||
base.read_type(self.stream)
|
base.read_type(self.stream)
|
||||||
|
|
||||||
def test_read_length(self):
|
def test_read_length(self):
|
||||||
self.stream.write('\x00\x00\x00\x04')
|
self.stream.write(b'\x00\x00\x00\x04')
|
||||||
base = Base()
|
base = Base()
|
||||||
base.length = 4
|
base.length = 4
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ class TestBase(TestCase):
|
||||||
base.read_length(self.stream)
|
base.read_length(self.stream)
|
||||||
|
|
||||||
def test_read_length_error(self):
|
def test_read_length_error(self):
|
||||||
self.stream.write('\x00\x00\x00\x00')
|
self.stream.write(b'\x00\x00\x00\x00')
|
||||||
base = Base()
|
base = Base()
|
||||||
base.length = 4
|
base.length = 4
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ class TestBase(TestCase):
|
||||||
self.stream)
|
self.stream)
|
||||||
|
|
||||||
def test_read_length_underflow(self):
|
def test_read_length_underflow(self):
|
||||||
self.stream.write('\x00')
|
self.stream.write(b'\x00')
|
||||||
base = Base()
|
base = Base()
|
||||||
base.length = 4
|
base.length = 4
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ class TestBase(TestCase):
|
||||||
self.stream)
|
self.stream)
|
||||||
|
|
||||||
def test_read_length_overflow(self):
|
def test_read_length_overflow(self):
|
||||||
self.stream.write('\x00\x00\x00\x04\x00')
|
self.stream.write(b'\x00\x00\x00\x04\x00')
|
||||||
base = Base()
|
base = Base()
|
||||||
base.length = 4
|
base.length = 4
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ class TestBase(TestCase):
|
||||||
self.assertRaises(NotImplementedError, base.read_value, self.stream)
|
self.assertRaises(NotImplementedError, base.read_value, self.stream)
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
self.stream.write('\x42\x00\x00\x00\x00\x00\x00\x04')
|
self.stream.write(b'\x42\x00\x00\x00\x00\x00\x00\x04')
|
||||||
base = Base()
|
base = Base()
|
||||||
base.length = 4
|
base.length = 4
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class TestBase(TestCase):
|
||||||
base.read(self.stream)
|
base.read(self.stream)
|
||||||
|
|
||||||
def test_write_tag(self):
|
def test_write_tag(self):
|
||||||
encoding = ('\x42\x00\x00')
|
encoding = (b'\x42\x00\x00')
|
||||||
base = Base()
|
base = Base()
|
||||||
base.write_tag(self.stream)
|
base.write_tag(self.stream)
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ class TestBase(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding.format('tag'))
|
self.assertEqual(encoding, result, self.bad_encoding.format('tag'))
|
||||||
|
|
||||||
def test_write_type(self):
|
def test_write_type(self):
|
||||||
encoding = '\x00'
|
encoding = b'\x00'
|
||||||
base = Base()
|
base = Base()
|
||||||
base.write_type(self.stream)
|
base.write_type(self.stream)
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ class TestBase(TestCase):
|
||||||
self.assertRaises(TypeError, base.write_type, self.stream)
|
self.assertRaises(TypeError, base.write_type, self.stream)
|
||||||
|
|
||||||
def test_write_length(self):
|
def test_write_length(self):
|
||||||
encoding = '\x00\x00\x00\x04'
|
encoding = b'\x00\x00\x00\x04'
|
||||||
base = Base()
|
base = Base()
|
||||||
base.length = 4
|
base.length = 4
|
||||||
base.write_length(self.stream)
|
base.write_length(self.stream)
|
||||||
|
@ -217,7 +217,7 @@ class TestBase(TestCase):
|
||||||
self.assertRaises(NotImplementedError, base.write_value, self.stream)
|
self.assertRaises(NotImplementedError, base.write_value, self.stream)
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
encoding = '\x42\x00\x00\x00\x00\x00\x00\x04'
|
encoding = b'\x42\x00\x00\x00\x00\x00\x00\x04'
|
||||||
base = Base()
|
base = Base()
|
||||||
base.length = 4
|
base.length = 4
|
||||||
base.write(self.stream)
|
base.write(self.stream)
|
||||||
|
@ -234,17 +234,17 @@ class TestBase(TestCase):
|
||||||
self.bad_encoding.format('type/length'))
|
self.bad_encoding.format('type/length'))
|
||||||
|
|
||||||
def test_is_tag_next(self):
|
def test_is_tag_next(self):
|
||||||
encoding = ('\x42\x00\x00')
|
encoding = (b'\x42\x00\x00')
|
||||||
base = Base()
|
base = Base()
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
|
|
||||||
self.assertTrue(Base.is_tag_next(base.tag, self.stream),
|
self.assertTrue(Base.is_tag_next(base.tag, self.stream),
|
||||||
self.bad_match.format('tag', 'match', 'mismatch'))
|
self.bad_match.format('tag', 'match', 'mismatch'))
|
||||||
|
|
||||||
def test_is_tag_next_invalid(self):
|
def test_is_tag_next_invalid(self):
|
||||||
encoding = ('\x42\x00\x01')
|
encoding = (b'\x42\x00\x01')
|
||||||
base = Base()
|
base = Base()
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
|
|
||||||
self.assertFalse(Base.is_tag_next(base.tag, self.stream),
|
self.assertFalse(Base.is_tag_next(base.tag, self.stream),
|
||||||
self.bad_match.format('tag', 'mismatch', 'match'))
|
self.bad_match.format('tag', 'mismatch', 'match'))
|
||||||
|
@ -313,24 +313,24 @@ class TestInteger(TestCase):
|
||||||
self.max_byte_int + 1)
|
self.max_byte_int + 1)
|
||||||
|
|
||||||
def test_read_value(self):
|
def test_read_value(self):
|
||||||
encoding = ('\x00\x00\x00\x01\x00\x00\x00\x00')
|
encoding = (b'\x00\x00\x00\x01\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = Integer()
|
i = Integer()
|
||||||
i.read_value(self.stream)
|
i.read_value(self.stream)
|
||||||
|
|
||||||
self.assertEqual(1, i.value, self.bad_read.format(1, i.value))
|
self.assertEqual(1, i.value, self.bad_read.format(1, i.value))
|
||||||
|
|
||||||
def test_read_value_zero(self):
|
def test_read_value_zero(self):
|
||||||
encoding = ('\x00\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x00\x00\x00\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = Integer()
|
i = Integer()
|
||||||
i.read_value(self.stream)
|
i.read_value(self.stream)
|
||||||
|
|
||||||
self.assertEqual(0, i.value, self.bad_read.format(0, i.value))
|
self.assertEqual(0, i.value, self.bad_read.format(0, i.value))
|
||||||
|
|
||||||
def test_read_value_max_positive(self):
|
def test_read_value_max_positive(self):
|
||||||
encoding = ('\x7f\xff\xff\xff\x00\x00\x00\x00')
|
encoding = (b'\x7f\xff\xff\xff\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = Integer()
|
i = Integer()
|
||||||
i.read_value(self.stream)
|
i.read_value(self.stream)
|
||||||
|
|
||||||
|
@ -338,8 +338,8 @@ class TestInteger(TestCase):
|
||||||
self.bad_read.format(1, i.value))
|
self.bad_read.format(1, i.value))
|
||||||
|
|
||||||
def test_read_value_min_negative(self):
|
def test_read_value_min_negative(self):
|
||||||
encoding = ('\xff\xff\xff\xff\x00\x00\x00\x00')
|
encoding = (b'\xff\xff\xff\xff\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = Integer()
|
i = Integer()
|
||||||
i.read_value(self.stream)
|
i.read_value(self.stream)
|
||||||
|
|
||||||
|
@ -347,32 +347,32 @@ class TestInteger(TestCase):
|
||||||
self.bad_read.format(1, i.value))
|
self.bad_read.format(1, i.value))
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
encoding = ('\x42\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00'
|
encoding = (b'\x42\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = Integer()
|
i = Integer()
|
||||||
i.read(self.stream)
|
i.read(self.stream)
|
||||||
|
|
||||||
self.assertEqual(1, i.value, self.bad_read.format(1, i.value))
|
self.assertEqual(1, i.value, self.bad_read.format(1, i.value))
|
||||||
|
|
||||||
def test_read_on_invalid_length(self):
|
def test_read_on_invalid_length(self):
|
||||||
encoding = ('\x42\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = Integer()
|
i = Integer()
|
||||||
|
|
||||||
self.assertRaises(errors.ReadValueError, i.read, self.stream)
|
self.assertRaises(errors.ReadValueError, i.read, self.stream)
|
||||||
|
|
||||||
def test_read_on_invalid_padding(self):
|
def test_read_on_invalid_padding(self):
|
||||||
encoding = ('\x42\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x00\xff\xff'
|
encoding = (b'\x42\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x00\xff\xff'
|
||||||
'\xff\xff')
|
b'\xff\xff')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = Integer()
|
i = Integer()
|
||||||
|
|
||||||
self.assertRaises(errors.ReadValueError, i.read, self.stream)
|
self.assertRaises(errors.ReadValueError, i.read, self.stream)
|
||||||
|
|
||||||
def test_write_value(self):
|
def test_write_value(self):
|
||||||
encoding = ('\x00\x00\x00\x01\x00\x00\x00\x00')
|
encoding = (b'\x00\x00\x00\x01\x00\x00\x00\x00')
|
||||||
i = Integer(1)
|
i = Integer(1)
|
||||||
i.write_value(self.stream)
|
i.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ class TestInteger(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_zero(self):
|
def test_write_value_zero(self):
|
||||||
encoding = ('\x00\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x00\x00\x00\x00\x00\x00\x00\x00')
|
||||||
i = Integer(0)
|
i = Integer(0)
|
||||||
i.write_value(self.stream)
|
i.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ class TestInteger(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_max_positive(self):
|
def test_write_value_max_positive(self):
|
||||||
encoding = ('\x7f\xff\xff\xff\x00\x00\x00\x00')
|
encoding = (b'\x7f\xff\xff\xff\x00\x00\x00\x00')
|
||||||
i = Integer(self.max_int)
|
i = Integer(self.max_int)
|
||||||
i.write_value(self.stream)
|
i.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ class TestInteger(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_min_negative(self):
|
def test_write_value_min_negative(self):
|
||||||
encoding = ('\xff\xff\xff\xff\x00\x00\x00\x00')
|
encoding = (b'\xff\xff\xff\xff\x00\x00\x00\x00')
|
||||||
i = Integer(-1)
|
i = Integer(-1)
|
||||||
i.write_value(self.stream)
|
i.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -424,8 +424,8 @@ class TestInteger(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
encoding = ('\x42\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00'
|
encoding = (b'\x42\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
i = Integer(1)
|
i = Integer(1)
|
||||||
i.write(self.stream)
|
i.write(self.stream)
|
||||||
|
|
||||||
|
@ -503,24 +503,24 @@ class TestLongInteger(TestCase):
|
||||||
self.max_byte_long + 1)
|
self.max_byte_long + 1)
|
||||||
|
|
||||||
def test_read_value(self):
|
def test_read_value(self):
|
||||||
encoding = ('\x00\x00\x00\x00\x00\x00\x00\x01')
|
encoding = (b'\x00\x00\x00\x00\x00\x00\x00\x01')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = LongInteger()
|
i = LongInteger()
|
||||||
i.read_value(self.stream)
|
i.read_value(self.stream)
|
||||||
|
|
||||||
self.assertEqual(1, i.value, self.bad_read.format(1, i.value))
|
self.assertEqual(1, i.value, self.bad_read.format(1, i.value))
|
||||||
|
|
||||||
def test_read_value_zero(self):
|
def test_read_value_zero(self):
|
||||||
encoding = ('\x00\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x00\x00\x00\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = LongInteger()
|
i = LongInteger()
|
||||||
i.read_value(self.stream)
|
i.read_value(self.stream)
|
||||||
|
|
||||||
self.assertEqual(0, i.value, self.bad_read.format(0, i.value))
|
self.assertEqual(0, i.value, self.bad_read.format(0, i.value))
|
||||||
|
|
||||||
def test_read_value_max_positive(self):
|
def test_read_value_max_positive(self):
|
||||||
encoding = ('\x7f\xff\xff\xff\xff\xff\xff\xff')
|
encoding = (b'\x7f\xff\xff\xff\xff\xff\xff\xff')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = LongInteger()
|
i = LongInteger()
|
||||||
i.read_value(self.stream)
|
i.read_value(self.stream)
|
||||||
|
|
||||||
|
@ -528,8 +528,8 @@ class TestLongInteger(TestCase):
|
||||||
self.bad_read.format(1, i.value))
|
self.bad_read.format(1, i.value))
|
||||||
|
|
||||||
def test_read_value_min_negative(self):
|
def test_read_value_min_negative(self):
|
||||||
encoding = ('\xff\xff\xff\xff\xff\xff\xff\xff')
|
encoding = (b'\xff\xff\xff\xff\xff\xff\xff\xff')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = LongInteger()
|
i = LongInteger()
|
||||||
i.read_value(self.stream)
|
i.read_value(self.stream)
|
||||||
|
|
||||||
|
@ -537,24 +537,24 @@ class TestLongInteger(TestCase):
|
||||||
self.bad_read.format(1, i.value))
|
self.bad_read.format(1, i.value))
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
encoding = ('\x42\x00\x00\x03\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x00\x03\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x01')
|
b'\x00\x01')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = LongInteger()
|
i = LongInteger()
|
||||||
i.read(self.stream)
|
i.read(self.stream)
|
||||||
|
|
||||||
self.assertEqual(1, i.value, self.bad_read.format(1, i.value))
|
self.assertEqual(1, i.value, self.bad_read.format(1, i.value))
|
||||||
|
|
||||||
def test_read_on_invalid_length(self):
|
def test_read_on_invalid_length(self):
|
||||||
encoding = ('\x42\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = LongInteger()
|
i = LongInteger()
|
||||||
|
|
||||||
self.assertRaises(errors.ReadValueError, i.read, self.stream)
|
self.assertRaises(errors.ReadValueError, i.read, self.stream)
|
||||||
|
|
||||||
def test_write_value(self):
|
def test_write_value(self):
|
||||||
encoding = ('\x00\x00\x00\x00\x00\x00\x00\x01')
|
encoding = (b'\x00\x00\x00\x00\x00\x00\x00\x01')
|
||||||
i = LongInteger(1)
|
i = LongInteger(1)
|
||||||
i.write_value(self.stream)
|
i.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -567,7 +567,7 @@ class TestLongInteger(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_zero(self):
|
def test_write_value_zero(self):
|
||||||
encoding = ('\x00\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x00\x00\x00\x00\x00\x00\x00\x00')
|
||||||
i = LongInteger(0)
|
i = LongInteger(0)
|
||||||
i.write_value(self.stream)
|
i.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -580,7 +580,7 @@ class TestLongInteger(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_max_positive(self):
|
def test_write_value_max_positive(self):
|
||||||
encoding = ('\x7f\xff\xff\xff\xff\xff\xff\xff')
|
encoding = (b'\x7f\xff\xff\xff\xff\xff\xff\xff')
|
||||||
i = LongInteger(self.max_long)
|
i = LongInteger(self.max_long)
|
||||||
i.write_value(self.stream)
|
i.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -593,7 +593,7 @@ class TestLongInteger(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_min_negative(self):
|
def test_write_value_min_negative(self):
|
||||||
encoding = ('\xff\xff\xff\xff\xff\xff\xff\xff')
|
encoding = (b'\xff\xff\xff\xff\xff\xff\xff\xff')
|
||||||
i = LongInteger(-1)
|
i = LongInteger(-1)
|
||||||
i.write_value(self.stream)
|
i.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -606,8 +606,8 @@ class TestLongInteger(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
encoding = ('\x42\x00\x00\x03\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x00\x03\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x01')
|
b'\x00\x01')
|
||||||
i = LongInteger(1)
|
i = LongInteger(1)
|
||||||
i.write(self.stream)
|
i.write(self.stream)
|
||||||
|
|
||||||
|
@ -699,8 +699,8 @@ class TestBigInteger(TestCase):
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
self.skip('BigInteger implementation incomplete')
|
self.skip('BigInteger implementation incomplete')
|
||||||
encoding = ('\x42\x00\x01\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x01\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x01')
|
b'\x00\x01')
|
||||||
i = BigInteger(1)
|
i = BigInteger(1)
|
||||||
i.TAG = Tags.ACTIVATION_DATE
|
i.TAG = Tags.ACTIVATION_DATE
|
||||||
i.write(self.stream)
|
i.write(self.stream)
|
||||||
|
@ -715,8 +715,8 @@ class TestBigInteger(TestCase):
|
||||||
|
|
||||||
def test_write_zero(self):
|
def test_write_zero(self):
|
||||||
self.skip('BigInteger implementation incomplete')
|
self.skip('BigInteger implementation incomplete')
|
||||||
encoding = ('\x42\x00\x01\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x01\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
i = BigInteger(0)
|
i = BigInteger(0)
|
||||||
i.TAG = Tags.ACTIVATION_DATE
|
i.TAG = Tags.ACTIVATION_DATE
|
||||||
i.write(self.stream)
|
i.write(self.stream)
|
||||||
|
@ -731,8 +731,8 @@ class TestBigInteger(TestCase):
|
||||||
|
|
||||||
def test_write_max_positive_value(self):
|
def test_write_max_positive_value(self):
|
||||||
self.skip('BigInteger implementation incomplete')
|
self.skip('BigInteger implementation incomplete')
|
||||||
encoding = ('\x42\x00\x01\x04\x00\x00\x00\x08\x7f\xff\xff\xff\xff\xff'
|
encoding = (b'\x42\x00\x01\x04\x00\x00\x00\x08\x7f\xff\xff\xff\xff\xff'
|
||||||
'\xff\xff')
|
b'\xff\xff')
|
||||||
i = BigInteger(self.max_long)
|
i = BigInteger(self.max_long)
|
||||||
i.TAG = Tags.ACTIVATION_DATE
|
i.TAG = Tags.ACTIVATION_DATE
|
||||||
i.write(self.stream)
|
i.write(self.stream)
|
||||||
|
@ -747,8 +747,8 @@ class TestBigInteger(TestCase):
|
||||||
|
|
||||||
def test_write_min_negative_value(self):
|
def test_write_min_negative_value(self):
|
||||||
self.skip('BigInteger implementation incomplete')
|
self.skip('BigInteger implementation incomplete')
|
||||||
encoding = ('\x42\x00\x01\x04\x00\x00\x00\x08\xff\xff\xff\xff\xff\xff'
|
encoding = (b'\x42\x00\x01\x04\x00\x00\x00\x08\xff\xff\xff\xff\xff\xff'
|
||||||
'\xff\xff')
|
b'\xff\xff')
|
||||||
i = BigInteger(-1)
|
i = BigInteger(-1)
|
||||||
i.TAG = Tags.ACTIVATION_DATE
|
i.TAG = Tags.ACTIVATION_DATE
|
||||||
i.write(self.stream)
|
i.write(self.stream)
|
||||||
|
@ -763,9 +763,9 @@ class TestBigInteger(TestCase):
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
self.skip('BigInteger implementation incomplete')
|
self.skip('BigInteger implementation incomplete')
|
||||||
encoding = ('\x42\x00\x01\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x01\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x01')
|
b'\x00\x01')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = BigInteger()
|
i = BigInteger()
|
||||||
i.TAG = Tags.ACTIVATION_DATE
|
i.TAG = Tags.ACTIVATION_DATE
|
||||||
i.read(self.stream)
|
i.read(self.stream)
|
||||||
|
@ -774,9 +774,9 @@ class TestBigInteger(TestCase):
|
||||||
|
|
||||||
def test_read_zero(self):
|
def test_read_zero(self):
|
||||||
self.skip('BigInteger implementation incomplete')
|
self.skip('BigInteger implementation incomplete')
|
||||||
encoding = ('\x42\x00\x01\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x01\x04\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = BigInteger()
|
i = BigInteger()
|
||||||
i.TAG = Tags.ACTIVATION_DATE
|
i.TAG = Tags.ACTIVATION_DATE
|
||||||
i.read(self.stream)
|
i.read(self.stream)
|
||||||
|
@ -785,9 +785,9 @@ class TestBigInteger(TestCase):
|
||||||
|
|
||||||
def test_read_max_positive_value(self):
|
def test_read_max_positive_value(self):
|
||||||
self.skip('BigInteger implementation incomplete')
|
self.skip('BigInteger implementation incomplete')
|
||||||
encoding = ('\x42\x00\x01\x04\x00\x00\x00\x08\x7f\xff\xff\xff\xff\xff'
|
encoding = (b'\x42\x00\x01\x04\x00\x00\x00\x08\x7f\xff\xff\xff\xff\xff'
|
||||||
'\xff\xff')
|
b'\xff\xff')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = BigInteger()
|
i = BigInteger()
|
||||||
i.TAG = Tags.ACTIVATION_DATE
|
i.TAG = Tags.ACTIVATION_DATE
|
||||||
i.read(self.stream)
|
i.read(self.stream)
|
||||||
|
@ -797,9 +797,9 @@ class TestBigInteger(TestCase):
|
||||||
|
|
||||||
def test_read_min_negative_value(self):
|
def test_read_min_negative_value(self):
|
||||||
self.skip('BigInteger implementation incomplete')
|
self.skip('BigInteger implementation incomplete')
|
||||||
encoding = ('\x42\x00\x01\x04\x00\x00\x00\x08\xff\xff\xff\xff\xff\xff'
|
encoding = (b'\x42\x00\x01\x04\x00\x00\x00\x08\xff\xff\xff\xff\xff\xff'
|
||||||
'\xff\xff')
|
b'\xff\xff')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = BigInteger()
|
i = BigInteger()
|
||||||
i.TAG = Tags.ACTIVATION_DATE
|
i.TAG = Tags.ACTIVATION_DATE
|
||||||
i.read(self.stream)
|
i.read(self.stream)
|
||||||
|
@ -809,9 +809,9 @@ class TestBigInteger(TestCase):
|
||||||
|
|
||||||
def test_read_on_invalid_length(self):
|
def test_read_on_invalid_length(self):
|
||||||
self.skip('BigInteger implementation incomplete')
|
self.skip('BigInteger implementation incomplete')
|
||||||
encoding = ('\x42\x00\x01\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x01\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
i = BigInteger()
|
i = BigInteger()
|
||||||
i.TAG = Tags.ACTIVATION_DATE
|
i.TAG = Tags.ACTIVATION_DATE
|
||||||
|
|
||||||
|
@ -881,9 +881,9 @@ class TestEnumeration(TestCase):
|
||||||
self.assertRaises(TypeError, e.validate)
|
self.assertRaises(TypeError, e.validate)
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
encoding = ('\x42\x00\x00\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x00\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
e = Enumeration()
|
e = Enumeration()
|
||||||
e.read(self.stream)
|
e.read(self.stream)
|
||||||
|
|
||||||
|
@ -899,8 +899,8 @@ class TestEnumeration(TestCase):
|
||||||
e.value))
|
e.value))
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
encoding = ('\x42\x00\x00\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00'
|
encoding = (b'\x42\x00\x00\x05\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
e = Enumeration(Types.DEFAULT)
|
e = Enumeration(Types.DEFAULT)
|
||||||
e.write(self.stream)
|
e.write(self.stream)
|
||||||
|
|
||||||
|
@ -1013,9 +1013,9 @@ class TestTextString(TestCase):
|
||||||
self.assertRaises(TypeError, ts.validate)
|
self.assertRaises(TypeError, ts.validate)
|
||||||
|
|
||||||
def test_read_value(self):
|
def test_read_value(self):
|
||||||
encoding = ('\x48\x65\x6C\x6C\x6F\x20\x57\x6F\x72\x6C\x64\x00\x00\x00'
|
encoding = (b'\x48\x65\x6C\x6C\x6F\x20\x57\x6F\x72\x6C\x64\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
ts = TextString()
|
ts = TextString()
|
||||||
ts.length = 0x0B
|
ts.length = 0x0B
|
||||||
ts.read_value(self.stream)
|
ts.read_value(self.stream)
|
||||||
|
@ -1025,8 +1025,8 @@ class TestTextString(TestCase):
|
||||||
self.bad_read.format('value', expected, ts.value))
|
self.bad_read.format('value', expected, ts.value))
|
||||||
|
|
||||||
def test_read_value_no_padding(self):
|
def test_read_value_no_padding(self):
|
||||||
encoding = ('\x48\x65\x6C\x6C\x6F\x20\x57\x6F')
|
encoding = (b'\x48\x65\x6C\x6C\x6F\x20\x57\x6F')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
ts = TextString()
|
ts = TextString()
|
||||||
ts.length = 0x08
|
ts.length = 0x08
|
||||||
ts.read_value(self.stream)
|
ts.read_value(self.stream)
|
||||||
|
@ -1036,8 +1036,8 @@ class TestTextString(TestCase):
|
||||||
self.bad_read.format('value', expected, ts.value))
|
self.bad_read.format('value', expected, ts.value))
|
||||||
|
|
||||||
def test_read_value_max_padding(self):
|
def test_read_value_max_padding(self):
|
||||||
encoding = ('\x48\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x48\x00\x00\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
ts = TextString()
|
ts = TextString()
|
||||||
ts.length = 0x01
|
ts.length = 0x01
|
||||||
ts.read_value(self.stream)
|
ts.read_value(self.stream)
|
||||||
|
@ -1047,9 +1047,9 @@ class TestTextString(TestCase):
|
||||||
self.bad_read.format('value', expected, ts.value))
|
self.bad_read.format('value', expected, ts.value))
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
encoding = ('\x42\x00\x00\x07\x00\x00\x00\x0B\x48\x65\x6C\x6C\x6F\x20'
|
encoding = (b'\x42\x00\x00\x07\x00\x00\x00\x0B\x48\x65\x6C\x6C\x6F\x20'
|
||||||
'\x57\x6F\x72\x6C\x64\x00\x00\x00\x00\x00')
|
b'\x57\x6F\x72\x6C\x64\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
ts = TextString()
|
ts = TextString()
|
||||||
ts.read(self.stream)
|
ts.read(self.stream)
|
||||||
|
|
||||||
|
@ -1058,16 +1058,16 @@ class TestTextString(TestCase):
|
||||||
self.bad_read.format('value', expected, ts.value))
|
self.bad_read.format('value', expected, ts.value))
|
||||||
|
|
||||||
def test_read_on_invalid_padding(self):
|
def test_read_on_invalid_padding(self):
|
||||||
encoding = ('\x42\x00\x00\x07\x00\x00\x00\x0B\x48\x65\x6C\x6C\x6F\x20'
|
encoding = (b'\x42\x00\x00\x07\x00\x00\x00\x0B\x48\x65\x6C\x6C\x6F\x20'
|
||||||
'\x57\x6F\x72\x6C\x64\xff\xff\xff\xff\xff')
|
b'\x57\x6F\x72\x6C\x64\xff\xff\xff\xff\xff')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
ts = TextString()
|
ts = TextString()
|
||||||
|
|
||||||
self.assertRaises(errors.ReadValueError, ts.read, self.stream)
|
self.assertRaises(errors.ReadValueError, ts.read, self.stream)
|
||||||
|
|
||||||
def test_write_value(self):
|
def test_write_value(self):
|
||||||
encoding = ('\x48\x65\x6C\x6C\x6F\x20\x57\x6F\x72\x6C\x64\x00\x00\x00'
|
encoding = (b'\x48\x65\x6C\x6C\x6F\x20\x57\x6F\x72\x6C\x64\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream()
|
self.stream = BytearrayStream()
|
||||||
value = 'Hello World'
|
value = 'Hello World'
|
||||||
ts = TextString(value)
|
ts = TextString(value)
|
||||||
|
@ -1082,7 +1082,7 @@ class TestTextString(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_no_padding(self):
|
def test_write_value_no_padding(self):
|
||||||
encoding = ('\x48\x65\x6C\x6C\x6F\x20\x57\x6F')
|
encoding = (b'\x48\x65\x6C\x6C\x6F\x20\x57\x6F')
|
||||||
self.stream = BytearrayStream()
|
self.stream = BytearrayStream()
|
||||||
value = 'Hello Wo'
|
value = 'Hello Wo'
|
||||||
ts = TextString(value)
|
ts = TextString(value)
|
||||||
|
@ -1097,7 +1097,7 @@ class TestTextString(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_max_padding(self):
|
def test_write_value_max_padding(self):
|
||||||
encoding = ('\x48\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x48\x00\x00\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream()
|
self.stream = BytearrayStream()
|
||||||
value = 'H'
|
value = 'H'
|
||||||
ts = TextString(value)
|
ts = TextString(value)
|
||||||
|
@ -1112,8 +1112,8 @@ class TestTextString(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
encoding = ('\x42\x00\x00\x07\x00\x00\x00\x0B\x48\x65\x6C\x6C\x6F\x20'
|
encoding = (b'\x42\x00\x00\x07\x00\x00\x00\x0B\x48\x65\x6C\x6C\x6F\x20'
|
||||||
'\x57\x6F\x72\x6C\x64\x00\x00\x00\x00\x00')
|
b'\x57\x6F\x72\x6C\x64\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream()
|
self.stream = BytearrayStream()
|
||||||
value = 'Hello World'
|
value = 'Hello World'
|
||||||
ts = TextString(value)
|
ts = TextString(value)
|
||||||
|
@ -1153,7 +1153,7 @@ class TestByteString(TestCase):
|
||||||
super(self.__class__, self).tearDown()
|
super(self.__class__, self).tearDown()
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
value = bytearray('\x01\x02\x03')
|
value = bytearray(b'\x01\x02\x03')
|
||||||
bs = ByteString(value)
|
bs = ByteString(value)
|
||||||
|
|
||||||
self.assertIsInstance(bs.value, bytearray,
|
self.assertIsInstance(bs.value, bytearray,
|
||||||
|
@ -1173,7 +1173,7 @@ class TestByteString(TestCase):
|
||||||
|
|
||||||
def test_validate_on_valid(self):
|
def test_validate_on_valid(self):
|
||||||
bs = ByteString()
|
bs = ByteString()
|
||||||
bs.value = bytearray('\x00')
|
bs.value = bytearray(b'\x00')
|
||||||
|
|
||||||
# Check no exception thrown.
|
# Check no exception thrown.
|
||||||
bs.validate()
|
bs.validate()
|
||||||
|
@ -1191,72 +1191,72 @@ class TestByteString(TestCase):
|
||||||
self.assertRaises(TypeError, bs.validate)
|
self.assertRaises(TypeError, bs.validate)
|
||||||
|
|
||||||
def test_read_value(self):
|
def test_read_value(self):
|
||||||
encoding = ('\x01\x02\x03\x00\x00\x00\x00\x00')
|
encoding = (b'\x01\x02\x03\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
bs = ByteString()
|
bs = ByteString()
|
||||||
bs.length = 0x03
|
bs.length = 0x03
|
||||||
bs.read_value(self.stream)
|
bs.read_value(self.stream)
|
||||||
|
|
||||||
expected = bytearray('\x01\x02\x03')
|
expected = b'\x01\x02\x03'
|
||||||
self.assertEqual(expected, bs.value,
|
self.assertEqual(expected, bs.value,
|
||||||
self.bad_read.format('value', expected, bs.value))
|
self.bad_read.format('value', expected, bs.value))
|
||||||
|
|
||||||
def test_read_value_no_padding(self):
|
def test_read_value_no_padding(self):
|
||||||
encoding = ('\x01\x02\x03\x04\x05\x06\x07\x08')
|
encoding = (b'\x01\x02\x03\x04\x05\x06\x07\x08')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
bs = ByteString()
|
bs = ByteString()
|
||||||
bs.length = 0x08
|
bs.length = 0x08
|
||||||
bs.read_value(self.stream)
|
bs.read_value(self.stream)
|
||||||
|
|
||||||
expected = bytearray('\x01\x02\x03\x04\x05\x06\x07\x08')
|
expected = b'\x01\x02\x03\x04\x05\x06\x07\x08'
|
||||||
self.assertEqual(expected, bs.value,
|
self.assertEqual(expected, bs.value,
|
||||||
self.bad_read.format('value', expected, bs.value))
|
self.bad_read.format('value', expected, bs.value))
|
||||||
|
|
||||||
def test_read_value_max_padding(self):
|
def test_read_value_max_padding(self):
|
||||||
encoding = ('\x01\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x01\x00\x00\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
bs = ByteString()
|
bs = ByteString()
|
||||||
bs.length = 0x01
|
bs.length = 0x01
|
||||||
bs.read_value(self.stream)
|
bs.read_value(self.stream)
|
||||||
|
|
||||||
expected = bytearray('\x01')
|
expected = bytearray(b'\x01')
|
||||||
self.assertEqual(expected, bs.value,
|
self.assertEqual(expected, bs.value,
|
||||||
self.bad_read.format('value', expected, bs.value))
|
self.bad_read.format('value', expected, bs.value))
|
||||||
|
|
||||||
def test_read_value_zero(self):
|
def test_read_value_zero(self):
|
||||||
encoding = ('\x00\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x00\x00\x00\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
bs = ByteString()
|
bs = ByteString()
|
||||||
bs.length = 0x01
|
bs.length = 0x01
|
||||||
bs.read_value(self.stream)
|
bs.read_value(self.stream)
|
||||||
|
|
||||||
expected = bytearray('\x00')
|
expected = bytearray(b'\x00')
|
||||||
self.assertEqual(expected, bs.value,
|
self.assertEqual(expected, bs.value,
|
||||||
self.bad_read.format('value', expected, bs.value))
|
self.bad_read.format('value', expected, bs.value))
|
||||||
|
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
encoding = ('\x42\x00\x00\x08\x00\x00\x00\x03\x01\x02\x03\x00\x00\x00'
|
encoding = (b'\x42\x00\x00\x08\x00\x00\x00\x03\x01\x02\x03\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
bs = ByteString()
|
bs = ByteString()
|
||||||
bs.read(self.stream)
|
bs.read(self.stream)
|
||||||
|
|
||||||
expected = bytearray('\x01\x02\x03')
|
expected = bytearray(b'\x01\x02\x03')
|
||||||
self.assertEqual(expected, bs.value,
|
self.assertEqual(expected, bs.value,
|
||||||
self.bad_read.format('value', expected, bs.value))
|
self.bad_read.format('value', expected, bs.value))
|
||||||
|
|
||||||
def test_read_on_invalid_padding(self):
|
def test_read_on_invalid_padding(self):
|
||||||
encoding = ('\x42\x00\x00\x08\x00\x00\x00\x03\x01\x02\x03\xff\xff\xff'
|
encoding = (b'\x42\x00\x00\x08\x00\x00\x00\x03\x01\x02\x03\xff\xff\xff'
|
||||||
'\xff\xff')
|
b'\xff\xff')
|
||||||
self.stream = BytearrayStream(str(encoding))
|
self.stream = BytearrayStream(encoding)
|
||||||
bs = ByteString()
|
bs = ByteString()
|
||||||
|
|
||||||
self.assertRaises(errors.ReadValueError, bs.read, self.stream)
|
self.assertRaises(errors.ReadValueError, bs.read, self.stream)
|
||||||
|
|
||||||
def test_write_value(self):
|
def test_write_value(self):
|
||||||
encoding = ('\x01\x02\x03\x00\x00\x00\x00\x00')
|
encoding = (b'\x01\x02\x03\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream()
|
self.stream = BytearrayStream()
|
||||||
value = bytearray('\x01\x02\x03')
|
value = bytearray(b'\x01\x02\x03')
|
||||||
bs = ByteString(value)
|
bs = ByteString(value)
|
||||||
bs.write_value(self.stream)
|
bs.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -1269,9 +1269,9 @@ class TestByteString(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_no_padding(self):
|
def test_write_value_no_padding(self):
|
||||||
encoding = ('\x01\x02\x03\x04\x05\x06\x07\x08')
|
encoding = (b'\x01\x02\x03\x04\x05\x06\x07\x08')
|
||||||
self.stream = BytearrayStream()
|
self.stream = BytearrayStream()
|
||||||
value = bytearray('\x01\x02\x03\x04\x05\x06\x07\x08')
|
value = bytearray(b'\x01\x02\x03\x04\x05\x06\x07\x08')
|
||||||
bs = ByteString(value)
|
bs = ByteString(value)
|
||||||
bs.write_value(self.stream)
|
bs.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -1284,9 +1284,9 @@ class TestByteString(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_max_padding(self):
|
def test_write_value_max_padding(self):
|
||||||
encoding = ('\x01\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x01\x00\x00\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream()
|
self.stream = BytearrayStream()
|
||||||
value = bytearray('\x01')
|
value = bytearray(b'\x01')
|
||||||
bs = ByteString(value)
|
bs = ByteString(value)
|
||||||
bs.write_value(self.stream)
|
bs.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -1299,9 +1299,9 @@ class TestByteString(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write_value_zero(self):
|
def test_write_value_zero(self):
|
||||||
encoding = ('\x00\x00\x00\x00\x00\x00\x00\x00')
|
encoding = (b'\x00\x00\x00\x00\x00\x00\x00\x00')
|
||||||
self.stream = BytearrayStream()
|
self.stream = BytearrayStream()
|
||||||
value = bytearray('\x00')
|
value = bytearray(b'\x00')
|
||||||
bs = ByteString(value)
|
bs = ByteString(value)
|
||||||
bs.write_value(self.stream)
|
bs.write_value(self.stream)
|
||||||
|
|
||||||
|
@ -1314,10 +1314,10 @@ class TestByteString(TestCase):
|
||||||
self.assertEqual(encoding, result, self.bad_encoding)
|
self.assertEqual(encoding, result, self.bad_encoding)
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
encoding = ('\x42\x00\x00\x08\x00\x00\x00\x03\x01\x02\x03\x00\x00\x00'
|
encoding = (b'\x42\x00\x00\x08\x00\x00\x00\x03\x01\x02\x03\x00\x00\x00'
|
||||||
'\x00\x00')
|
b'\x00\x00')
|
||||||
self.stream = BytearrayStream()
|
self.stream = BytearrayStream()
|
||||||
value = bytearray('\x01\x02\x03')
|
value = bytearray(b'\x01\x02\x03')
|
||||||
bs = ByteString(value)
|
bs = ByteString(value)
|
||||||
bs.write(self.stream)
|
bs.write(self.stream)
|
||||||
|
|
||||||
|
|
|
@ -73,19 +73,19 @@ class TestBytearrayStream(TestCase):
|
||||||
super(TestBytearrayStream, self).tearDown()
|
super(TestBytearrayStream, self).tearDown()
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
value = '\x00'
|
value = b'\x00'
|
||||||
b = utils.BytearrayStream(value)
|
b = utils.BytearrayStream(value)
|
||||||
|
|
||||||
buf_type = type(b.buffer)
|
buf_type = type(b.buffer)
|
||||||
msg = self.bad_type.format('buffer', bytearray, buf_type)
|
msg = self.bad_type.format('buffer', type(b''), buf_type)
|
||||||
self.assertIsInstance(b.buffer, bytearray,
|
self.assertIsInstance(b.buffer, type(b''),
|
||||||
msg.format(bytearray, type(b.buffer)))
|
msg.format(type(b''), type(b.buffer)))
|
||||||
|
|
||||||
length = len(b.buffer)
|
length = len(b.buffer)
|
||||||
msg = self.bad_len.format('buffer', 1, length)
|
msg = self.bad_len.format('buffer', 1, length)
|
||||||
self.assertEqual(1, length, msg)
|
self.assertEqual(1, length, msg)
|
||||||
|
|
||||||
content = str(b.buffer)
|
content = b.buffer
|
||||||
msg = self.bad_val.format('buffer', value, content)
|
msg = self.bad_val.format('buffer', value, content)
|
||||||
self.assertEqual(value, content, msg)
|
self.assertEqual(value, content, msg)
|
||||||
|
|
||||||
|
@ -93,9 +93,9 @@ class TestBytearrayStream(TestCase):
|
||||||
b = utils.BytearrayStream()
|
b = utils.BytearrayStream()
|
||||||
|
|
||||||
buf_type = type(b.buffer)
|
buf_type = type(b.buffer)
|
||||||
msg = self.bad_type.format('buffer', bytearray, buf_type)
|
msg = self.bad_type.format('buffer', type(b''), buf_type)
|
||||||
self.assertIsInstance(b.buffer, bytearray,
|
self.assertIsInstance(b.buffer, type(b''),
|
||||||
msg.format(bytearray, type(b.buffer)))
|
msg.format(type(b''), type(b.buffer)))
|
||||||
|
|
||||||
length = len(b.buffer)
|
length = len(b.buffer)
|
||||||
msg = self.bad_len.format('buffer', 0, length)
|
msg = self.bad_len.format('buffer', 0, length)
|
||||||
|
@ -111,7 +111,7 @@ class TestBytearrayStream(TestCase):
|
||||||
|
|
||||||
def test_peek(self):
|
def test_peek(self):
|
||||||
# TODO (peter-hamilton) Finish implementation.
|
# TODO (peter-hamilton) Finish implementation.
|
||||||
value = ('\x00\x01\x02\x03')
|
value = (b'\x00\x01\x02\x03')
|
||||||
expected = value
|
expected = value
|
||||||
b = expected
|
b = expected
|
||||||
expected = b
|
expected = b
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TestKMIPClient(TestCase):
|
||||||
try:
|
try:
|
||||||
self.client = KMIPProxy(port=self.KMIP_PORT)
|
self.client = KMIPProxy(port=self.KMIP_PORT)
|
||||||
self.client.open()
|
self.client.open()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self._shutdown_server()
|
self._shutdown_server()
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
@ -195,8 +195,8 @@ class TestKMIPClient(TestCase):
|
||||||
key_format_type = KeyFormatType.RAW
|
key_format_type = KeyFormatType.RAW
|
||||||
secret_features.update([('key_format_type', key_format_type)])
|
secret_features.update([('key_format_type', key_format_type)])
|
||||||
|
|
||||||
key_data = {'bytes': bytearray('\x00\x00\x00\x00\x00\x00\x00\x00'
|
key_data = {'bytes': bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00'
|
||||||
'\x00\x00\x00\x00\x00\x00\x00\x00')}
|
b'\x00\x00\x00\x00\x00\x00\x00\x00')}
|
||||||
|
|
||||||
secret_features.update([('key_value', key_data)])
|
secret_features.update([('key_value', key_data)])
|
||||||
secret_features.update([('cryptographic_algorithm', algorithm_value)])
|
secret_features.update([('cryptographic_algorithm', algorithm_value)])
|
||||||
|
@ -333,7 +333,7 @@ class TestKMIPClient(TestCase):
|
||||||
message = utils.build_er_error(TemplateAttribute.__class__, 'number',
|
message = utils.build_er_error(TemplateAttribute.__class__, 'number',
|
||||||
expected, observed, 'attributes')
|
expected, observed, 'attributes')
|
||||||
|
|
||||||
for i in xrange(num_attributes):
|
for i in range(num_attributes):
|
||||||
features = attribute_features[i]
|
features = attribute_features[i]
|
||||||
self._check_attribute(attributes[i], features[0], features[1],
|
self._check_attribute(attributes[i], features[0], features[1],
|
||||||
features[2], features[3])
|
features[2], features[3])
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDBjCCAe4CCQDWchiOQEmcDDANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB
|
||||||
|
VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0
|
||||||
|
cyBQdHkgTHRkMB4XDTE0MDgxOTA0MjAzM1oXDTE1MDgxOTA0MjAzM1owRTELMAkG
|
||||||
|
A1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0
|
||||||
|
IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
|
||||||
|
AKcLbcQbhvzQ/5JB/omGt+VHXbnUinWKygYPNdJH5dvt0DVUNRvlvjTjkrNqTTVG
|
||||||
|
iAdSuhxylW6NB7/aJ5Cen3J22NT01O7g5JNsNrrDwvOUNLnaMYCtIaMaHPrLFqTb
|
||||||
|
SwlUoCbwY1W9/PWb63IorZOrs4iT0DhBqal6gshUFXYPYqTtseO+lMwTh9ETIcnV
|
||||||
|
8wwFCieX4czmQKcBZCBXShkyepSW/JczaYEelxhlfsAvNWKnvLE0SCOM2wp7XaB4
|
||||||
|
Rjx0wbenQQvg0KqksIBXBa/Xm2YNyzonnPpG59HoAuap3ZP6ZqgdRy9CYNK92j17
|
||||||
|
ZGzrxG5FWNeGKSCJUi7O7/sCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAnx2LB4Ma
|
||||||
|
BKHOszMJQi5vrLni6G1IMWNmbbXERHancFovgGB//YaTnKnJxEPXx+WIrX5S+zLI
|
||||||
|
3Du4bQ78HMv7TSp5YV/E988qaGHjrKNp4aZpDM/uDE1p3Ik2mPUCa4uf3/HT2VaI
|
||||||
|
LzSYZN7/C2CLg/65MuV10Tus0wE3H6UCWmBjNuZpCxIvuEYA2ZD7pHdvZgOe/dYX
|
||||||
|
PEDRyDzkMAArJ/v4A/yj9JUB2nGkJLf/KHImFfZ+3+6UIiOQPsRvMlw4y7vCV+5d
|
||||||
|
T5TN4NSj9+l6kGiB4fFszj60erPlRpshuRjcrrzJAxK7XZgZgsl/6UMoPBoUdsNx
|
||||||
|
/Wc6VFs6KyJvgw==
|
||||||
|
-----END CERTIFICATE-----
|
|
@ -0,0 +1,16 @@
|
||||||
|
-----BEGIN CERTIFICATE REQUEST-----
|
||||||
|
MIICijCCAXICAQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx
|
||||||
|
ITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcN
|
||||||
|
AQEBBQADggEPADCCAQoCggEBAKcLbcQbhvzQ/5JB/omGt+VHXbnUinWKygYPNdJH
|
||||||
|
5dvt0DVUNRvlvjTjkrNqTTVGiAdSuhxylW6NB7/aJ5Cen3J22NT01O7g5JNsNrrD
|
||||||
|
wvOUNLnaMYCtIaMaHPrLFqTbSwlUoCbwY1W9/PWb63IorZOrs4iT0DhBqal6gshU
|
||||||
|
FXYPYqTtseO+lMwTh9ETIcnV8wwFCieX4czmQKcBZCBXShkyepSW/JczaYEelxhl
|
||||||
|
fsAvNWKnvLE0SCOM2wp7XaB4Rjx0wbenQQvg0KqksIBXBa/Xm2YNyzonnPpG59Ho
|
||||||
|
Auap3ZP6ZqgdRy9CYNK92j17ZGzrxG5FWNeGKSCJUi7O7/sCAwEAAaAAMA0GCSqG
|
||||||
|
SIb3DQEBBQUAA4IBAQAkMXNZFu+fcAAf/iKNAeG2p/ptKvFMIkm0JUp9zHhidm21
|
||||||
|
tgAjRMwOTKNQfGRKb1nVV45W8YBSaw3iZR50FKJPBmoO+S63InRJe4YhywcMQNXC
|
||||||
|
RH37IVxKzGl5NmfPqLmEAD/VGTKbqQr27YDQ/azwGhjPrjN3gSx5YklySSefQRuU
|
||||||
|
PQOvxYe2jA8fAo6kf0QFtxOPK2DVvnP2CQqyIOHdybWFeYrTWCiXWLDoKrkmACbE
|
||||||
|
SCLXT7dZaM7+BvrkMDNz85co7ik7fFUZgxeEWVYwVhnscg7/gJBSCvxFIBeoK9oP
|
||||||
|
TyJ0SuVK9fr8U3neXbQozmWc5WqYpISS8LGbJ/6H
|
||||||
|
-----END CERTIFICATE REQUEST-----
|
|
@ -0,0 +1,27 @@
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEpAIBAAKCAQEApwttxBuG/ND/kkH+iYa35UddudSKdYrKBg810kfl2+3QNVQ1
|
||||||
|
G+W+NOOSs2pNNUaIB1K6HHKVbo0Hv9onkJ6fcnbY1PTU7uDkk2w2usPC85Q0udox
|
||||||
|
gK0hoxoc+ssWpNtLCVSgJvBjVb389Zvrciitk6uziJPQOEGpqXqCyFQVdg9ipO2x
|
||||||
|
476UzBOH0RMhydXzDAUKJ5fhzOZApwFkIFdKGTJ6lJb8lzNpgR6XGGV+wC81Yqe8
|
||||||
|
sTRII4zbCntdoHhGPHTBt6dBC+DQqqSwgFcFr9ebZg3LOiec+kbn0egC5qndk/pm
|
||||||
|
qB1HL0Jg0r3aPXtkbOvEbkVY14YpIIlSLs7v+wIDAQABAoIBAQCiM6nJNAWWdgbE
|
||||||
|
aUqVFfh5LRwoduZfjn3u9lQHtQLQ1JJJRlQvm51fU98+UilYYv1xRvYq62SIrW7p
|
||||||
|
7xZeCni/OAICfx5IOp4ZPInEPpSN2sp78RACZ5ry+kdLi2qYd8vb6o18Yg3C0zHO
|
||||||
|
+DDeb/tkGeTB6O3VwoTRaYGWrncMZABgOjGI0Iyjn4tJZnl8V+rhoseCKezGwaZl
|
||||||
|
rAukc0lv4GX6jQoMWB72/qhIu8a9MinP0b3U17j+flnVlcrYS1Y6Atuj4sGCpeVc
|
||||||
|
fxLfbkUy2p7Ja4YBmYfhlnJb76VBKr2MeKHcHJl2+CzWMbDJsH+/skD0UPfvicjr
|
||||||
|
wC1m9NQxAoGBANR6a6x3afQG2iLMhmQa9WdH7ufWlL122ssal+u66r68PsqBu0Zs
|
||||||
|
264lYyJmjyQvWw6Kbh1Lre14/LpwJMZko2HSqcy0cz7qTKwIAcxI3Qi5ZEhngU/l
|
||||||
|
lyOLFm6fPdA57vTkb7kgi1EmwWdf8mTDCHrLQpCMIRXc1rQAYKwfGb35AoGBAMlC
|
||||||
|
o3Ol+Br8pltjKtmlfYLnznFeepqPWBO+lTFqZYA6LvDAsjfEVufsMXCeNKq0Uopi
|
||||||
|
ocRIkPy0V1DZSe3hfZAV55fH3nk9uo2MfSsEKS/0lrG6PG4VK69Mo9wvkj7N5Oyj
|
||||||
|
qFc8tjRO43IZaOA1zWh8eFGdHERs6AZHXWEPvCqTAoGAB7nX1nKVILFrFx7WuCce
|
||||||
|
yz2bW0S7LdR3ijESWxj11i+kHNrww1PL/R4Q57xQ8iDir7mq3VfWIC9pCSJww+H+
|
||||||
|
6tytHetl0WDVnt+/qPzxRJLxKYzR7+TKRRmWnDkgF0U0AiWYRmP/jNja6XZcqvtI
|
||||||
|
gKaJahYeUdww1mS5HykWV4kCgYEAjz2yf7j8YJi4/goSkV1Le0Polp+buy2Sjlry
|
||||||
|
bH1BSIYgqpE7Rp2jDOX6OiEfcu9sX7nbUIwlRPZFvvEnwPrgFxDACDLkkH3yrJP0
|
||||||
|
8gzAE7WNG2llYSQIN3fgl/HzsGdyK0o/ofc/5vLOxoJ3NjyUuWz9ZXjgiYLJkM5y
|
||||||
|
E4bTcakCgYBQZuce3iG9DpW/YZwRIasUYfjLgOecwLRP+Bh8iv6NAe3sOJFlY1XQ
|
||||||
|
37De7wtSG24SogJDv5vglI9MwY2N1MCqT74HgZhazjtIz3cXwREDf7/vmiWsBPlA
|
||||||
|
Xghc8kmX70eb471WAI9y1wlj/UtNEeXT/ntfWCLFKdBH+o32P/UsiQ==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
|
@ -15,27 +15,20 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
import optparse
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from thrift.server import TServer
|
from kmip.services.kmip_server import KMIPServer
|
||||||
from thrift.transport import TSocket
|
|
||||||
from thrift.transport import TTransport
|
|
||||||
|
|
||||||
from kmip.core.server import KMIPImpl
|
FILE_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
from kmip.services.kmip_protocol import KMIPProtocolFactory
|
|
||||||
from kmip.services.kmip_server import Processor
|
|
||||||
|
|
||||||
|
|
||||||
def run_server(host='127.0.0.1', port=5696):
|
def run_server(host='127.0.0.1', port=5696,
|
||||||
|
cert_file=FILE_PATH + '/certs/server.crt',
|
||||||
|
key_file=FILE_PATH + '/certs/server.key'):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
handler = KMIPImpl()
|
server = KMIPServer(host, port, cert_file, key_file)
|
||||||
processor = Processor(handler)
|
|
||||||
transport = TSocket.TServerSocket(host, port)
|
|
||||||
tfactory = TTransport.TBufferedTransportFactory()
|
|
||||||
pfactory = KMIPProtocolFactory()
|
|
||||||
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
|
|
||||||
|
|
||||||
logger.info('Starting the KMIP server')
|
logger.info('Starting the KMIP server')
|
||||||
|
|
||||||
|
@ -43,10 +36,10 @@ def run_server(host='127.0.0.1', port=5696):
|
||||||
server.serve()
|
server.serve()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.info('KeyboardInterrupt received while serving')
|
logger.info('KeyboardInterrupt received while serving')
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.info('Exception received while serving: {0}'.format(e))
|
logger.info('Exception received while serving: {0}'.format(e))
|
||||||
finally:
|
finally:
|
||||||
transport.close()
|
server.close()
|
||||||
|
|
||||||
logger.info('Shutting down KMIP server')
|
logger.info('Shutting down KMIP server')
|
||||||
|
|
||||||
|
@ -60,6 +53,12 @@ def build_cli_parser():
|
||||||
"server (e.g., localhost, 127.0.0.1)")
|
"server (e.g., localhost, 127.0.0.1)")
|
||||||
parser.add_option("-p", "--port", action="store", default=5696,
|
parser.add_option("-p", "--port", action="store", default=5696,
|
||||||
dest="port", help="Port number for KMIP services")
|
dest="port", help="Port number for KMIP services")
|
||||||
|
parser.add_option("-c", "--cert_file", action="store",
|
||||||
|
default=FILE_PATH + '/certs/server.crt',
|
||||||
|
dest="cert_file")
|
||||||
|
parser.add_option("-k", "--key_file", action="store",
|
||||||
|
default=FILE_PATH + '/certs/server.key',
|
||||||
|
dest="key_file")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -67,4 +66,4 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
opts, args = parser.parse_args(sys.argv[1:])
|
opts, args = parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
run_server(opts.hostname, opts.port)
|
run_server(opts.hostname, opts.port, opts.cert_file, opts.key_file)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
enum34
|
enum34
|
||||||
sqlalchemy
|
sqlalchemy
|
||||||
thrift
|
|
||||||
|
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -17,7 +17,7 @@ import setuptools
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='PyKMIP',
|
name='PyKMIP',
|
||||||
version='0.0.1',
|
version='0.1.0',
|
||||||
description='KMIP v1.1 library',
|
description='KMIP v1.1 library',
|
||||||
keywords='KMIP',
|
keywords='KMIP',
|
||||||
author='Peter Hamilton',
|
author='Peter Hamilton',
|
||||||
|
@ -39,5 +39,7 @@ setuptools.setup(
|
||||||
"Programming Language :: Python :: 2",
|
"Programming Language :: Python :: 2",
|
||||||
"Programming Language :: Python :: 2.6",
|
"Programming Language :: Python :: 2.6",
|
||||||
"Programming Language :: Python :: 2.7",
|
"Programming Language :: Python :: 2.7",
|
||||||
|
"Programming Language :: Python :: 3.3",
|
||||||
|
"Programming Language :: Python :: 3.4",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue