def files_from_farc_bytes(b): farc = pyfarc.from_bytes(b) out = [] for fname, info in farc['files'].items(): out += [(fname, info['data'])] return sorted(out, key=lambda f: f[0])
def test_FARC_flags_false(self): farc = { 'farc_type': 'FARC', 'files': { 'a': { 'data': b'a' }, 'b': { 'data': b'b' }, 'c': { 'data': b'cccccccccccccccccccccccc' } } } res = pyfarc.from_bytes(pyfarc.to_bytes(farc)) self.assertFalse(res['flags']['encrypted']) self.assertFalse(res['flags']['compressed'])
def test_FARC_FT_flags_per_file_true(self): farc = { 'farc_type': 'FARC', 'format': 1, 'files': { 'a': { 'data': b'aaaaaaaaaaaaaaaaaaaaaaaa', }, 'b': { 'data': b'bbbbbbbbbbbbbbbbbbbbbbbb', 'flags': { 'encrypted': False } }, 'c': { 'data': b'cccccccccccccccccccccccc', 'flags': { 'encrypted': False, 'compressed': False } } }, 'flags': { 'encrypted': True, 'compressed': True } } res = pyfarc.from_bytes(pyfarc.to_bytes(farc)) self.assertTrue(res['flags']['encrypted']) self.assertTrue(res['flags']['compressed']) self.assertTrue(res['files']['a']['flags'] ['encrypted']) # a has inherited true flags self.assertTrue(res['files']['a']['flags']['compressed']) self.assertFalse( res['files']['b']['flags']['encrypted'] ) # b has encryption disabled with inherited compression self.assertTrue(res['files']['b']['flags']['compressed']) self.assertFalse( res['files']['c']['flags'] ['encrypted']) # c has encryption and compression disabled self.assertFalse(res['files']['c']['flags']['compressed'])
def test_FARC_FT_flags_true(self): farc = { 'farc_type': 'FARC', 'format': 1, 'files': { 'a': { 'data': b'aaaaaaaaaaaaaaaaaaaaaaaa' }, 'b': { 'data': b'bbbbbbbbbbbbbbbbbbbbbbbb' }, 'c': { 'data': b'cccccccccccccccccccccccc' } }, 'flags': { 'encrypted': True, 'compressed': True } } res = pyfarc.from_bytes(pyfarc.to_bytes(farc)) self.assertTrue(res['flags']['encrypted']) self.assertTrue(res['flags']['compressed'])
def test_farc_load_whitelist_default(self): b = farc_bytes_from_files(customdata, 'FArc', 16, False, False) farc = pyfarc.from_bytes(b, files_whitelist=['zero-length']) self.assertEqual(farc['files'], {'zero-length': {'data': b''}})