summaryrefslogtreecommitdiff
path: root/gcr/tests
diff options
context:
space:
mode:
Diffstat (limited to 'gcr/tests')
-rw-r--r--gcr/tests/frob-openpgp.c29
-rw-r--r--gcr/tests/test-fingerprint.c95
-rw-r--r--gcr/tests/test-openpgp.c26
-rw-r--r--gcr/tests/test-openssh.c39
-rw-r--r--gcr/tests/test-pkcs11-certificate.c16
5 files changed, 109 insertions, 96 deletions
diff --git a/gcr/tests/frob-openpgp.c b/gcr/tests/frob-openpgp.c
index b83305a..46748f6 100644
--- a/gcr/tests/frob-openpgp.c
+++ b/gcr/tests/frob-openpgp.c
@@ -31,8 +31,7 @@
static void
on_packet_print_records (GPtrArray *records,
- const guchar *packet,
- gsize n_packet,
+ EggBytes *packet,
gpointer user_data)
{
gchar *string;
@@ -46,12 +45,11 @@ on_packet_print_records (GPtrArray *records,
}
static gboolean
-parse_binary (gconstpointer contents,
- gsize length)
+parse_binary (EggBytes *contents)
{
guint packets;
- packets = _gcr_openpgp_parse (contents, length,
+ packets = _gcr_openpgp_parse (contents,
GCR_OPENPGP_PARSE_KEYS |
GCR_OPENPGP_PARSE_ATTRIBUTES,
on_packet_print_records, NULL);
@@ -61,10 +59,8 @@ parse_binary (gconstpointer contents,
static void
on_armor_parsed (GQuark type,
- const guchar *data,
- gsize n_data,
- const gchar *outer,
- gsize n_outer,
+ EggBytes *data,
+ EggBytes *outer,
GHashTable *headers,
gpointer user_data)
{
@@ -74,19 +70,18 @@ on_armor_parsed (GQuark type,
value = g_hash_table_lookup (headers, "Version");
g_assert_cmpstr (value, ==, "GnuPG v1.4.11 (GNU/Linux)");
- *result = parse_binary (data, n_data);
+ *result = parse_binary (data);
}
static gboolean
-parse_armor_or_binary (gconstpointer contents,
- gsize length)
+parse_armor_or_binary (EggBytes *contents)
{
gboolean result;
guint parts;
- parts = egg_armor_parse (contents, length, on_armor_parsed, &result);
+ parts = egg_armor_parse (contents, on_armor_parsed, &result);
if (parts == 0)
- result = parse_binary (contents, length);
+ result = parse_binary (contents);
return result;
}
@@ -96,6 +91,7 @@ main(int argc, char *argv[])
GError *error = NULL;
gchar *contents;
gsize length;
+ EggBytes *bytes;
int ret;
g_set_prgname ("frob-openpgp");
@@ -111,12 +107,13 @@ main(int argc, char *argv[])
return 1;
}
+ bytes = egg_bytes_new_take (contents, length);
ret = 0;
- if (!parse_armor_or_binary (contents, length)) {
+ if (!parse_armor_or_binary (bytes)) {
g_printerr ("frob-openpgp: no openpgp data found in data");
ret = 1;
}
- g_free (contents);
+ egg_bytes_unref (bytes);
return ret;
}
diff --git a/gcr/tests/test-fingerprint.c b/gcr/tests/test-fingerprint.c
index d17208b..94564f8 100644
--- a/gcr/tests/test-fingerprint.c
+++ b/gcr/tests/test-fingerprint.c
@@ -39,49 +39,43 @@
#include <errno.h>
typedef struct {
- gpointer cert_rsa;
- gsize n_cert_rsa;
- gpointer key_rsa;
- gsize n_key_rsa;
- gpointer cert_dsa;
- gsize n_cert_dsa;
- gpointer key_dsa;
- gsize n_key_dsa;
+ EggBytes *cert_rsa;
+ EggBytes *key_rsa;
+ EggBytes *cert_dsa;
+ EggBytes *key_dsa;
} Test;
static void
setup (Test *test, gconstpointer unused)
{
GError *error = NULL;
+ gchar *contents;
+ gsize length;
- g_file_get_contents (SRCDIR "/files/client.crt", (gchar**)&test->cert_rsa,
- &test->n_cert_rsa, &error);
+ g_file_get_contents (SRCDIR "/files/client.crt", &contents, &length, &error);
g_assert_no_error (error);
- g_assert (test->cert_rsa);
+ test->cert_rsa = egg_bytes_new_take (contents, length);
- g_file_get_contents (SRCDIR "/files/client.key", (gchar**)&test->key_rsa,
- &test->n_key_rsa, &error);
+ g_file_get_contents (SRCDIR "/files/client.key", &contents, &length, &error);
g_assert_no_error (error);
- g_assert (test->key_rsa);
+ test->key_rsa = egg_bytes_new_take (contents, length);
- g_file_get_contents (SRCDIR "/files/generic-dsa.crt", (gchar**)&test->cert_dsa,
- &test->n_cert_dsa, &error);
+ g_file_get_contents (SRCDIR "/files/generic-dsa.crt", &contents, &length, &error);
g_assert_no_error (error);
- g_assert (test->cert_dsa);
+ test->cert_dsa = egg_bytes_new_take (contents, length);
- g_file_get_contents (SRCDIR "/files/generic-dsa.key", (gchar**)&test->key_dsa,
- &test->n_key_dsa, &error);
+ g_file_get_contents (SRCDIR "/files/generic-dsa.key", &contents, &length, &error);
g_assert_no_error (error);
- g_assert (test->key_dsa);
+ test->key_dsa = egg_bytes_new_take (contents, length);
}
static void
teardown (Test *test, gconstpointer unused)
{
- g_free (test->cert_rsa);
- g_free (test->key_rsa);
- g_free (test->cert_dsa);
- g_free (test->key_dsa);
+ egg_bytes_unref (test->cert_rsa);
+ egg_bytes_unref (test->key_rsa);
+ egg_bytes_unref (test->cert_dsa);
+ egg_bytes_unref (test->key_dsa);
}
static void
@@ -96,7 +90,7 @@ on_parser_parsed (GcrParser *parser,
}
static GckAttributes*
-parse_attributes_for_key (gpointer data, gsize n_data)
+parse_attributes_for_key (EggBytes *data)
{
GcrParser *parser;
GckAttributes *attrs = NULL;
@@ -104,7 +98,8 @@ parse_attributes_for_key (gpointer data, gsize n_data)
parser = gcr_parser_new ();
g_signal_connect (parser, "parsed", G_CALLBACK (on_parser_parsed), &attrs);
- gcr_parser_parse_data (parser, data, n_data, &error);
+ gcr_parser_parse_data (parser, egg_bytes_get_data (data),
+ egg_bytes_get_size (data), &error);
g_assert_no_error (error);
g_object_unref (parser);
@@ -113,30 +108,30 @@ parse_attributes_for_key (gpointer data, gsize n_data)
}
static GckAttributes *
-build_attributes_for_cert (guchar *data,
- gsize n_data)
+build_attributes_for_cert (EggBytes *data)
{
GckAttributes *attrs;
attrs = gck_attributes_new ();
- gck_attributes_add_data (attrs, CKA_VALUE, data, n_data);
+ gck_attributes_add_data (attrs, CKA_VALUE, egg_bytes_get_data (data),
+ egg_bytes_get_size (data));
gck_attributes_add_ulong (attrs, CKA_CLASS, CKO_CERTIFICATE);
gck_attributes_add_ulong (attrs, CKA_CERTIFICATE_TYPE, CKC_X_509);
return attrs;
}
-static gconstpointer
-parse_subject_public_key_info_for_cert (gpointer data, gsize n_data, gsize *n_info)
+static EggBytes *
+parse_subject_public_key_info_for_cert (EggBytes *data)
{
- gconstpointer info;
+ EggBytes *info;
GNode *asn;
- asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", data, n_data);
- g_assert (asn);
+ asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", data);
+ g_assert (asn != NULL);
- info = egg_asn1x_get_raw_element (egg_asn1x_node (asn, "tbsCertificate", "subjectPublicKeyInfo", NULL), n_info);
- g_assert (info);
+ info = egg_asn1x_get_raw_element (egg_asn1x_node (asn, "tbsCertificate", "subjectPublicKeyInfo", NULL));
+ g_assert (info != NULL);
egg_asn1x_destroy (asn);
return info;
@@ -146,16 +141,17 @@ static void
test_rsa (Test *test, gconstpointer unused)
{
GckAttributes *key, *cert;
- gconstpointer info;
- gsize n_info;
+ EggBytes *info;
guchar *fingerprint1, *fingerprint2, *fingerprint3;
gsize n_fingerprint1, n_fingerprint2, n_fingerprint3;
- key = parse_attributes_for_key (test->key_rsa, test->n_key_rsa);
- info = parse_subject_public_key_info_for_cert (test->cert_rsa, test->n_cert_rsa, &n_info);
- cert = build_attributes_for_cert (test->cert_rsa, test->n_cert_rsa);
+ key = parse_attributes_for_key (test->key_rsa);
+ info = parse_subject_public_key_info_for_cert (test->cert_rsa);
+ cert = build_attributes_for_cert (test->cert_rsa);
- fingerprint1 = gcr_fingerprint_from_subject_public_key_info (info, n_info, G_CHECKSUM_SHA1, &n_fingerprint1);
+ fingerprint1 = gcr_fingerprint_from_subject_public_key_info (egg_bytes_get_data (info),
+ egg_bytes_get_size (info),
+ G_CHECKSUM_SHA1, &n_fingerprint1);
fingerprint2 = gcr_fingerprint_from_attributes (key, G_CHECKSUM_SHA1, &n_fingerprint2);
fingerprint3 = gcr_fingerprint_from_attributes (cert, G_CHECKSUM_SHA1, &n_fingerprint3);
@@ -166,6 +162,7 @@ test_rsa (Test *test, gconstpointer unused)
g_free (fingerprint2);
g_free (fingerprint3);
+ egg_bytes_unref (info);
gck_attributes_unref (key);
gck_attributes_unref (cert);
}
@@ -174,16 +171,17 @@ static void
test_dsa (Test *test, gconstpointer unused)
{
GckAttributes *key, *cert;
- gconstpointer info;
- gsize n_info;
+ EggBytes *info;
guchar *fingerprint1, *fingerprint2, *fingerprint3;
gsize n_fingerprint1, n_fingerprint2, n_fingerprint3;
- key = parse_attributes_for_key (test->key_dsa, test->n_key_dsa);
- info = parse_subject_public_key_info_for_cert (test->cert_dsa, test->n_cert_dsa, &n_info);
- cert = build_attributes_for_cert (test->cert_dsa, test->n_cert_dsa);
+ key = parse_attributes_for_key (test->key_dsa);
+ info = parse_subject_public_key_info_for_cert (test->cert_dsa);
+ cert = build_attributes_for_cert (test->cert_dsa);
- fingerprint1 = gcr_fingerprint_from_subject_public_key_info (info, n_info, G_CHECKSUM_SHA1, &n_fingerprint1);
+ fingerprint1 = gcr_fingerprint_from_subject_public_key_info (egg_bytes_get_data (info),
+ egg_bytes_get_size (info),
+ G_CHECKSUM_SHA1, &n_fingerprint1);
fingerprint2 = gcr_fingerprint_from_attributes (key, G_CHECKSUM_SHA1, &n_fingerprint2);
fingerprint3 = gcr_fingerprint_from_attributes (cert, G_CHECKSUM_SHA1, &n_fingerprint3);
@@ -194,6 +192,7 @@ test_dsa (Test *test, gconstpointer unused)
g_free (fingerprint2);
g_free (fingerprint3);
+ egg_bytes_unref (info);
gck_attributes_unref (key);
gck_attributes_unref (cert);
}
diff --git a/gcr/tests/test-openpgp.c b/gcr/tests/test-openpgp.c
index be41f40..cfc1dad 100644
--- a/gcr/tests/test-openpgp.c
+++ b/gcr/tests/test-openpgp.c
@@ -240,15 +240,14 @@ compare_fixture_with_records (const gchar *fixture,
static void
on_openpgp_packet (GPtrArray *records,
- const guchar *outer,
- gsize n_outer,
+ EggBytes *outer,
gpointer user_data)
{
Test *test = user_data;
guint seen;
/* Should be parseable again */
- seen = _gcr_openpgp_parse (outer, n_outer, test->fixture->flags |
+ seen = _gcr_openpgp_parse (outer, test->fixture->flags |
GCR_OPENPGP_PARSE_NO_RECORDS, NULL, NULL);
g_assert_cmpuint (seen, ==, 1);
@@ -263,10 +262,8 @@ on_openpgp_packet (GPtrArray *records,
static void
on_armor_parsed (GQuark type,
- const guchar *data,
- gsize n_data,
- const gchar *outer,
- gsize n_outer,
+ EggBytes *data,
+ EggBytes *outer,
GHashTable *headers,
gpointer user_data)
{
@@ -279,7 +276,7 @@ on_armor_parsed (GQuark type,
g_assert_cmpstr (value, ==, test->fixture->version);
}
- seen = _gcr_openpgp_parse (data, n_data, test->fixture->flags,
+ seen = _gcr_openpgp_parse (data, test->fixture->flags,
on_openpgp_packet, test);
g_assert_cmpuint (seen, >, 0);
@@ -294,6 +291,7 @@ test_openpgp_armor (Test *test,
gconstpointer data)
{
GError *error = NULL;
+ EggBytes *bytes;
gchar *armor;
gsize length;
guint parts;
@@ -301,10 +299,11 @@ test_openpgp_armor (Test *test,
g_file_get_contents (test->fixture->filename, &armor, &length, &error);
g_assert_no_error (error);
- parts = egg_armor_parse (armor, length, on_armor_parsed, test);
+ bytes = egg_bytes_new_take (armor, length);
+ parts = egg_armor_parse (bytes, on_armor_parsed, test);
g_assert_cmpuint (parts, ==, 1);
- g_free (armor);
+ egg_bytes_unref (bytes);
}
static void
@@ -312,6 +311,7 @@ test_openpgp_binary (Test *test,
gconstpointer data)
{
GError *error = NULL;
+ EggBytes *bytes;
gchar *binary;
gsize length;
guint seen;
@@ -319,8 +319,8 @@ test_openpgp_binary (Test *test,
g_file_get_contents (test->fixture->filename, &binary, &length, &error);
g_assert_no_error (error);
- seen = _gcr_openpgp_parse (binary, length, test->fixture->flags,
- on_openpgp_packet, test);
+ bytes = egg_bytes_new_take (binary, length);
+ seen = _gcr_openpgp_parse (bytes, test->fixture->flags, on_openpgp_packet, test);
g_assert_cmpuint (seen, >, 0);
if (*(test->at) != NULL) {
@@ -328,7 +328,7 @@ test_openpgp_binary (Test *test,
g_assert_not_reached ();
}
- g_free (binary);
+ egg_bytes_unref (binary);
}
int
diff --git a/gcr/tests/test-openssh.c b/gcr/tests/test-openssh.c
index 81634da..b7742d9 100644
--- a/gcr/tests/test-openssh.c
+++ b/gcr/tests/test-openssh.c
@@ -91,8 +91,7 @@ static void
on_openssh_pub_parse (GckAttributes *attrs,
const gchar *label,
const gchar *options,
- const gchar *outer,
- gsize n_outer,
+ EggBytes *outer,
gpointer user_data)
{
Test *test = user_data;
@@ -104,7 +103,7 @@ on_openssh_pub_parse (GckAttributes *attrs,
g_assert_cmpstr (options, ==, test->expected_options);
/* The block should parse properly */
- keys = _gcr_openssh_pub_parse (outer, n_outer, NULL, NULL);
+ keys = _gcr_openssh_pub_parse (outer, NULL, NULL);
g_assert_cmpuint (keys, ==, 1);
}
@@ -113,14 +112,16 @@ test_parse_v1_rsa (Test *test,
gconstpointer unused)
{
const gchar *data = OPENSSH_PUBLIC_RSA1 EXTRA_LINES_WITHOUT_KEY;
+ EggBytes *bytes;
gint keys;
test->expected_label = "rsa-key@example.com";
- keys = _gcr_openssh_pub_parse (data, strlen (data),
- on_openssh_pub_parse, test);
+ bytes = egg_bytes_new_static (data, strlen (data));
+ keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
+ egg_bytes_unref (bytes);
}
static void
@@ -128,13 +129,16 @@ test_parse_v2_rsa (Test *test,
gconstpointer unused)
{
const gchar *data = OPENSSH_PUBLIC_RSA2 EXTRA_LINES_WITHOUT_KEY;
+ EggBytes *bytes;
gint keys;
test->expected_label = "rsa-key@example.com";
- keys = _gcr_openssh_pub_parse (data, strlen (data),
- on_openssh_pub_parse, test);
+ bytes = egg_bytes_new_static (data, strlen (data));
+ keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
+
+ egg_bytes_unref (bytes);
}
static void
@@ -142,13 +146,16 @@ test_parse_v2_dsa (Test *test,
gconstpointer unused)
{
const gchar *data = OPENSSH_PUBLIC_DSA2 EXTRA_LINES_WITHOUT_KEY;
+ EggBytes *bytes;
gint keys;
test->expected_label = "dsa-key@example.com";
- keys = _gcr_openssh_pub_parse (data, strlen (data),
- on_openssh_pub_parse, test);
+ bytes = egg_bytes_new_static (data, strlen (data));
+ keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
+
+ egg_bytes_unref (bytes);
}
static void
@@ -156,13 +163,16 @@ test_parse_v1_options (Test *test,
gconstpointer unused)
{
const gchar *data = "option1,option2=\"value 2\",option3 " OPENSSH_PUBLIC_RSA1;
+ EggBytes *bytes;
gint keys;
test->expected_options = "option1,option2=\"value 2\",option3";
- keys = _gcr_openssh_pub_parse (data, strlen (data),
- on_openssh_pub_parse, test);
+ bytes = egg_bytes_new_static (data, strlen (data));
+ keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
+
+ egg_bytes_unref (bytes);
}
static void
@@ -170,13 +180,16 @@ test_parse_v2_options (Test *test,
gconstpointer unused)
{
const gchar *data = "option1,option2=\"value 2\",option3 " OPENSSH_PUBLIC_RSA2;
+ EggBytes *bytes;
gint keys;
test->expected_options = "option1,option2=\"value 2\",option3";
- keys = _gcr_openssh_pub_parse (data, strlen (data),
- on_openssh_pub_parse, test);
+ bytes = egg_bytes_new_static (data, strlen (data));
+ keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
+
+ egg_bytes_unref (bytes);
}
int
diff --git a/gcr/tests/test-pkcs11-certificate.c b/gcr/tests/test-pkcs11-certificate.c
index 7c04c07..daf97e1 100644
--- a/gcr/tests/test-pkcs11-certificate.c
+++ b/gcr/tests/test-pkcs11-certificate.c
@@ -53,8 +53,8 @@ setup (Test *test, gconstpointer unused)
GckAttributes *attrs;
CK_FUNCTION_LIST_PTR f;
GckModule *module;
- gconstpointer subject;
- gsize n_subject;
+ EggBytes *subject;
+ EggBytes *bytes;
GNode *asn, *node;
CK_RV rv;
@@ -82,20 +82,24 @@ setup (Test *test, gconstpointer unused)
gcr_pkcs11_set_modules (modules);
gck_list_unref_free (modules);
- asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate",
- test->cert_data, test->n_cert_data);
+ bytes = egg_bytes_new_static (test->cert_data, test->n_cert_data);
+ asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", bytes);
g_assert (asn);
node = egg_asn1x_node (asn, "tbsCertificate", "subject", NULL);
- subject = egg_asn1x_get_raw_element (node, &n_subject);
+ subject = egg_asn1x_get_raw_element (node);
/* Add a certificate to the module */
attrs = gck_attributes_new ();
gck_attributes_add_data (attrs, CKA_VALUE, test->cert_data, test->n_cert_data);
gck_attributes_add_ulong (attrs, CKA_CLASS, CKO_CERTIFICATE);
gck_attributes_add_ulong (attrs, CKA_CERTIFICATE_TYPE, CKC_X_509);
- gck_attributes_add_data (attrs, CKA_SUBJECT, subject, n_subject);
+ gck_attributes_add_data (attrs, CKA_SUBJECT,
+ egg_bytes_get_data (subject),
+ egg_bytes_get_size (subject));
gck_mock_module_take_object (attrs);
+ egg_bytes_unref (bytes);
+ egg_bytes_unref (subject);
egg_asn1x_destroy (asn);
}