Browse Source

Allow armored output.

Add an option to generated armored ASCII output instead of the
default binary output.
master
Damien Goutte-Gattat 2 years ago
parent
commit
e924e5a2f5
  1. 21
      src/encrypt.c
  2. 37
      src/yki-encrypt.ui

21
src/encrypt.c

@ -43,6 +43,7 @@ typedef struct {
gboolean symmetric;
gboolean sign;
gboolean detached;
gboolean armored;
GtkWidget *ok_button;
GtkWidget *detached_button;
@ -81,6 +82,12 @@ detach_sign_toggled(GtkWidget *widget, gpointer data)
((yki_encrypt_data_t *)data)->detached = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
}
static void
armored_toggled(GtkWidget *widget, gpointer data)
{
((yki_encrypt_data_t *)data)->armored = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
}
static void
public_key_toggled(GtkCellRendererToggle *renderer,
gchar *path,
@ -130,6 +137,8 @@ create_encrypt_dialog(yki_encrypt_data_t *yki)
"clicked", G_CALLBACK(sign_toggled), yki);
g_signal_connect(gtk_builder_get_object(builder, "chkDetachSign"),
"clicked", G_CALLBACK(detach_sign_toggled), yki);
g_signal_connect(gtk_builder_get_object(builder, "chkArmor"),
"clicked", G_CALLBACK(armored_toggled), yki);
widget = gtk_builder_get_object(builder, "trvPublicKeys");
yki->public_keys = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget)));
@ -271,27 +280,27 @@ do_encrypt(yki_encrypt_data_t *yki, gpgme_data_t in, gpgme_data_t out, GError **
int
yki_encrypt(gpgme_ctx_t gpgme, const char *file, GError **error)
{
yki_encrypt_data_t yki;
yki_encrypt_data_t yki = { 0 };
gpgutil_file_t in = { 0 }, out = { 0 };
GtkDialog *dlg;
gpgutil_file_t in, out;
gchar *outname;
int ret;
g_assert(gpgme && file);
yki.gpgme = gpgme;
yki.selected_keys = 0;
yki.symmetric = yki.sign = yki.detached = FALSE;
in.buffer = out.buffer = NULL;
dlg = create_encrypt_dialog(&yki);
ret = populate_public_key_list(gpgme, yki.public_keys, error);
set_default_output_filename(&yki, file);
if ( ret && gtk_dialog_run(dlg) == GTK_RESPONSE_OK && yki_can_encrypt(yki) ) {
gpgme_set_armor(gpgme, yki.armored);
ret = gpgutil_open_file(file, "r", &in, error);
if ( ret ) {
outname = g_strdup_printf("%s.gpg", file);
outname = g_strdup_printf("%s.%s", file, yki.armored ? "asc" : "gpg");
ret = gpgutil_open_file(outname, "w", &out, error);
g_free(outname);
}

37
src/yki-encrypt.ui

@ -213,6 +213,43 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
<child>
<object class="GtkCheckButton" id="chkArmor">
<property name="label" translatable="yes">Armored output</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Output&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>

Loading…
Cancel
Save