gpgme_data_t seahorse_vfs_data_read_multi (const gchar **uris, GError **err) { gpgme_error_t gerr; gpgme_data_t data; GList *datas = NULL; const gchar **u; for (u = uris; *u; u++) { if(!(*u)[0]) continue; data = seahorse_vfs_data_create (*u, SEAHORSE_VFS_READ, err); if (!data) break; datas = g_list_prepend (datas, data); } /* Failed somewhere */ if (!data) { multi_data_release (datas); return NULL; } datas = g_list_reverse (datas); gerr = gpgme_data_new_from_cbs (&data, &multi_data_cbs, datas); if (!GPG_IS_OK (gerr)) { seahorse_util_gpgme_to_error (gerr, err); multi_data_release (datas); return NULL; } return data; }
static gboolean decrypt_start (SeahorseToolMode *mode, const gchar *uri, gpgme_data_t uridata, SeahorsePGPOperation *pop, GError **err) { gpgme_data_t plain; gpgme_error_t gerr; gchar *touri; /* File to decrypt to */ touri = seahorse_util_remove_suffix (uri, _("Choose Decrypted File Name for '%s'")); if (!touri) return FALSE; /* Open necessary files, release these with the operation */ plain = seahorse_vfs_data_create (touri, SEAHORSE_VFS_WRITE | SEAHORSE_VFS_DELAY, err); g_free (touri); if (!plain) return FALSE; g_object_set_data_full (G_OBJECT (pop), "plain-data", plain, (GDestroyNotify)gpgme_data_release); /* Start actual decryption */ gerr = gpgme_op_decrypt_verify_start (pop->gctx, uridata, plain); if (gerr != 0) { seahorse_util_gpgme_to_error (gerr, err); return FALSE; } return TRUE; }
gboolean seahorse_vfs_set_file_contents (const gchar *uri, const gchar *text, gint len, GError **err) { gpgme_data_t data; gboolean ret; data = seahorse_vfs_data_create (uri, SEAHORSE_VFS_WRITE, err); if (!data) return FALSE; ret = seahorse_vfs_data_write_all (data, (void*)text, len, err); gpgme_data_release (data); return ret; }
static gboolean encrypt_sign_start (SeahorseToolMode *mode, const gchar *uri, gpgme_data_t uridata, SeahorsePGPOperation *pop, GError **err) { gpgme_data_t cipher; gpgme_error_t gerr; gchar *touri; g_assert (mode->recipients && mode->recipients[0]); /* File to encrypt to */ touri = seahorse_util_add_suffix (uri, SEAHORSE_CRYPT_SUFFIX, _("Choose Encrypted File Name for '%s'")); if (!touri) return FALSE; /* Open necessary files, release these with the operation */ cipher = seahorse_vfs_data_create (touri, SEAHORSE_VFS_WRITE | SEAHORSE_VFS_DELAY, err); g_free (touri); if (!cipher) return FALSE; g_object_set_data_full (G_OBJECT (pop), "cipher-data", cipher, (GDestroyNotify)gpgme_data_release); gpgme_set_armor (pop->gctx, seahorse_gconf_get_boolean (ARMOR_KEY)); gpgme_set_textmode (pop->gctx, FALSE); /* Start actual encryption */ gpgme_signers_clear (pop->gctx); if (mode->signer) { gpgme_signers_add (pop->gctx, mode->signer); gerr = gpgme_op_encrypt_sign_start (pop->gctx, mode->recipients, GPGME_ENCRYPT_ALWAYS_TRUST, uridata, cipher); } else { gerr = gpgme_op_encrypt_start (pop->gctx, mode->recipients, GPGME_ENCRYPT_ALWAYS_TRUST, uridata, cipher); } if (gerr != 0) { seahorse_util_gpgme_to_error (gerr, err); return FALSE; } return TRUE; }
static gboolean verify_start (SeahorseToolMode *mode, const gchar *uri, gpgme_data_t uridata, SeahorsePGPOperation *pop, GError **err) { gpgme_data_t plain; gpgme_error_t gerr; gchar *original, *unesc_uri; /* File to decrypt to */ original = seahorse_util_remove_suffix (uri, NULL); /* The original file doesn't exist, prompt for it */ if (!seahorse_util_uri_exists (original)) { GtkWidget *dialog; gchar *t; unesc_uri = g_uri_unescape_string (seahorse_util_uri_get_last (uri), NULL); t = g_strdup_printf (_("Choose Original File for '%s'"), unesc_uri); dialog = gtk_file_chooser_dialog_new (t, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); g_free (unesc_uri); g_free (t); gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), original); gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE); g_free (original); original = NULL; seahorse_tool_progress_block (TRUE); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) original = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog)); seahorse_tool_progress_block (FALSE); gtk_widget_destroy (dialog); } if (!original) return FALSE; g_object_set_data_full (G_OBJECT (pop), "original-file", original, g_free); /* Open necessary files, release with operation */ plain = seahorse_vfs_data_create (original, SEAHORSE_VFS_READ, err); if (!plain) return FALSE; g_object_set_data_full (G_OBJECT (pop), "plain-data", plain, (GDestroyNotify)gpgme_data_release); /* Start actual verify */ gerr = gpgme_op_verify_start (pop->gctx, uridata, plain, NULL); if (gerr != 0) { seahorse_util_gpgme_to_error (gerr, err); return FALSE; } return TRUE; }