[gnome-keyring] gcr: Rename GcrColons to GcrRecord
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] gcr: Rename GcrColons to GcrRecord
- Date: Mon, 16 May 2011 05:30:17 +0000 (UTC)
commit 948688d39a4d6e4ff3cf0d8af6c069901cdc6222
Author: Stef Walter <stefw collabora co uk>
Date: Thu May 12 17:31:47 2011 +0200
gcr: Rename GcrColons to GcrRecord
* These records can be used for other purposes as well. Can represent
any data with uniform single character delimiters
.gitignore | 1 +
docs/reference/gcr/gcr-sections.txt | 16 ++--
gcr/Makefile.am | 2 +-
gcr/gcr-gnupg-collection.c | 80 ++++++++--------
gcr/gcr-gnupg-key.c | 162 ++++++++++++++++----------------
gcr/gcr-gnupg-key.h | 14 ++--
gcr/{gcr-colons.c => gcr-record.c} | 78 +++++++++-------
gcr/{gcr-colons.h => gcr-record.h} | 45 +++++----
gcr/tests/Makefile.am | 2 +-
gcr/tests/test-colons.c | 180 -----------------------------------
gcr/tests/test-gnupg-collection.c | 8 +-
gcr/tests/test-gnupg-key.c | 94 +++++++++---------
gcr/tests/test-record.c | 180 +++++++++++++++++++++++++++++++++++
13 files changed, 439 insertions(+), 423 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index f552444..0c871fa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -123,6 +123,7 @@ run-tests
/gcr/tests/test-gnupg-key
/gcr/tests/test-parser
/gcr/tests/test-pkcs11-certificate
+/gcr/tests/test-record
/gcr/tests/test-simple-certificate
/gcr/tests/test-trust
/gcr/tests/test-util
diff --git a/docs/reference/gcr/gcr-sections.txt b/docs/reference/gcr/gcr-sections.txt
index b28a131..d4240e4 100644
--- a/docs/reference/gcr/gcr-sections.txt
+++ b/docs/reference/gcr/gcr-sections.txt
@@ -433,9 +433,9 @@ GcrUnlockOptionsWidgetPrivate
<SECTION>
<FILE>gcr-private</FILE>
<SUBSECTION Private>
-GCR_COLONS_SCHEMA_PUB
-GCR_COLONS_SCHEMA_UID
-GCR_COLONS_SCHEMA_SEC
+GCR_RECORD_SCHEMA_PUB
+GCR_RECORD_SCHEMA_UID
+GCR_RECORD_SCHEMA_SEC
GCR_GNUPG_COLLECTION
GCR_GNUPG_COLLECTION_CLASS
GCR_GNUPG_COLLECTION_GET_CLASS
@@ -449,11 +449,11 @@ GCR_IS_GNUPG_KEY
GCR_IS_GNUPG_KEY_CLASS
GCR_TYPE_GNUPG_COLLECTION
GCR_TYPE_GNUPG_KEY
-GcrColonColumns
-GcrColonPubColumns
-GcrColonUidColumns
-GcrColonSecColumns
-GcrColons
+GcrRecordColumns
+GcrRecordPubColumns
+GcrRecordUidColumns
+GcrRecordSecColumns
+GcrRecord
GcrGnupgCollection
GcrGnupgCollectionClass
GcrGnupgCollectionPrivate
diff --git a/gcr/Makefile.am b/gcr/Makefile.am
index bd20723..d2e7206 100644
--- a/gcr/Makefile.am
+++ b/gcr/Makefile.am
@@ -77,7 +77,6 @@ libgcr GCR_VERSION_SUFFIX@_la_SOURCES = \
gcr-certificate-widget.c gcr-certificate-widget.h \
gcr-collection.c gcr-collection.h \
gcr-collection-model.c gcr-collection-model.h \
- gcr-colons.c gcr-colons.h \
gcr-debug.c gcr-debug.h \
gcr-display-scrolled.c gcr-display-scrolled.h \
gcr-comparable.c gcr-comparable.h \
@@ -93,6 +92,7 @@ libgcr GCR_VERSION_SUFFIX@_la_SOURCES = \
gcr-library.c gcr-library.h \
gcr-parser.c gcr-parser.h \
gcr-pkcs11-certificate.c gcr-pkcs11-certificate.h \
+ gcr-record.c gcr-record.h \
gcr-renderer.c gcr-renderer.h \
gcr-selector.c gcr-selector.h \
gcr-simple-certificate.c gcr-simple-certificate.h \
diff --git a/gcr/gcr-gnupg-collection.c b/gcr/gcr-gnupg-collection.c
index 5a68470..4e3da44 100644
--- a/gcr/gcr-gnupg-collection.c
+++ b/gcr/gcr-gnupg-collection.c
@@ -23,7 +23,7 @@
#include "config.h"
-#include "gcr-colons.h"
+#include "gcr-record.h"
#include "gcr-collection.h"
#define DEBUG_FLAG GCR_DEBUG_GNUPG
#include "gcr-debug.h"
@@ -214,7 +214,7 @@ typedef enum {
typedef struct {
GcrGnupgCollection *collection; /* reffed pointer back to collection */
GcrLoadingPhase loading_phase; /* Whether loading public or private */
- GPtrArray *dataset; /* GcrColons* not yet made into a key */
+ GPtrArray *records; /* GcrRecord* not yet made into a key */
guint spawn_sig;
GString *out_data; /* Pending output not yet parsed into colons */
GString *err_data; /* Pending errors not yet printed */
@@ -230,7 +230,7 @@ _gcr_gnupg_collection_load_free (gpointer data)
GcrGnupgCollectionLoad *load = data;
g_assert (load);
- g_ptr_array_unref (load->dataset);
+ g_ptr_array_unref (load->records);
g_string_free (load->err_data, TRUE);
g_string_free (load->out_data, TRUE);
g_hash_table_destroy (load->difference);
@@ -242,7 +242,7 @@ _gcr_gnupg_collection_load_free (gpointer data)
}
static void
-process_dataset_as_public_key (GcrGnupgCollectionLoad *load, GPtrArray *dataset,
+process_records_as_public_key (GcrGnupgCollectionLoad *load, GPtrArray *records,
const gchar *keyid)
{
GcrGnupgKey *key;
@@ -255,11 +255,11 @@ process_dataset_as_public_key (GcrGnupgCollectionLoad *load, GPtrArray *dataset,
/* Already have this key, just update */
if (key) {
_gcr_debug ("updating public key: %s", keyid);
- _gcr_gnupg_key_set_public_dataset (key, dataset);
+ _gcr_gnupg_key_set_public_records (key, records);
/* Add a new key */
} else {
- key = _gcr_gnupg_key_new (dataset, NULL);
+ key = _gcr_gnupg_key_new (records, NULL);
_gcr_debug ("creating public key: %s", keyid);
g_hash_table_insert (load->collection->pv->items, g_strdup (keyid), key);
gcr_collection_emit_added (GCR_COLLECTION (load->collection), G_OBJECT (key));
@@ -267,7 +267,7 @@ process_dataset_as_public_key (GcrGnupgCollectionLoad *load, GPtrArray *dataset,
}
static void
-process_dataset_as_secret_key (GcrGnupgCollectionLoad *load, GPtrArray *dataset,
+process_records_as_secret_key (GcrGnupgCollectionLoad *load, GPtrArray *records,
const gchar *keyid)
{
GcrGnupgKey *key;
@@ -280,34 +280,34 @@ process_dataset_as_secret_key (GcrGnupgCollectionLoad *load, GPtrArray *dataset,
/* Tell the private key that it's a secret one */
} else {
- _gcr_debug ("adding secret dataset to key: %s", keyid);
- _gcr_gnupg_key_set_secret_dataset (key, dataset);
+ _gcr_debug ("adding secret records to key: %s", keyid);
+ _gcr_gnupg_key_set_secret_records (key, records);
}
}
static void
-process_dataset_as_key (GcrGnupgCollectionLoad *load)
+process_records_as_key (GcrGnupgCollectionLoad *load)
{
- GPtrArray *dataset;
+ GPtrArray *records;
const gchar *keyid;
GQuark schema;
- g_assert (load->dataset->len);
+ g_assert (load->records->len);
- dataset = load->dataset;
- load->dataset = g_ptr_array_new_with_free_func (_gcr_colons_free);
+ records = load->records;
+ load->records = g_ptr_array_new_with_free_func (_gcr_record_free);
- keyid = _gcr_gnupg_key_get_keyid_for_colons (dataset);
+ keyid = _gcr_gnupg_key_get_keyid_for_records (records);
if (keyid) {
- schema = _gcr_colons_get_schema (dataset->pdata[0]);
+ schema = _gcr_record_get_schema (records->pdata[0]);
/* A public key */
- if (schema == GCR_COLONS_SCHEMA_PUB)
- process_dataset_as_public_key (load, dataset, keyid);
+ if (schema == GCR_RECORD_SCHEMA_PUB)
+ process_records_as_public_key (load, records, keyid);
/* A secret key */
- else if (schema == GCR_COLONS_SCHEMA_SEC)
- process_dataset_as_secret_key (load, dataset, keyid);
+ else if (schema == GCR_RECORD_SCHEMA_SEC)
+ process_records_as_secret_key (load, records, keyid);
else
g_assert_not_reached ();
@@ -316,50 +316,50 @@ process_dataset_as_key (GcrGnupgCollectionLoad *load)
g_warning ("parsed gnupg data had no keyid");
}
- g_ptr_array_unref (dataset);
+ g_ptr_array_unref (records);
}
static void
on_line_parse_output (const gchar *line, gpointer user_data)
{
GcrGnupgCollectionLoad *load = user_data;
- GcrColons *colons;
+ GcrRecord *record;
GQuark schema;
_gcr_debug ("output: %s", line);
- colons = _gcr_colons_parse (line, -1);
- if (!colons) {
+ record = _gcr_record_parse_colons (line, -1);
+ if (!record) {
g_warning ("invalid gnupg output line: %s", line);
return;
}
- schema = _gcr_colons_get_schema (colons);
+ schema = _gcr_record_get_schema (record);
/*
* Each time we see a line with 'pub' or 'sec' schema we assume that
* it's a new key being listed.
*/
- if (schema == GCR_COLONS_SCHEMA_PUB || schema == GCR_COLONS_SCHEMA_SEC) {
+ if (schema == GCR_RECORD_SCHEMA_PUB || schema == GCR_RECORD_SCHEMA_SEC) {
_gcr_debug ("start of new key");
- if (load->dataset->len)
- process_dataset_as_key (load);
- g_assert (!load->dataset->len);
- g_ptr_array_add (load->dataset, colons);
- colons = NULL;
+ if (load->records->len)
+ process_records_as_key (load);
+ g_assert (!load->records->len);
+ g_ptr_array_add (load->records, record);
+ record = NULL;
/*
* 'uid' schema lines get added to the key that came before.
*/
- } else if (schema == GCR_COLONS_SCHEMA_UID) {
- if (load->dataset->len) {
- g_ptr_array_add (load->dataset, colons);
- colons = NULL;
+ } else if (schema == GCR_RECORD_SCHEMA_UID) {
+ if (load->records->len) {
+ g_ptr_array_add (load->records, record);
+ record = NULL;
}
}
- if (colons != NULL)
- _gcr_colons_free (colons);
+ if (record != NULL)
+ _gcr_record_free (record);
}
@@ -429,8 +429,8 @@ on_spawn_completed (gpointer user_data)
_gcr_util_parse_lines (load->out_data, TRUE, on_line_parse_output, load);
/* Process last bit as a key, if any */
- if (load->dataset->len)
- process_dataset_as_key (load);
+ if (load->records->len)
+ process_records_as_key (load);
/* If we completed loading public keys, then go and load secret */
switch (load->loading_phase) {
@@ -577,7 +577,7 @@ _gcr_gnupg_collection_load_async (GcrGnupgCollection *self, GCancellable *cancel
_gcr_gnupg_collection_load_async);
load = g_slice_new0 (GcrGnupgCollectionLoad);
- load->dataset = g_ptr_array_new_with_free_func (_gcr_colons_free);
+ load->records = g_ptr_array_new_with_free_func (_gcr_record_free);
load->err_data = g_string_sized_new (128);
load->out_data = g_string_sized_new (1024);
load->collection = g_object_ref (self);
diff --git a/gcr/gcr-gnupg-key.c b/gcr/gcr-gnupg-key.c
index 079358f..31ab77b 100644
--- a/gcr/gcr-gnupg-key.c
+++ b/gcr/gcr-gnupg-key.c
@@ -21,7 +21,7 @@
#include "config.h"
-#include "gcr-colons.h"
+#include "gcr-record.h"
#include "gcr-gnupg-key.h"
#include "gck/gck.h"
@@ -32,8 +32,8 @@
enum {
PROP_0,
PROP_KEYID,
- PROP_PUBLIC_DATASET,
- PROP_SECRET_DATASET,
+ PROP_PUBLIC_RECORDS,
+ PROP_SECRET_RECORDS,
PROP_LABEL,
PROP_MARKUP,
PROP_DESCRIPTION,
@@ -41,8 +41,8 @@ enum {
};
struct _GcrGnupgKeyPrivate {
- GPtrArray *public_dataset;
- GPtrArray *secret_dataset;
+ GPtrArray *public_records;
+ GPtrArray *secret_records;
};
G_DEFINE_TYPE (GcrGnupgKey, _gcr_gnupg_key, G_TYPE_OBJECT);
@@ -54,12 +54,12 @@ G_DEFINE_TYPE (GcrGnupgKey, _gcr_gnupg_key, G_TYPE_OBJECT);
static gchar *
calculate_name (GcrGnupgKey *self)
{
- GcrColons* colons;
+ GcrRecord* record;
- colons = _gcr_colons_find (self->pv->public_dataset, GCR_COLONS_SCHEMA_UID);
- g_return_val_if_fail (colons, NULL);
+ record = _gcr_record_find (self->pv->public_records, GCR_RECORD_SCHEMA_UID);
+ g_return_val_if_fail (record, NULL);
- return _gcr_colons_get_string (colons, GCR_COLONS_UID_NAME);
+ return _gcr_record_get_string (record, GCR_RECORD_UID_NAME);
}
static gchar *
@@ -82,7 +82,7 @@ calculate_short_keyid (GcrGnupgKey *self)
const gchar *keyid;
gsize length;
- keyid = _gcr_gnupg_key_get_keyid_for_colons (self->pv->public_dataset);
+ keyid = _gcr_gnupg_key_get_keyid_for_records (self->pv->public_records);
if (keyid == NULL)
return NULL;
@@ -104,10 +104,10 @@ _gcr_gnupg_key_finalize (GObject *obj)
{
GcrGnupgKey *self = GCR_GNUPG_KEY (obj);
- if (self->pv->public_dataset)
- g_ptr_array_free (self->pv->public_dataset, TRUE);
- if (self->pv->secret_dataset)
- g_ptr_array_free (self->pv->secret_dataset, TRUE);
+ if (self->pv->public_records)
+ g_ptr_array_free (self->pv->public_records, TRUE);
+ if (self->pv->secret_records)
+ g_ptr_array_free (self->pv->secret_records, TRUE);
G_OBJECT_CLASS (_gcr_gnupg_key_parent_class)->finalize (obj);
}
@@ -119,11 +119,11 @@ _gcr_gnupg_key_set_property (GObject *obj, guint prop_id, const GValue *value,
GcrGnupgKey *self = GCR_GNUPG_KEY (obj);
switch (prop_id) {
- case PROP_PUBLIC_DATASET:
- _gcr_gnupg_key_set_public_dataset (self, g_value_get_boxed (value));
+ case PROP_PUBLIC_RECORDS:
+ _gcr_gnupg_key_set_public_records (self, g_value_get_boxed (value));
break;
- case PROP_SECRET_DATASET:
- _gcr_gnupg_key_set_secret_dataset (self, g_value_get_boxed (value));
+ case PROP_SECRET_RECORDS:
+ _gcr_gnupg_key_set_secret_records (self, g_value_get_boxed (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
@@ -138,11 +138,11 @@ _gcr_gnupg_key_get_property (GObject *obj, guint prop_id, GValue *value,
GcrGnupgKey *self = GCR_GNUPG_KEY (obj);
switch (prop_id) {
- case PROP_PUBLIC_DATASET:
- g_value_set_boxed (value, self->pv->public_dataset);
+ case PROP_PUBLIC_RECORDS:
+ g_value_set_boxed (value, self->pv->public_records);
break;
- case PROP_SECRET_DATASET:
- g_value_set_boxed (value, self->pv->secret_dataset);
+ case PROP_SECRET_RECORDS:
+ g_value_set_boxed (value, self->pv->secret_records);
break;
case PROP_KEYID:
g_value_set_string (value, _gcr_gnupg_key_get_keyid (self));
@@ -178,22 +178,22 @@ _gcr_gnupg_key_class_init (GcrGnupgKeyClass *klass)
gobject_class->get_property = _gcr_gnupg_key_get_property;
/**
- * GcrGnupgKey::public-dataset:
+ * GcrGnupgKey::public-records:
*
* Public key data. Should always be present.
*/
- g_object_class_install_property (gobject_class, PROP_PUBLIC_DATASET,
- g_param_spec_boxed ("public-dataset", "Public Dataset", "Public Key Colon Dataset",
+ g_object_class_install_property (gobject_class, PROP_PUBLIC_RECORDS,
+ g_param_spec_boxed ("public-records", "Public Records", "Public Key Colon Records",
G_TYPE_PTR_ARRAY, G_PARAM_READWRITE));
/**
- * GcrGnupgKey::secret-dataset:
+ * GcrGnupgKey::secret-records:
*
* Secret key data. The keyid of this data must match public-dataset.
* If present, this key represents a secret key.
*/
- g_object_class_install_property (gobject_class, PROP_SECRET_DATASET,
- g_param_spec_boxed ("secret-dataset", "Secret Dataset", "Secret Key Colon Dataset",
+ g_object_class_install_property (gobject_class, PROP_SECRET_RECORDS,
+ g_param_spec_boxed ("secret-records", "Secret Records", "Secret Key Colon Records",
G_TYPE_PTR_ARRAY, G_PARAM_READWRITE));
/**
@@ -244,10 +244,10 @@ _gcr_gnupg_key_class_init (GcrGnupgKeyClass *klass)
/**
* _gcr_gnupg_key_new:
- * @pubset: array of GcrColons* representing public part of key
- * @secset: (allow-none): array of GcrColons* representing secret part of key.
+ * @pubset: array of GcrRecord* representing public part of key
+ * @secset: (allow-none): array of GcrRecord* representing secret part of key.
*
- * Create a new GcrGnupgKey for the colons data passed. If the secret part
+ * Create a new GcrGnupgKey for the record data passed. If the secret part
* of the key is set, then this represents a secret key; otherwise it represents
* a public key.
*
@@ -258,45 +258,45 @@ _gcr_gnupg_key_new (GPtrArray *pubset, GPtrArray *secset)
{
g_return_val_if_fail (pubset, NULL);
return g_object_new (GCR_TYPE_GNUPG_KEY,
- "public-dataset", pubset,
- "secret-dataset", secset,
+ "public-records", pubset,
+ "secret-records", secset,
NULL);
}
/**
- * _gcr_gnupg_key_get_public_dataset:
+ * _gcr_gnupg_key_get_public_records:
* @self: The key
*
- * Get the colons data this key is based on.
+ * Get the record data this key is based on.
*
- * Returns: (transfer none): An array of GcrColons*.
+ * Returns: (transfer none): An array of GcrRecord*.
*/
GPtrArray*
-_gcr_gnupg_key_get_public_dataset (GcrGnupgKey *self)
+_gcr_gnupg_key_get_public_records (GcrGnupgKey *self)
{
g_return_val_if_fail (GCR_IS_GNUPG_KEY (self), NULL);
- return self->pv->public_dataset;
+ return self->pv->public_records;
}
/**
- * _gcr_gnupg_key_set_public_dataset:
+ * _gcr_gnupg_key_set_public_records:
* @self: The key
- * @dataset: The new array of GcrColons*
+ * @records: The new array of GcrRecord*
*
- * Change the colons data that this key is based on.
+ * Change the record data that this key is based on.
*/
void
-_gcr_gnupg_key_set_public_dataset (GcrGnupgKey *self, GPtrArray *dataset)
+_gcr_gnupg_key_set_public_records (GcrGnupgKey *self, GPtrArray *records)
{
GObject *obj;
g_return_if_fail (GCR_IS_GNUPG_KEY (self));
- g_return_if_fail (dataset);
+ g_return_if_fail (records);
/* Check that it matches previous */
- if (self->pv->public_dataset) {
- const gchar *old_keyid = _gcr_gnupg_key_get_keyid_for_colons (self->pv->public_dataset);
- const gchar *new_keyid = _gcr_gnupg_key_get_keyid_for_colons (dataset);
+ if (self->pv->public_records) {
+ const gchar *old_keyid = _gcr_gnupg_key_get_keyid_for_records (self->pv->public_records);
+ const gchar *new_keyid = _gcr_gnupg_key_get_keyid_for_records (records);
if (g_strcmp0 (old_keyid, new_keyid) != 0) {
g_warning ("it is an error to change a gnupg key so that the "
@@ -306,52 +306,52 @@ _gcr_gnupg_key_set_public_dataset (GcrGnupgKey *self, GPtrArray *dataset)
}
}
- g_ptr_array_ref (dataset);
- if (self->pv->public_dataset)
- g_ptr_array_unref (self->pv->public_dataset);
- self->pv->public_dataset = dataset;
+ g_ptr_array_ref (records);
+ if (self->pv->public_records)
+ g_ptr_array_unref (self->pv->public_records);
+ self->pv->public_records = records;
obj = G_OBJECT (self);
g_object_freeze_notify (obj);
- g_object_notify (obj, "public-dataset");
+ g_object_notify (obj, "public-records");
g_object_notify (obj, "label");
g_object_notify (obj, "markup");
g_object_thaw_notify (obj);
}
/**
- * _gcr_gnupg_key_get_secret_dataset:
+ * _gcr_gnupg_key_get_secret_records:
* @self: The key
*
- * Get the colons secret data this key is based on. %NULL if a public key.
+ * Get the record secret data this key is based on. %NULL if a public key.
*
* Returns: (transfer none) (allow-none): An array of GcrColons*.
*/
GPtrArray*
-_gcr_gnupg_key_get_secret_dataset (GcrGnupgKey *self)
+_gcr_gnupg_key_get_secret_records (GcrGnupgKey *self)
{
g_return_val_if_fail (GCR_IS_GNUPG_KEY (self), NULL);
- return self->pv->secret_dataset;
+ return self->pv->secret_records;
}
/**
- * _gcr_gnupg_key_set_secret_dataset:
+ * _gcr_gnupg_key_set_secret_records:
* @self: The key
- * @dataset: (allow-none): The new array of GcrColons*
+ * @records: (allow-none): The new array of GcrRecord*
*
* Set the secret data for this key. %NULL if public key.
*/
void
-_gcr_gnupg_key_set_secret_dataset (GcrGnupgKey *self, GPtrArray *dataset)
+_gcr_gnupg_key_set_secret_records (GcrGnupgKey *self, GPtrArray *records)
{
GObject *obj;
g_return_if_fail (GCR_IS_GNUPG_KEY (self));
/* Check that it matches public key */
- if (self->pv->public_dataset && dataset) {
- const gchar *pub_keyid = _gcr_gnupg_key_get_keyid_for_colons (self->pv->public_dataset);
- const gchar *sec_keyid = _gcr_gnupg_key_get_keyid_for_colons (dataset);
+ if (self->pv->public_records && records) {
+ const gchar *pub_keyid = _gcr_gnupg_key_get_keyid_for_records (self->pv->public_records);
+ const gchar *sec_keyid = _gcr_gnupg_key_get_keyid_for_records (records);
if (g_strcmp0 (pub_keyid, sec_keyid) != 0) {
g_warning ("it is an error to create a gnupg key so that the "
@@ -361,15 +361,15 @@ _gcr_gnupg_key_set_secret_dataset (GcrGnupgKey *self, GPtrArray *dataset)
}
}
- if (dataset)
- g_ptr_array_ref (dataset);
- if (self->pv->secret_dataset)
- g_ptr_array_unref (self->pv->secret_dataset);
- self->pv->secret_dataset = dataset;
+ if (records)
+ g_ptr_array_ref (records);
+ if (self->pv->secret_records)
+ g_ptr_array_unref (self->pv->secret_records);
+ self->pv->secret_records = records;
obj = G_OBJECT (self);
g_object_freeze_notify (obj);
- g_object_notify (obj, "secret-dataset");
+ g_object_notify (obj, "secret-records");
g_object_thaw_notify (obj);
}
@@ -378,33 +378,35 @@ _gcr_gnupg_key_set_secret_dataset (GcrGnupgKey *self, GPtrArray *dataset)
* @self: The key
*
* Get the keyid for this key.
+ *
+ * Returns: (transfer none): The keyid.
*/
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);
+ return _gcr_gnupg_key_get_keyid_for_records (self->pv->public_records);
}
/**
- * _gcr_gnupg_key_get_keyid_for_colons:
- * @dataset: Array of GcrColons*
+ * _gcr_gnupg_key_get_keyid_for_records:
+ * @records: Array of GcrRecord*
*
- * Get the keyid for some colons data.
+ * Get the keyid for some record data.
*
* Returns: (transfer none): The keyid.
*/
const gchar*
-_gcr_gnupg_key_get_keyid_for_colons (GPtrArray *dataset)
+_gcr_gnupg_key_get_keyid_for_records (GPtrArray *records)
{
- GcrColons *colons;
-
- colons = _gcr_colons_find (dataset, GCR_COLONS_SCHEMA_PUB);
- if (colons != NULL)
- return _gcr_colons_get_raw (colons, GCR_COLONS_PUB_KEYID);
- colons = _gcr_colons_find (dataset, GCR_COLONS_SCHEMA_SEC);
- if (colons != NULL)
- return _gcr_colons_get_raw (colons, GCR_COLONS_SEC_KEYID);
+ GcrRecord *record;
+
+ record = _gcr_record_find (records, GCR_RECORD_SCHEMA_PUB);
+ if (record != NULL)
+ return _gcr_record_get_raw (record, GCR_RECORD_PUB_KEYID);
+ record = _gcr_record_find (records, GCR_RECORD_SCHEMA_SEC);
+ if (record != NULL)
+ return _gcr_record_get_raw (record, GCR_RECORD_SEC_KEYID);
return NULL;
}
diff --git a/gcr/gcr-gnupg-key.h b/gcr/gcr-gnupg-key.h
index 104c495..dcef960 100644
--- a/gcr/gcr-gnupg-key.h
+++ b/gcr/gcr-gnupg-key.h
@@ -66,17 +66,17 @@ GcrGnupgKey* _gcr_gnupg_key_new (GPtrArray *pub
const gchar* _gcr_gnupg_key_get_keyid (GcrGnupgKey *self);
-GPtrArray* _gcr_gnupg_key_get_public_dataset (GcrGnupgKey *self);
+GPtrArray* _gcr_gnupg_key_get_public_records (GcrGnupgKey *self);
-void _gcr_gnupg_key_set_public_dataset (GcrGnupgKey *self,
- GPtrArray *dataset);
+void _gcr_gnupg_key_set_public_records (GcrGnupgKey *self,
+ GPtrArray *records);
-GPtrArray* _gcr_gnupg_key_get_secret_dataset (GcrGnupgKey *self);
+GPtrArray* _gcr_gnupg_key_get_secret_records (GcrGnupgKey *self);
-void _gcr_gnupg_key_set_secret_dataset (GcrGnupgKey *self,
- GPtrArray *dataset);
+void _gcr_gnupg_key_set_secret_records (GcrGnupgKey *self,
+ GPtrArray *records);
-const gchar* _gcr_gnupg_key_get_keyid_for_colons (GPtrArray *dataset);
+const gchar* _gcr_gnupg_key_get_keyid_for_records (GPtrArray *records);
G_END_DECLS
diff --git a/gcr/gcr-colons.c b/gcr/gcr-record.c
similarity index 61%
rename from gcr/gcr-colons.c
rename to gcr/gcr-record.c
index 2695b1d..25a1bb2 100644
--- a/gcr/gcr-colons.c
+++ b/gcr/gcr-record.c
@@ -23,7 +23,7 @@
#include "config.h"
-#include "gcr-colons.h"
+#include "gcr-record.h"
#define DEBUG_FLAG GCR_DEBUG_PARSE
#include "gcr-debug.h"
@@ -31,30 +31,31 @@
#define MAX_COLUMNS 32
-struct _GcrColons {
+struct _GcrRecord {
gchar *data;
- gpointer columns[MAX_COLUMNS];
+ gchar *columns[MAX_COLUMNS];
guint n_columns;
};
-GcrColons*
-_gcr_colons_parse (const gchar *line, gssize n_line)
+static GcrRecord*
+parse_internal (gchar *line, gsize n_line)
{
- GcrColons *result;
+ GcrRecord *result;
gchar *p;
- g_return_val_if_fail (line, NULL);
- if (n_line < 0)
- n_line = strlen (line);
+ g_assert (line);
+ g_assert (n_line);
- result = g_slice_new0 (GcrColons);
- result->data = g_strndup (line, n_line);
+ result = g_slice_new0 (GcrRecord);
+ result->data = line;
+
+ _gcr_debug ("parsing line %.*s", (gint)n_line, line);
p = result->data;
for (;;) {
if (result->n_columns >= MAX_COLUMNS) {
- _gcr_debug ("too many colons in gnupg line: %.*s", (gint)n_line, line);
- _gcr_colons_free (result);
+ _gcr_debug ("too many record (%d) in gnupg line", MAX_COLUMNS);
+ _gcr_record_free (result);
return NULL;
}
@@ -68,36 +69,45 @@ _gcr_colons_parse (const gchar *line, gssize n_line)
p++;
}
- _gcr_debug ("parsed line %.*s into %d columns", (gint)n_line, line, result->n_columns);
return result;
}
-GcrColons*
-_gcr_colons_find (GPtrArray *dataset, GQuark schema)
+GcrRecord*
+_gcr_record_parse_colons (const gchar *line, gssize n_line)
+{
+ g_return_val_if_fail (line, NULL);
+ if (n_line < 0)
+ n_line = strlen (line);
+
+ return parse_internal (g_strndup (line, n_line), n_line);
+}
+
+GcrRecord*
+_gcr_record_find (GPtrArray *records, GQuark schema)
{
guint i;
- g_return_val_if_fail (dataset, NULL);
+ g_return_val_if_fail (records, NULL);
g_return_val_if_fail (schema, NULL);
- for (i = 0; i < dataset->len; i++) {
- if (schema == _gcr_colons_get_schema (dataset->pdata[i]))
- return dataset->pdata[i];
+ for (i = 0; i < records->len; i++) {
+ if (schema == _gcr_record_get_schema (records->pdata[i]))
+ return records->pdata[i];
}
return NULL;
}
gchar*
-_gcr_colons_get_string (GcrColons *colons, guint column)
+_gcr_record_get_string (GcrRecord *record, guint column)
{
const gchar *value;
gchar *text;
gchar *converted;
- g_return_val_if_fail (colons, NULL);
+ g_return_val_if_fail (record, NULL);
- value = _gcr_colons_get_raw (colons, column);
+ value = _gcr_record_get_raw (record, column);
if (!value)
return NULL;
text = g_strcompress (value);
@@ -117,35 +127,35 @@ _gcr_colons_get_string (GcrColons *colons, guint column)
}
const gchar*
-_gcr_colons_get_raw (GcrColons *colons, guint column)
+_gcr_record_get_raw (GcrRecord *record, guint column)
{
- g_return_val_if_fail (colons, NULL);
+ g_return_val_if_fail (record, NULL);
- if (column >= colons->n_columns) {
+ if (column >= record->n_columns) {
_gcr_debug ("only %d columns exist, tried to access %d",
- colons->n_columns, column);
+ record->n_columns, column);
return NULL;
}
- return colons->columns[column];
+ return record->columns[column];
}
void
-_gcr_colons_free (gpointer colons)
+_gcr_record_free (gpointer record)
{
- if (!colons)
+ if (!record)
return;
- g_free (((GcrColons*)colons)->data);
- g_slice_free (GcrColons, colons);
+ g_free (((GcrRecord*)record)->data);
+ g_slice_free (GcrRecord, record);
}
GQuark
-_gcr_colons_get_schema (GcrColons *colons)
+_gcr_record_get_schema (GcrRecord *record)
{
const gchar *value;
- value = _gcr_colons_get_raw (colons, GCR_COLONS_SCHEMA);
+ value = _gcr_record_get_raw (record, GCR_RECORD_SCHEMA);
if (value != NULL)
return g_quark_try_string (value);
return 0;
diff --git a/gcr/gcr-colons.h b/gcr/gcr-record.h
similarity index 71%
rename from gcr/gcr-colons.h
rename to gcr/gcr-record.h
index ac89681..b3a54ae 100644
--- a/gcr/gcr-colons.h
+++ b/gcr/gcr-record.h
@@ -25,8 +25,8 @@
#error "Only <gcr/gcr.h> can be included directly."
#endif
-#ifndef GCR_GNUPG_COLONS_H
-#define GCR_GNUPG_COLONS_H
+#ifndef GCR_RECORD_H
+#define GCR_RECORD_H
#include <glib.h>
@@ -50,57 +50,60 @@
G_BEGIN_DECLS
-#define GCR_COLONS_SCHEMA_UID (g_quark_from_static_string ("uid"))
-#define GCR_COLONS_SCHEMA_PUB (g_quark_from_static_string ("pub"))
-#define GCR_COLONS_SCHEMA_SEC (g_quark_from_static_string ("sec"))
+#define GCR_RECORD_SCHEMA_UID (g_quark_from_static_string ("uid"))
+#define GCR_RECORD_SCHEMA_PUB (g_quark_from_static_string ("pub"))
+#define GCR_RECORD_SCHEMA_SEC (g_quark_from_static_string ("sec"))
/* Common columns for all schemas */
typedef enum {
- GCR_COLONS_SCHEMA = 0
-} GcrColonColumns;
+ GCR_RECORD_SCHEMA = 0
+} GcrRecordColumns;
/*
* Columns for pub schema, add them as they're used. eg:
* pub:f:1024:17:6C7EE1B8621CC013:899817715:1055898235::m:::scESC:
*/
typedef enum {
- GCR_COLONS_PUB_KEYID = 4
-} GcrColonPubColumns;
+ GCR_RECORD_PUB_KEYID = 4
+} GcrRecordPubColumns;
/*
* Columns for sec schema, add them as they're used. eg:
* sec::2048:1:293FC71A513189BD:1299771018::::::::::
*/
typedef enum {
- GCR_COLONS_SEC_KEYID = 4
-} GcrColonSecColumns;
+ GCR_RECORD_SEC_KEYID = 4
+} GcrRecordSecColumns;
/*
* Columns for uid schema, add them as they're used. eg:
* pub:f:1024:17:6C7EE1B8621CC013:899817715:1055898235::m:::scESC:
*/
typedef enum {
- GCR_COLONS_UID_NAME = 9
-} GcrColonUidColumns;
+ GCR_RECORD_UID_NAME = 9
+} GcrRecordUidColumns;
-typedef struct _GcrColons GcrColons;
+typedef struct _GcrRecord GcrRecord;
-GcrColons* _gcr_colons_parse (const gchar *line,
+GcrRecord* _gcr_record_parse_colons (const gchar *line,
gssize n_line);
-void _gcr_colons_free (gpointer colons);
+GcrRecord* _gcr_record_parse_spaces (const gchar *line,
+ gssize n_line);
+
+void _gcr_record_free (gpointer record);
-GcrColons* _gcr_colons_find (GPtrArray *dataset,
+GcrRecord* _gcr_record_find (GPtrArray *records,
GQuark schema);
-gchar* _gcr_colons_get_string (GcrColons *colons,
+gchar* _gcr_record_get_string (GcrRecord *record,
guint column);
-const gchar* _gcr_colons_get_raw (GcrColons *colons,
+const gchar* _gcr_record_get_raw (GcrRecord *record,
guint column);
-GQuark _gcr_colons_get_schema (GcrColons *colons);
+GQuark _gcr_record_get_schema (GcrRecord *record);
G_END_DECLS
-#endif /* GCR_GNUPG_COLONS_H */
+#endif /* GCR_RECORD_H */
diff --git a/gcr/tests/Makefile.am b/gcr/tests/Makefile.am
index 9a74eb9..de8eefb 100644
--- a/gcr/tests/Makefile.am
+++ b/gcr/tests/Makefile.am
@@ -27,7 +27,7 @@ TEST_PROGS = \
test-pkcs11-certificate \
test-trust \
test-parser \
- test-colons \
+ test-record \
test-gnupg-key \
test-gnupg-collection
diff --git a/gcr/tests/test-gnupg-collection.c b/gcr/tests/test-gnupg-collection.c
index acfb186..e76b29a 100644
--- a/gcr/tests/test-gnupg-collection.c
+++ b/gcr/tests/test-gnupg-collection.c
@@ -135,12 +135,12 @@ test_load (Test *test, gconstpointer unused)
/* Werner Koch (a public key) */
key = g_hash_table_lookup (test->keys, "5DE249965B0358A2");
g_assert (GCR_IS_GNUPG_KEY (key));
- g_assert (_gcr_gnupg_key_get_secret_dataset (key) == NULL);
+ g_assert (_gcr_gnupg_key_get_secret_records (key) == NULL);
/* Test Number 2 (a secret key)*/
key = g_hash_table_lookup (test->keys, "268FEE686262C395");
g_assert (GCR_IS_GNUPG_KEY (key));
- g_assert (_gcr_gnupg_key_get_secret_dataset (key));
+ g_assert (_gcr_gnupg_key_get_secret_records (key));
}
static void
@@ -167,12 +167,12 @@ test_reload (Test *test, gconstpointer unused)
/* Werner Koch (a public key) */
key = g_hash_table_lookup (test->keys, "5DE249965B0358A2");
g_assert (GCR_IS_GNUPG_KEY (key));
- g_assert (_gcr_gnupg_key_get_secret_dataset (key) == NULL);
+ g_assert (_gcr_gnupg_key_get_secret_records (key) == NULL);
/* Test Number 2 (a secret key)*/
key = g_hash_table_lookup (test->keys, "268FEE686262C395");
g_assert (GCR_IS_GNUPG_KEY (key));
- g_assert (_gcr_gnupg_key_get_secret_dataset (key));
+ g_assert (_gcr_gnupg_key_get_secret_records (key));
}
int
diff --git a/gcr/tests/test-gnupg-key.c b/gcr/tests/test-gnupg-key.c
index f1f58fe..ec6547d 100644
--- a/gcr/tests/test-gnupg-key.c
+++ b/gcr/tests/test-gnupg-key.c
@@ -22,7 +22,7 @@
#include "config.h"
-#include "gcr/gcr-colons.h"
+#include "gcr/gcr-record.h"
#include "gcr/gcr-gnupg-key.h"
#include "egg/egg-testing.h"
@@ -34,7 +34,7 @@
#include <string.h>
typedef struct {
- GPtrArray *dataset;
+ GPtrArray *records;
GPtrArray *pubset;
GPtrArray *secset;
GcrGnupgKey *key;
@@ -43,34 +43,34 @@ typedef struct {
static void
setup (Test *test, gconstpointer unused)
{
- GPtrArray *dataset;
-
- dataset = g_ptr_array_new_with_free_func (_gcr_colons_free);
- g_ptr_array_add (dataset, _gcr_colons_parse ("pub:f:1024:17:6C7EE1B8621CC013:899817715:1055898235::m:::scESC:", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("fpr:::::::::ECAF7590EB3443B5C7CF3ACB6C7EE1B8621CC013:", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("uid:f::::::::Werner Koch <wk g10code com>:\n", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("uid:f::::::::Werner Koch <wk gnupg org>:\n", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("sub:f:1536:16:06AD222CADF6A6E1:919537416:1036177416:::::e:\n", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("fpr:::::::::CF8BCC4B18DE08FCD8A1615906AD222CADF6A6E1:\n", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("sub:r:1536:20:5CE086B5B5A18FF4:899817788:1025961788:::::esc:\n", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("fpr:::::::::AB059359A3B81F410FCFF97F5CE086B5B5A18FF4:", -1));
- test->dataset = dataset;
-
- test->key = _gcr_gnupg_key_new (dataset, NULL);
-
- dataset = g_ptr_array_new_with_free_func (_gcr_colons_free);
- g_ptr_array_add (dataset, _gcr_colons_parse ("pub:u:2048:1:4842D952AFC000FD:1305189489:::u:::scESC:", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("uid:u::::1305189849::D0A8FA7B15DC4BE3F8F03A49C372F2718C78AFC0::Dr. Strangelove <lovingbomb example com>:", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("uid:u::::1305189489::D449F1605254754B0BBFA424FC34E50609103BBB::Test Number 1 (unlimited) <test-number-1 example com>:", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("sub:u:2048:1:4852132BBED15014:1305189489::::::e:", -1));
- test->pubset = dataset;
-
- dataset = g_ptr_array_new_with_free_func (_gcr_colons_free);
- g_ptr_array_add (dataset, _gcr_colons_parse ("sec::2048:1:4842D952AFC000FD:1305189489::::::::::", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("uid:::::::D449F1605254754B0BBFA424FC34E50609103BBB::Test Number 1 (unlimited) <test-number-1 example com>:", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("uid:::::::D0A8FA7B15DC4BE3F8F03A49C372F2718C78AFC0::Dr. Strangelove <lovingbomb example com>:", -1));
- g_ptr_array_add (dataset, _gcr_colons_parse ("ssb::2048:1:4852132BBED15014:1305189489::::::::::", -1));
- test->secset = dataset;
+ GPtrArray *records;
+
+ records = g_ptr_array_new_with_free_func (_gcr_record_free);
+ g_ptr_array_add (records, _gcr_record_parse_colons ("pub:f:1024:17:6C7EE1B8621CC013:899817715:1055898235::m:::scESC:", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("fpr:::::::::ECAF7590EB3443B5C7CF3ACB6C7EE1B8621CC013:", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("uid:f::::::::Werner Koch <wk g10code com>:\n", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("uid:f::::::::Werner Koch <wk gnupg org>:\n", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("sub:f:1536:16:06AD222CADF6A6E1:919537416:1036177416:::::e:\n", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("fpr:::::::::CF8BCC4B18DE08FCD8A1615906AD222CADF6A6E1:\n", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("sub:r:1536:20:5CE086B5B5A18FF4:899817788:1025961788:::::esc:\n", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("fpr:::::::::AB059359A3B81F410FCFF97F5CE086B5B5A18FF4:", -1));
+ test->records = records;
+
+ test->key = _gcr_gnupg_key_new (records, NULL);
+
+ records = g_ptr_array_new_with_free_func (_gcr_record_free);
+ g_ptr_array_add (records, _gcr_record_parse_colons ("pub:u:2048:1:4842D952AFC000FD:1305189489:::u:::scESC:", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("uid:u::::1305189849::D0A8FA7B15DC4BE3F8F03A49C372F2718C78AFC0::Dr. Strangelove <lovingbomb example com>:", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("uid:u::::1305189489::D449F1605254754B0BBFA424FC34E50609103BBB::Test Number 1 (unlimited) <test-number-1 example com>:", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("sub:u:2048:1:4852132BBED15014:1305189489::::::e:", -1));
+ test->pubset = records;
+
+ records = g_ptr_array_new_with_free_func (_gcr_record_free);
+ g_ptr_array_add (records, _gcr_record_parse_colons ("sec::2048:1:4842D952AFC000FD:1305189489::::::::::", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("uid:::::::D449F1605254754B0BBFA424FC34E50609103BBB::Test Number 1 (unlimited) <test-number-1 example com>:", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("uid:::::::D0A8FA7B15DC4BE3F8F03A49C372F2718C78AFC0::Dr. Strangelove <lovingbomb example com>:", -1));
+ g_ptr_array_add (records, _gcr_record_parse_colons ("ssb::2048:1:4852132BBED15014:1305189489::::::::::", -1));
+ test->secset = records;
}
static void
@@ -79,7 +79,7 @@ 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->records);
g_ptr_array_unref (test->pubset);
g_ptr_array_unref (test->secset);
}
@@ -118,17 +118,17 @@ test_description (Test *test, gconstpointer unused)
}
static void
-test_dataset (Test *test, gconstpointer unused)
+test_records (Test *test, gconstpointer unused)
{
- GPtrArray *dataset;
+ GPtrArray *records;
- g_object_get (test->key, "public-dataset", &dataset, NULL);
- g_assert (dataset == test->dataset);
+ g_object_get (test->key, "public-records", &records, NULL);
+ g_assert (records == test->records);
- _gcr_gnupg_key_set_public_dataset (test->key, dataset);
- g_assert (dataset == _gcr_gnupg_key_get_public_dataset (test->key));
+ _gcr_gnupg_key_set_public_records (test->key, records);
+ g_assert (records == _gcr_gnupg_key_get_public_records (test->key));
- g_ptr_array_unref (dataset);
+ g_ptr_array_unref (records);
}
static void
@@ -156,11 +156,11 @@ test_short_keyid (Test *test, gconstpointer unused)
}
static void
-test_keyid_for_colons (Test *test, gconstpointer unused)
+test_keyid_for_records (Test *test, gconstpointer unused)
{
const gchar *keyid;
- keyid = _gcr_gnupg_key_get_keyid_for_colons (test->dataset);
+ keyid = _gcr_gnupg_key_get_keyid_for_records (test->records);
g_assert_cmpstr (keyid, ==, "6C7EE1B8621CC013");
}
@@ -173,9 +173,9 @@ test_with_secret (Test *test, gconstpointer unused)
key = _gcr_gnupg_key_new (test->pubset, test->secset);
g_assert (GCR_IS_GNUPG_KEY (key));
- g_object_get (key, "secret-dataset", &secset, NULL);
- g_assert (secset == _gcr_gnupg_key_get_secret_dataset (key));
- g_object_set (key, "secret-dataset", secset, NULL);
+ g_object_get (key, "secret-records", &secset, NULL);
+ g_assert (secset == _gcr_gnupg_key_get_secret_records (key));
+ g_object_set (key, "secret-records", secset, NULL);
g_object_unref (key);
}
@@ -185,7 +185,7 @@ 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);
+ _gcr_gnupg_key_set_public_records (test->key, test->pubset);
exit (0);
}
@@ -198,7 +198,7 @@ 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);
+ _gcr_gnupg_key_set_secret_records (test->key, test->secset);
exit (0);
}
@@ -215,10 +215,10 @@ main (int argc, char **argv)
g_test_add ("/gcr/gnupg-key/label", Test, NULL, setup, test_label, teardown);
g_test_add ("/gcr/gnupg-key/description", Test, NULL, setup, test_description, teardown);
g_test_add ("/gcr/gnupg-key/markup", Test, NULL, setup, test_markup, teardown);
- g_test_add ("/gcr/gnupg-key/dataset", Test, NULL, setup, test_dataset, teardown);
+ g_test_add ("/gcr/gnupg-key/records", Test, NULL, setup, test_records, teardown);
g_test_add ("/gcr/gnupg-key/keyid", Test, NULL, setup, test_keyid, teardown);
g_test_add ("/gcr/gnupg-key/short_keyid", Test, NULL, setup, test_short_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/keyid_for_records", Test, NULL, setup, test_keyid_for_records, 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);
diff --git a/gcr/tests/test-record.c b/gcr/tests/test-record.c
new file mode 100644
index 0000000..0cf91b8
--- /dev/null
+++ b/gcr/tests/test-record.c
@@ -0,0 +1,180 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ Copyright (C) 2011 Collabora Ltd.
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stefw collabora co uk>
+*/
+
+#include "config.h"
+
+#include "gcr/gcr-record.h"
+
+#include "egg/egg-testing.h"
+
+#include <glib.h>
+
+typedef struct {
+ GcrRecord *record;
+} Test;
+
+static void
+setup (Test *test, gconstpointer unused)
+{
+ test->record = _gcr_record_parse_colons ("one:tab\\there::four:f\xfc""nf:", -1);
+}
+
+static void
+teardown (Test *test, gconstpointer unused)
+{
+ _gcr_record_free (test->record);
+}
+
+static void
+test_parse (void)
+{
+ GcrRecord *record;
+
+ record = _gcr_record_parse_colons ("one:two::four::six", -1);
+ g_assert (record);
+
+ g_assert_cmpstr (_gcr_record_get_raw (record, 0), ==, "one");
+ g_assert_cmpstr (_gcr_record_get_raw (record, 1), ==, "two");
+ g_assert_cmpstr (_gcr_record_get_raw (record, 2), ==, "");
+ g_assert_cmpstr (_gcr_record_get_raw (record, 3), ==, "four");
+ g_assert_cmpstr (_gcr_record_get_raw (record, 4), ==, "");
+ g_assert_cmpstr (_gcr_record_get_raw (record, 5), ==, "six");
+ g_assert (_gcr_record_get_raw (record, 6) == NULL);
+
+ _gcr_record_free (record);
+}
+
+static void
+test_parse_part (void)
+{
+ GcrRecord *record;
+
+ record = _gcr_record_parse_colons ("one:two::four::six", 8);
+ g_assert (record);
+
+ g_assert_cmpstr (_gcr_record_get_raw (record, 0), ==, "one");
+ g_assert_cmpstr (_gcr_record_get_raw (record, 1), ==, "two");
+ g_assert_cmpstr (_gcr_record_get_raw (record, 2), ==, "");
+ g_assert (_gcr_record_get_raw (record, 3) == NULL);
+
+ _gcr_record_free (record);
+}
+
+static void
+test_parse_too_long (void)
+{
+ GcrRecord *record;
+
+ /* Too many columns */
+ record = _gcr_record_parse_colons (":::::::::::::::::::::::::::::::::::::::::::::::::::::", -1);
+ g_assert (record == NULL);
+}
+
+static void
+test_find (void)
+{
+ GcrRecord *uid, *pub, *one, *check;
+ GPtrArray *records;
+
+ records = g_ptr_array_new_with_free_func (_gcr_record_free);
+
+ one = _gcr_record_parse_colons ("one:two::four::six", -1);
+ g_ptr_array_add (records, one);
+ pub = _gcr_record_parse_colons ("pub:two", -1);
+ g_ptr_array_add (records, pub);
+ uid = _gcr_record_parse_colons ("uid:two", -1);
+ g_ptr_array_add (records, uid);
+
+ check = _gcr_record_find (records, GCR_RECORD_SCHEMA_PUB);
+ g_assert (check == pub);
+
+ check = _gcr_record_find (records, GCR_RECORD_SCHEMA_UID);
+ g_assert (check == uid);
+
+ g_ptr_array_unref (records);
+}
+
+static void
+test_get_string (Test *test, gconstpointer unused)
+{
+ gchar *value = _gcr_record_get_string (test->record, 1);
+ g_assert (value);
+
+ g_assert_cmpstr (value, ==, "tab\there");
+ g_free (value);
+}
+
+static void
+test_get_string_null (Test *test, gconstpointer unused)
+{
+ gchar *value = _gcr_record_get_string (test->record, 35);
+ g_assert (value == NULL);
+}
+
+static void
+test_get_string_latin1 (Test *test, gconstpointer unused)
+{
+ gchar *value = _gcr_record_get_string (test->record, 4);
+ g_assert (value);
+
+ g_assert_cmpstr (value, ==, "f\xc3\xbc""nf");
+ g_assert (g_utf8_validate (value, -1, NULL));
+ g_free (value);
+}
+
+static void
+test_free_null (void)
+{
+ _gcr_record_free (NULL);
+}
+
+static void
+test_get_schema (Test *test, gconstpointer unused)
+{
+ GQuark schema;
+ GQuark check;
+
+ /* Initialize this quark */
+ check = g_quark_from_static_string ("one");
+
+ schema = _gcr_record_get_schema (test->record);
+ g_assert (check == schema);
+ g_assert_cmpstr (g_quark_to_string (schema), ==, "one");
+}
+
+int
+main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/gcr/record/parse", test_parse);
+ g_test_add_func ("/gcr/record/parse_part", test_parse_part);
+ g_test_add_func ("/gcr/record/parse_too_long", test_parse_too_long);
+ g_test_add_func ("/gcr/record/free_null", test_free_null);
+ g_test_add_func ("/gcr/record/find", test_find);
+ g_test_add ("/gcr/record/get_string", Test, NULL, setup, test_get_string, teardown);
+ g_test_add ("/gcr/record/get_string_null", Test, NULL, setup, test_get_string_null, teardown);
+ g_test_add ("/gcr/record/get_string_latin1", Test, NULL, setup, test_get_string_latin1, teardown);
+ g_test_add ("/gcr/record/get_schema", Test, NULL, setup, test_get_schema, teardown);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]