Beispiel #1
0
    def assemble_and_store_file(self,
                                ts:            'datetime',
                                onion_pub_key: bytes,
                                window_list:   'WindowList'
                                ) -> None:
        """Assemble file packet and store it."""
        padded  = b''.join([p[ASSEMBLY_PACKET_HEADER_LENGTH:] for p in self.assembly_pt_list])
        payload = rm_padding_bytes(padded)

        process_assembled_file(ts, payload, onion_pub_key, self.contact.nick, self.settings, window_list)
Beispiel #2
0
    def assemble_and_store_file(self, ts: 'datetime', onion_pub_key: bytes,
                                window_list: 'WindowList') -> None:
        """Assemble file packet and store it."""
        padded = b''.join(
            [p[ASSEMBLY_PACKET_HEADER_LENGTH:] for p in self.assembly_pt_list])
        payload = rm_padding_bytes(padded)

        no_fields = 3 if len(self.assembly_pt_list) > 1 else 2
        *_, payload = separate_headers(payload,
                                       no_fields * [ENCODED_INTEGER_LENGTH])

        process_assembled_file(ts, payload, onion_pub_key, self.contact.nick,
                               self.settings, window_list)
Beispiel #3
0
    def test_successful_reception(self) -> None:
        # Setup
        compressed = zlib.compress(b'file_data', level=COMPRESSION_LEVEL)
        file_data  = encrypt_and_sign(compressed, self.key) + self.key
        payload    = b'testfile.txt' + US_BYTE + file_data

        # Test
        self.assertIsNone(process_assembled_file(self.ts, payload, *self.args))
        self.assertTrue(os.path.isfile(f'{DIR_RECV_FILES}Alice/testfile.txt'))
Beispiel #4
0
    def test_successful_reception_during_traffic_masking(self) -> None:
        # Setup
        self.settings.traffic_masking = True
        self.window_list.active_win   = self.window_list.get_window(nick_to_pub_key('Bob'))

        compressed = zlib.compress(b'file_data', level=COMPRESSION_LEVEL)
        file_data  = encrypt_and_sign(compressed, self.key) + self.key
        payload    = b'testfile.txt' + US_BYTE + file_data

        # Test
        self.assertIsNone(process_assembled_file(self.ts, payload, *self.args))
        self.assertEqual(self.window_list.get_window(nick_to_pub_key('Bob')).message_log[0][1],
                         "Stored file from Alice as 'testfile.txt'.")
        self.assertTrue(os.path.isfile(f'{DIR_RECV_FILES}Alice/testfile.txt'))