本文整理汇总了Python中tlslite.utils.codec.Writer.add方法的典型用法代码示例。如果您正苦于以下问题:Python Writer.add方法的具体用法?Python Writer.add怎么用?Python Writer.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tlslite.utils.codec.Writer
的用法示例。
在下文中一共展示了Writer.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_five_twice
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_five_twice(self):
w = Writer()
w.add(0x0102030405, 5)
w.add(0x1112131415, 5)
self.assertEqual(bytearray(b'\x01\x02\x03\x04\x05'
b'\x11\x12\x13\x14\x15'),
w.bytes)
示例2: post_write
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def post_write(writer, self=msg, size=size, pad_byte=pad_byte, pad=pad):
"""Monkey patch for the postWrite of handshake messages"""
if pad is not None:
size = len(pad)
header_writer = Writer()
header_writer.add(self.handshakeType, 1)
header_writer.add(len(writer.bytes) + size, 3)
if pad is not None:
return header_writer.bytes + writer.bytes + pad
elif size < 0:
return header_writer.bytes + writer.bytes[:size]
else:
return header_writer.bytes + writer.bytes + \
bytearray([pad_byte]*size)
示例3: extData
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def extData(self):
"""Serialise the extension."""
if self.client_shares is None:
return bytearray(0)
writer = Writer()
for group_id, share in self.client_shares:
writer.add(group_id, 2)
if group_id in GroupName.allFF:
share_length_length = 2
else:
share_length_length = 1
writer.addVarSeq(share, 1, share_length_length)
ext_writer = Writer()
ext_writer.add(len(writer.bytes), 2)
ext_writer.bytes += writer.bytes
return ext_writer.bytes
示例4: test_bytes
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_bytes(self):
w = Writer()
w.bytes += bytearray(b'\xbe\xef')
w.add(15, 1)
self.assertEqual(bytearray(b'\xbe\xef\x0f'), w.bytes)
示例5: test_add_with_four_bytes_overflowing_data
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_four_bytes_overflowing_data(self):
w = Writer()
with self.assertRaises(ValueError):
w.add(0x0100000000, 4)
示例6: test_add_with_five_underflowing_bytes
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_five_underflowing_bytes(self):
w = Writer()
with self.assertRaises(ValueError):
w.add(-1, 5)
示例7: test_add_with_five_overflowing_bytes
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_five_overflowing_bytes(self):
w = Writer()
with self.assertRaises(ValueError):
w.add(0x010000000000, 5)
示例8: test_add_with_six_bytes_data
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_six_bytes_data(self):
w = Writer()
w.add(0x010203040506, 6)
self.assertEqual(bytearray(b'\x01\x02\x03\x04\x05\x06'), w.bytes)
示例9: test_add_with_five_bytes_data
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_five_bytes_data(self):
w = Writer()
w.add(0x02, 5)
self.assertEqual(bytearray(b'\x00\x00\x00\x00\x02'), w.bytes)
示例10: test_add_with_four_byte_data
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_four_byte_data(self):
w = Writer()
w.add(0x01020304, 4)
self.assertEqual(bytearray(b'\x01\x02\x03\x04'), w.bytes)
示例11: test_add_with_underflowing_data
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_underflowing_data(self):
w = Writer()
with self.assertRaises(ValueError):
w.add(-1, 1)
示例12: test_add_with_three_byte_data
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_three_byte_data(self):
w = Writer()
w.add(0xbacc01, 3)
self.assertEqual(bytearray(b'\xba\xcc\x01'), w.bytes)
示例13: test_add_with_multibyte_data
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_multibyte_data(self):
w = Writer()
w.add(512, 2)
self.assertEqual(bytearray(b'\x02\x00'), w.bytes)
示例14: test_add_with_multibyte_field
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add_with_multibyte_field(self):
w = Writer()
w.add(32, 2)
self.assertEqual(bytearray(b'\x00\x20'), w.bytes)
示例15: test_add
# 需要导入模块: from tlslite.utils.codec import Writer [as 别名]
# 或者: from tlslite.utils.codec.Writer import add [as 别名]
def test_add(self):
w = Writer()
w.add(255, 1)
self.assertEqual(bytearray(b'\xff'), w.bytes)