commit 802d1a2be68a8f417cbedb0e86f424309495adad
parent 754eba98c8d281aa32cc867b533e933a0ce4a657
Author: lash <dev@holbrook.no>
Date: Wed, 24 Apr 2024 22:37:06 +0100
Add context to kee menu object
Diffstat:
5 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/src/gpg.h b/src/gpg.h
@@ -8,11 +8,13 @@
#define GPG_MIN_VERSION "1.10.2"
#define CHACHA20_KEY_LENGTH_BYTES 32
#define CHACHA20_NONCE_LENGTH_BYTES 12
+#define PUBKEY_LENGTH 32
#ifndef ENCRYPT_BLOCKSIZE
#define ENCRYPT_BLOCKSIZE 4096
#endif
+
struct gpg_store {
size_t passphrase_digest_len;
char fingerprint[40];
diff --git a/src/gtk/kee-entry.c b/src/gtk/kee-entry.c
@@ -23,7 +23,7 @@
#include "strip.h"
#include "ledger.h"
#include "dn.h"
-
+#include "gpg.h"
typedef struct {
} KeeEntryPrivate;
@@ -39,9 +39,12 @@ struct _KeeEntryClass {
extern const asn1_static_node schema_entry_asn1_tab[];
struct kee_entry_form_t {
+ GtkEntry *bob_name;
+ GtkEntry *bob_pubkey;
GtkEntry *subject;
GtkEntry *uoa;
GtkEntry *uoa_decimals;
+ GtkEntry *passphrase;
};
/// \todo factor out separate struct for listitem
@@ -59,7 +62,7 @@ struct _KeeEntry {
struct Cadiz *resolver;
struct db_ctx *db;
struct kee_entry_form_t *form;
- struct gpg_store *signer;
+ struct gpg_store *gpg;
};
@@ -77,10 +80,15 @@ static void kee_entry_handle_add(GtkButton *butt, KeeEntry *o) {
b = (char*)gtk_entry_buffer_get_text(buf);
o->ledger.uoa_decimals = (char)atoi(b);
+ buf = gtk_entry_get_buffer(o->form->uoa);
+ if (gtk_entry_buffer_get_length(buf) != PUBKEY_LENGTH * 2) {
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "wrong size for counterparty public key");
+ return;
+ }
+ memcpy(o->ledger.pubkey_bob, o->form->bob_pubkey, PUBKEY_LENGTH);
+
o->state |= ENTRYSTATE_LOAD;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "adding ledger entry");
-
-
}
static void kee_entry_handle_item_setup(GtkListItemFactory* o, GtkListItem *item) {
@@ -177,6 +185,20 @@ static void kee_entry_setup_edit_widget(KeeEntry *o) {
o->form = calloc(sizeof(struct kee_entry_form_t), 1);
+ widget = gtk_label_new("counterparty name");
+ gtk_box_append(GTK_BOX(o->edit), widget);
+ widget = gtk_entry_new();
+ o->form->bob_name = GTK_ENTRY(widget);
+ gtk_entry_set_input_purpose(o->form->bob_name, GTK_INPUT_PURPOSE_NAME);
+ gtk_box_append(GTK_BOX(o->edit), widget);
+
+ widget = gtk_label_new("counterparty public key");
+ gtk_box_append(GTK_BOX(o->edit), widget);
+ widget = gtk_entry_new();
+ o->form->bob_pubkey = GTK_ENTRY(widget);
+ gtk_entry_set_max_length(o->form->bob_pubkey, PUBKEY_LENGTH * 2);
+ gtk_box_append(GTK_BOX(o->edit), widget);
+
widget = gtk_label_new("subject");
gtk_box_append(GTK_BOX(o->edit), widget);
widget = gtk_entry_new();
@@ -193,6 +215,16 @@ static void kee_entry_setup_edit_widget(KeeEntry *o) {
gtk_box_append(GTK_BOX(o->edit), widget);
widget = gtk_entry_new();
o->form->uoa_decimals = GTK_ENTRY(widget);
+ gtk_entry_set_input_purpose(o->form->uoa_decimals, GTK_INPUT_PURPOSE_DIGITS);
+ gtk_entry_set_max_length(o->form->uoa_decimals, 2);
+ gtk_box_append(GTK_BOX(o->edit), widget);
+
+ /// \todo DRY - kee-key.c
+ widget = gtk_label_new("private key passphrase");
+ gtk_box_append(GTK_BOX(o->edit), widget);
+ widget = gtk_entry_new();
+ o->form->passphrase = GTK_ENTRY(widget);
+ gtk_entry_set_input_purpose(o->form->passphrase, GTK_INPUT_PURPOSE_PASSWORD);
gtk_box_append(GTK_BOX(o->edit), widget);
widget = gtk_button_new_with_label("add");
@@ -241,7 +273,7 @@ void kee_entry_set_resolver(KeeEntry *o, struct Cadiz *resolver) {
}
void kee_entry_set_signer(KeeEntry *o, struct gpg_store *gpg) {
- o->signer = gpg;
+ o->gpg = gpg;
}
static void kee_entry_init_list_widget(KeeEntry *o) {
diff --git a/src/gtk/kee-menu.c b/src/gtk/kee-menu.c
@@ -7,6 +7,7 @@
#include "menu.h"
#include "nav.h"
#include "err.h"
+#include "context.h"
typedef struct {
} KeeMenuPrivate;
@@ -16,6 +17,7 @@ struct _KeeMenu {
GtkHeaderBar *head;
GtkStack *stack;
struct KeeNav nav;
+ struct kee_context *ctx;
};
struct _KeeMenuClass {
@@ -41,6 +43,7 @@ static void kee_menu_act_new_entry(GAction *act, GVariant *param, KeeMenu *menu)
kee_menu_next(menu, "entry");
o = g_object_new(KEE_TYPE_ENTRY, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
+ kee_entry_set_signer(o, &menu->ctx->gpg);
kee_menu_set(menu, GTK_WIDGET(o));
kee_entry_modeswitch(o, KEE_ENTRY_VIEWMODE_EDIT);
}
@@ -61,12 +64,13 @@ static void kee_menu_init(KeeMenu *o) {
o->stack = GTK_STACK(gtk_stack_new());
}
-KeeMenu* kee_menu_new(GtkApplication *gapp) {
+KeeMenu* kee_menu_new(GtkApplication *gapp, struct kee_context *ctx) {
KeeMenu *o;
GtkWidget *butt;
GSimpleAction *act;
o = g_object_new(KEE_TYPE_MENU, "application", gapp, NULL);
+ o->ctx = ctx;
gtk_widget_set_vexpand(GTK_WIDGET(o->stack), true);
gapp = gtk_window_get_application(GTK_WINDOW(o));
diff --git a/src/gtk/kee-menu.h b/src/gtk/kee-menu.h
@@ -4,6 +4,8 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include "context.h"
+
enum KEE_MENU_PROPS {
KEE_N_MENU_PROPS,
};
@@ -18,7 +20,7 @@ G_BEGIN_DECLS
#define KEE_TYPE_MENU kee_menu_get_type()
G_DECLARE_FINAL_TYPE(KeeMenu, kee_menu, KEE, MENU, GtkApplicationWindow);
-KeeMenu* kee_menu_new(GtkApplication *app);
+KeeMenu* kee_menu_new(GtkApplication *app, struct kee_context *ctx);
int kee_menu_add(KeeMenu *o, const char *k, GtkWidget *v);
GtkWidget* kee_menu_next(KeeMenu *o, const char *k);
int kee_menu_prev(KeeMenu *o);
diff --git a/src/gtk/ui.c b/src/gtk/ui.c
@@ -53,7 +53,7 @@ void ui_build(GtkApplication *app, struct kee_context *ctx) {
KeeMenu *win;
KeeImport *import;
- win = kee_menu_new(app);
+ win = kee_menu_new(app, ctx);
widget = GTK_WIDGET(kee_key_new(&ctx->gpg));
kee_menu_add(win, "unlock", widget);