Пример #1
0
def test_encrypt_regular_archive_remove_unencrypted(tmp_path):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("normal-archive")
    copied_archive_path = tmp_path / folder_name
    shutil.copytree(archive_path, copied_archive_path)

    keys = get_public_key_paths()
    encrypt_existing_archive(copied_archive_path, keys, remove_unencrypted=True)

    assert_successful_archive_creation(copied_archive_path, archive_path, folder_name, encrypted="all")
Пример #2
0
def test_encrypt_regular_file(tmp_path):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("normal-archive")
    copied_archive_path = tmp_path / folder_name
    archive_file = copied_archive_path / f"{folder_name}.tar.lz"

    shutil.copytree(archive_path, copied_archive_path)
    keys = get_public_key_paths()

    encrypt_existing_archive(archive_file, keys)
    assert_successful_archive_creation(copied_archive_path, archive_path, folder_name, encrypted="all", unencrypted="all")
Пример #3
0
def test_encrypt_regular_archive_error_existing(tmp_path):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("normal-archive")
    destination_path = tmp_path / folder_name
    destination_path.mkdir()

    keys = get_public_key_paths()

    with pytest.raises(SystemExit) as error:
        encrypt_existing_archive(archive_path, keys, destination_path)

        assert error.type == SystemExit
Пример #4
0
def handle_encryption(args):
    source_path = Path(args.source)
    destination_path = Path(args.destination) if args.destination else None

    remove_unencrypted = args.remove

    threads = args.threads if args.threads else 1

    if args.reencrypt:
        # Always remove the unencrypted archive when --reencrypt is used since there was no unencrypted archive present
        remove_unencrypted = True
        # Encrypted archive will be removed in any case, since new one will be created
        decrypt_existing_archive(source_path,
                                 remove_unencrypted=True,
                                 threads=threads)

    encrypt_existing_archive(source_path,
                             args.key,
                             destination_path,
                             remove_unencrypted,
                             args.force,
                             threads=threads)