Beispiel #1
0
 def getBytes(self, trimmed=False):
     """TODO"""
     ret = self.header.getBytes() + self.rheader.getBytes()
     ret += struct.pack('!B', self.reason)
     if trimmed is True:
         return ret
     else:
         return FixedLenCell.padCellBytes(ret, self.header.link_version)
Beispiel #2
0
    def getBytes(self, trimmed=False):
        '''Construct and return the byte string represented by this cell.

        :param bool trimmed: If **True**, return the non-padded payload.
            Otherwise pad the payload with null bytes to the fixed-size
            length in use according to the Link Protocol version.
        :returns: **str** byte string represented by this cell
        '''
        ret = self.header.getBytes() + self.rheader.getBytes() + self.rpayload
        return FixedLenCell.padCellBytes(ret, self.header.link_version)
Beispiel #3
0
    def getBytes(self, trimmed=False):
        '''Build and return the raw byte string this cell represents.

        :param bool trimmed: if **True**, do not pad payload bytes
        :returns: **str** raw bytes this cell represents
        '''
        ret = self.header.getBytes() + self.rheader.getBytes()
        ret += struct.pack('!B', self.reason)
        if trimmed is True:
            return ret
        else:
            return FixedLenCell.padCellBytes(ret, self.header.link_version)
Beispiel #4
0
    def getBytes(self, trimmed=False):
        '''Build and return the raw byte string this cell represents.

        :param bool trimmed: If **True**, do not pad this cell's payload.
        :returns: **str** raw byte string represented by this cell
        '''
        ret = self.header.getBytes() + self.rheader.getBytes()
        ret += self.addr
        ret += self.flags
        if trimmed is True:
            return ret
        else:
            return FixedLenCell.padCellBytes(ret, self.header.link_version)
Beispiel #5
0
    def getBytes(self, trimmed=False):
        '''Build and return the raw byte string this cell represents.

        :param bool trimmed: if **True**, do not pad payload bytes
        :returns: **str** raw byte string this cell represents
        '''
        ret = self.header.getBytes() + self.rheader.getBytes()
        ret += struct.pack('!B', self.reason)
        ret += self.reason_data
        if trimmed is True:
            return ret
        else:
            return FixedLenCell.padCellBytes(ret, self.header.link_version)
Beispiel #6
0
    def getBytes(self, trimmed=False):
        '''Build and return the raw byte string this cell represents.

        :param bool trimmed: If **True**, do not pad this cell's payload.
        :returns: **str** raw byte string represented by this cell
        '''
        ret = self.header.getBytes() + self.rheader.getBytes()
        ret += self.addr
        ret += self.flags
        if trimmed is True:
            return ret
        else:
            return FixedLenCell.padCellBytes(ret, self.header.link_version)
Beispiel #7
0
CIRC_ID = 1

# Unit tests and constants for Create2Cell

CREATE2_CMD = 10
CREATE2_NTOR_HTYPE = 2
CREATE2_NTOR_HLEN = 84
CREATE2_NTOR_HDATA_DUMMY = "\x00" * CREATE2_NTOR_HLEN

create2_bytes_good = struct.pack(
    "!HBHH{}s".format(CREATE2_NTOR_HLEN),
    CIRC_ID, CREATE2_CMD,
    CREATE2_NTOR_HTYPE, CREATE2_NTOR_HLEN, CREATE2_NTOR_HDATA_DUMMY,
)
create2_bytes_good_padded = FixedLenCell.padCellBytes(create2_bytes_good)
assert len(create2_bytes_good_padded) == 512

create2_parse_bad_htype = struct.pack(
    "!HBHH{}s".format(CREATE2_NTOR_HLEN),
    CIRC_ID, CREATE2_CMD,
    # ntor should be 2
    1, CREATE2_NTOR_HLEN, CREATE2_NTOR_HDATA_DUMMY,
)
create2_parse_bad_htype = FixedLenCell.padCellBytes(create2_parse_bad_htype)
assert len(create2_parse_bad_htype) == 512

create2_parse_bad_hlen = struct.pack(
    "!HBHH{}s".format(CREATE2_NTOR_HLEN),
    CIRC_ID, CREATE2_CMD,
    # hlen should be 84 for ntor