Example #1
0
    def test_serialize_4(self):
        """
		Tests serialization of a packet.
		"""

        buf = bytes([
            0xD8,
            0x00,
            0x7F,
            0xFF,  # magic + flags (x bit set)
            0x12,
            0x34,
            0x56,
            0x78,  # cat
            0x12,
            0x34,
            0x56,
            0x78,  # cat..
            0x13,
            0x11,
            0x11,
            0x11,  # psn
            0x23,
            0x22,
            0x22,
            0x22,  # pse
            0x00,
            0x01,
            0x00,  # PCF Type := 0x0100,
            # PCF Len := 0, PCF I := 00b,
            0x01,
            0x02,
            0x03,
            0x04,
            0x05,
            0x06,  # 
            0x99,
            0x98,
            0x97,
            0x96
        ])  # 10 bytes payload

        l = True
        r = True
        s = True
        cat = 0x1234567812345678
        psn = 0x13111111
        pse = 0x23222222
        pcf_type = 0x0100
        pcf_len = 0x00
        pcf_integrity = 0x00
        pcf_value = bytes([])
        payload = bytes(
            [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x99, 0x98, 0x97, 0x96])

        plus_packet = packet.new_extended_packet(l, r, s, cat, psn, pse,
                                                 pcf_type, pcf_integrity,
                                                 pcf_value, payload)

        self.assertEqual(plus_packet.to_bytes(), buf)
Example #2
0
    def _random_packet(self):
        """
		Returns a random packet.
		"""

        n = random.randint(0, 1)

        l = bool(random.randint(0, 1))
        r = bool(random.randint(0, 1))
        s = bool(random.randint(0, 1))
        cat = random.randint(0, 2**64 - 1)
        psn = random.randint(0, 2**32 - 1)
        pse = random.randint(0, 2**32 - 1)
        pcf_type = random.randint(0, 2**16 - 1)
        pcf_value = self._random_buf_1()
        pcf_integrity = random.randint(0, 3)
        payload = self._random_buf_2()

        return packet.new_extended_packet(l, r, s, cat, psn, pse, pcf_type,
                                          pcf_integrity, pcf_value, payload)