static void test_some_asn1_stuff (const ASN1_ARRAY_TYPE *defs, const gchar *file, const gchar *identifier) { GNode *asn; gpointer data, encoded; gsize n_data, n_encoded; if (!g_file_get_contents (file, (gchar**)&data, &n_data, NULL)) g_assert_not_reached (); asn = egg_asn1x_create (defs, identifier); egg_asn1x_dump (asn); if (!egg_asn1x_decode (asn, data, n_data)) g_warning ("decode of %s failed: %s", identifier, egg_asn1x_message (asn)); encoded = egg_asn1x_encode (asn, NULL, &n_encoded); if (encoded == NULL) g_warning ("encode of %s failed: %s", identifier, egg_asn1x_message (asn)); /* Decode the encoding */ if (!egg_asn1x_decode (asn, encoded, n_encoded)) g_warning ("decode of encoded %s failed: %s", identifier, egg_asn1x_message (asn)); egg_asn1x_clear (asn); egg_asn1x_destroy (asn); g_free (encoded); g_free (data); }
static void test_decode_encode (Test *test, gconstpointer data) { const Fixture *fixture = data; GNode *asn; GBytes *encoded; gboolean ret; asn = egg_asn1x_create (fixture->defs, fixture->identifier); if (g_test_verbose ()) egg_asn1x_dump (asn); ret = egg_asn1x_decode (asn, test->data); egg_asn1x_assert (ret == TRUE, asn); encoded = egg_asn1x_encode (asn, NULL); egg_asn1x_assert (encoded != NULL, asn); /* Decode the encoding */ ret = egg_asn1x_decode (asn, encoded); egg_asn1x_assert (ret == TRUE, asn); egg_asn1x_clear (asn); egg_asn1x_destroy (asn); g_bytes_unref (encoded); }
/** * gcr_certificate_request_set_cn: * @self: the certificate request * @cn: common name to set on the request * * Set the common name encoded in the certificate request. */ void gcr_certificate_request_set_cn (GcrCertificateRequest *self, const gchar *cn) { GNode *subject; GNode *dn; g_return_if_fail (GCR_IS_CERTIFICATE_REQUEST (self)); g_return_if_fail (cn != NULL); subject = egg_asn1x_node (self->asn, "certificationRequestInfo", "subject", NULL); dn = egg_asn1x_node (subject, "rdnSequence", NULL); /* TODO: we shouldn't really be clearing this, but replacing CN */ egg_asn1x_set_choice (subject, dn); egg_asn1x_clear (dn); egg_dn_add_string_part (dn, GCR_OID_NAME_CN, cn); }
static gboolean save_assertions (GkmXdgTrust *self, GNode *asn) { GHashTableIter iter; GNode *pair, *node; gpointer value; g_assert (GKM_XDG_IS_TRUST (self)); g_assert (asn); node = egg_asn1x_node (asn, "assertions", NULL); egg_asn1x_clear (node); g_hash_table_iter_init (&iter, self->pv->assertions); while (g_hash_table_iter_next (&iter, NULL, &value)) { pair = egg_asn1x_append (node); g_return_val_if_fail (pair, FALSE); save_assertion (pair, GKM_ASSERTION (value)); } return TRUE; }