[gnome-keyring] gcr: Make GcrGnupgKey::keyid full keyid and add short-keyid for display.
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] gcr: Make GcrGnupgKey::keyid full keyid and add short-keyid for display.
- Date: Sun, 15 May 2011 11:09:17 +0000 (UTC)
commit 00607c3b767b03955af981f5586ec4fb72a46ae4
Author: Stef Walter <stefw collabora co uk>
Date: Sun May 15 10:41:15 2011 +0200
gcr: Make GcrGnupgKey::keyid full keyid and add short-keyid for display.
* More documentation fixes and cleanup.
https://bugzilla.gnome.org/show_bug.cgi?id=648019
gcr/gcr-gnupg-key.c | 42 ++++++++++++++++++++++++++++++++++--------
gcr/gcr-gnupg-key.h | 2 ++
gcr/tests/test-gnupg-key.c | 31 +++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 8 deletions(-)
---
diff --git a/gcr/gcr-gnupg-key.c b/gcr/gcr-gnupg-key.c
index a59523a..5c07ac4 100644
--- a/gcr/gcr-gnupg-key.c
+++ b/gcr/gcr-gnupg-key.c
@@ -31,12 +31,13 @@
enum {
PROP_0,
+ PROP_KEYID,
PROP_PUBLIC_DATASET,
PROP_SECRET_DATASET,
PROP_LABEL,
PROP_MARKUP,
PROP_DESCRIPTION,
- PROP_KEYID
+ PROP_SHORT_KEYID
};
struct _GcrGnupgKeyPrivate {
@@ -76,7 +77,7 @@ calculate_markup (GcrGnupgKey *self)
}
static const gchar *
-calculate_keyid (GcrGnupgKey *self)
+calculate_short_keyid (GcrGnupgKey *self)
{
const gchar *keyid;
gsize length;
@@ -143,6 +144,9 @@ _gcr_gnupg_key_get_property (GObject *obj, guint prop_id, GValue *value,
case PROP_SECRET_DATASET:
g_value_set_boxed (value, self->pv->secret_dataset);
break;
+ case PROP_KEYID:
+ g_value_set_string (value, _gcr_gnupg_key_get_keyid (self));
+ break;
case PROP_LABEL:
g_value_take_string (value, calculate_name (self));
break;
@@ -152,8 +156,8 @@ _gcr_gnupg_key_get_property (GObject *obj, guint prop_id, GValue *value,
case PROP_MARKUP:
g_value_take_string (value, calculate_markup (self));
break;
- case PROP_KEYID:
- g_value_set_string (value, calculate_keyid (self));
+ case PROP_SHORT_KEYID:
+ g_value_set_string (value, calculate_short_keyid (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
@@ -193,6 +197,15 @@ _gcr_gnupg_key_class_init (GcrGnupgKeyClass *klass)
G_TYPE_PTR_ARRAY, G_PARAM_READWRITE));
/**
+ * GcrGnupgKey::keyid:
+ *
+ * Key identifier.
+ */
+ g_object_class_install_property (gobject_class, PROP_KEYID,
+ g_param_spec_string ("keyid", "Key ID", "Key identifier",
+ "", G_PARAM_READABLE));
+
+ /**
* GcrGnupgKey::label:
*
* User readable label for this key.
@@ -220,12 +233,12 @@ _gcr_gnupg_key_class_init (GcrGnupgKeyClass *klass)
"", G_PARAM_READABLE));
/**
- * GcrGnupgKey::keyid:
+ * GcrGnupgKey::short-keyid:
*
* User readable key identifier.
*/
- g_object_class_install_property (gobject_class, PROP_KEYID,
- g_param_spec_string ("keyid", "Key ID", "Display key identifier",
+ g_object_class_install_property (gobject_class, PROP_SHORT_KEYID,
+ g_param_spec_string ("short-keyid", "Short Key ID", "Display key identifier",
"", G_PARAM_READABLE));
}
@@ -361,6 +374,19 @@ _gcr_gnupg_key_set_secret_dataset (GcrGnupgKey *self, GPtrArray *dataset)
}
/**
+ * _gcr_gnupg_key_get_keyid:
+ * @self: The key
+ *
+ * Get the keyid for this key.
+ */
+const gchar*
+_gcr_gnupg_key_get_keyid (GcrGnupgKey *self)
+{
+ g_return_val_if_fail (GCR_IS_GNUPG_KEY (self), NULL);
+ return _gcr_gnupg_key_get_keyid_for_colons (self->pv->public_dataset);
+}
+
+/**
* _gcr_gnupg_key_get_keyid_for_colons:
* @dataset: Array of GcrColons*
*
@@ -395,7 +421,7 @@ _gcr_gnupg_key_get_columns (void)
static GcrColumn columns[] = {
{ "label", G_TYPE_STRING, G_TYPE_STRING, NC_("column", "Name"),
GCR_COLUMN_SORTABLE },
- { "keyid", G_TYPE_STRING, G_TYPE_STRING, NC_("column", "Key ID"),
+ { "short-keyid", G_TYPE_STRING, G_TYPE_STRING, NC_("column", "Key ID"),
GCR_COLUMN_SORTABLE },
{ NULL }
};
diff --git a/gcr/gcr-gnupg-key.h b/gcr/gcr-gnupg-key.h
index e6d0235..104c495 100644
--- a/gcr/gcr-gnupg-key.h
+++ b/gcr/gcr-gnupg-key.h
@@ -64,6 +64,8 @@ const GcrColumn* _gcr_gnupg_key_get_columns (void);
GcrGnupgKey* _gcr_gnupg_key_new (GPtrArray *pubset,
GPtrArray *secset);
+const gchar* _gcr_gnupg_key_get_keyid (GcrGnupgKey *self);
+
GPtrArray* _gcr_gnupg_key_get_public_dataset (GcrGnupgKey *self);
void _gcr_gnupg_key_set_public_dataset (GcrGnupgKey *self,
diff --git a/gcr/tests/test-gnupg-key.c b/gcr/tests/test-gnupg-key.c
index dfb19a3..409a3d8 100644
--- a/gcr/tests/test-gnupg-key.c
+++ b/gcr/tests/test-gnupg-key.c
@@ -30,6 +30,7 @@
#include <glib.h>
#include <errno.h>
+#include <stdlib.h>
#include <string.h>
typedef struct {
@@ -76,6 +77,8 @@ static void
teardown (Test *test, gconstpointer unused)
{
g_object_unref (test->key);
+ g_assert (!GCR_IS_GNUPG_KEY (test->key));
+
g_ptr_array_unref (test->dataset);
g_ptr_array_unref (test->pubset);
g_ptr_array_unref (test->secset);
@@ -164,6 +167,32 @@ test_with_secret (Test *test, gconstpointer unused)
g_object_unref (key);
}
+static void
+test_no_change_keyid (Test *test, gconstpointer unused)
+{
+ if (g_test_trap_fork (50000, G_TEST_TRAP_SILENCE_STDERR)) {
+ /* Changing the keyid. This should fail with a warning */
+ _gcr_gnupg_key_set_public_dataset (test->key, test->pubset);
+ exit (0);
+ }
+
+ g_test_trap_assert_failed ();
+ g_test_trap_assert_stderr ("*fingerprint is no longer the same:*");
+}
+
+static void
+test_secret_mismatched_keyid (Test *test, gconstpointer unused)
+{
+ if (g_test_trap_fork (50000, G_TEST_TRAP_SILENCE_STDERR)) {
+ /* Different keyid for secret part. This should fail with a warning */
+ _gcr_gnupg_key_set_secret_dataset (test->key, test->secset);
+ exit (0);
+ }
+
+ g_test_trap_assert_failed ();
+ g_test_trap_assert_stderr ("*pub and sec parts are not the same:*");
+}
+
int
main (int argc, char **argv)
{
@@ -177,6 +206,8 @@ main (int argc, char **argv)
g_test_add ("/gcr/gnupg-key/keyid", Test, NULL, setup, test_keyid, teardown);
g_test_add ("/gcr/gnupg-key/keyid_for_colons", Test, NULL, setup, test_keyid_for_colons, teardown);
g_test_add ("/gcr/gnupg-key/with_secret", Test, NULL, setup, test_with_secret, teardown);
+ g_test_add ("/gcr/gnupg-key/no_change_keyid", Test, NULL, setup, test_no_change_keyid, teardown);
+ g_test_add ("/gcr/gnupg-key/secret_mismatched_keyid", Test, NULL, setup, test_secret_mismatched_keyid, teardown);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]