[gcr] egg: Remove usage of libtasn1.h
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcr] egg: Remove usage of libtasn1.h
- Date: Mon, 21 Nov 2011 10:18:09 +0000 (UTC)
commit 2343c7fcebb865c3c8ad139bac89f7b4a053cc66
Author: Stef Walter <stefw collabora co uk>
Date: Mon Nov 21 11:13:32 2011 +0100
egg: Remove usage of libtasn1.h
* Copy a few definitions for using the asn1Parser generated
definitions files.
https://bugzilla.gnome.org/show_bug.cgi?id=664187
.gitignore | 3 +-
Makefile.decl | 9 +++-
egg/Makefile.am | 23 ++++-----
egg/egg-asn1-defs.c | 33 +++++++++++++
egg/egg-asn1-defs.h | 12 +++--
egg/egg-asn1x.c | 123 ++++++++++++++++++++++++++++++-----------------
egg/egg-asn1x.h | 8 ++--
egg/tests/Makefile.am | 18 ++++---
egg/tests/test-asn1.c | 4 +-
egg/tests/test-asn1x.c | 4 +-
egg/tests/test-dn.c | 1 -
gcr/gcr-parser.c | 2 +-
12 files changed, 161 insertions(+), 79 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 8165475..ee49192 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@ frob-*
# Common file extensions
*.abi
+*.asn.h
*.autogen_bak
*.bak
*.gcda
@@ -71,7 +72,7 @@ stamp-*
/docs/reference/*/tmpl
/docs/reference/*/version.xml
/docs/reference/*/version.xml
-/docs/reference/*/xml
+/docs/reference/*/
/egg/asn1-def-*.c
/egg/tests/asn1-def-*.c
diff --git a/Makefile.decl b/Makefile.decl
index 32d2067..f399af3 100644
--- a/Makefile.decl
+++ b/Makefile.decl
@@ -23,4 +23,11 @@ coverage:
clear-coverage:
$(LCOV) --directory . --zerocounters
-.PHONY: coverage
+V_ASN1 = $(V_ASN1_$(V))
+V_ASN1_ = $(V_ASN1_$(AM_DEFAULT_VERBOSITY))
+V_ASN1_0 = @echo " ASN1 " $@;
+
+.asn.asn.h:
+ $(V_ASN1) $(ASN1PARSER) -o $@ $< && sed -i 's|#include.*|/* \0 */|' $@
+
+SUFFIXES = .asn .asn.h
diff --git a/egg/Makefile.am b/egg/Makefile.am
index f00258c..a9de41a 100644
--- a/egg/Makefile.am
+++ b/egg/Makefile.am
@@ -1,3 +1,4 @@
+include $(top_srcdir)/Makefile.decl
noinst_LTLIBRARIES = \
libegg.la \
@@ -6,8 +7,14 @@ noinst_LTLIBRARIES = \
libegg-hex.la \
libegg-test.la
+ASN_FILES = \
+ pk.asn \
+ pkix.asn
+
+ASN_SRCS = $(ASN_FILES:.asn=.asn.h)
+
BUILT_SOURCES = \
- asn1-def-pk.c asn1-def-pkix.c
+ $(ASN_SRCS)
INCLUDES = \
-I$(top_srcdir) \
@@ -21,6 +28,7 @@ libegg_la_CFLAGS = \
libegg_la_SOURCES = \
egg-armor.c egg-armor.h \
egg-asn1x.c egg-asn1x.h \
+ egg-asn1-defs.c egg-asn1-defs.h \
egg-buffer.c egg-buffer.h \
egg-bytes.c egg-bytes.h \
egg-dh.c egg-dh.h \
@@ -37,20 +45,12 @@ libegg_la_SOURCES = \
egg-symkey.c egg-symkey.h \
egg-testing.c egg-testing.h \
egg-timegm.c egg-timegm.h \
- egg-asn1-defs.h \
$(BUILT_SOURCES)
-asn1-def-pk.c: pk.asn
- $(ASN1PARSER) -o asn1-def-pk.c $(srcdir)/pk.asn
-
-asn1-def-pkix.c: pkix.asn
- $(ASN1PARSER) -o asn1-def-pkix.c $(srcdir)/pkix.asn
-
EXTRA_DIST = \
- pkix.asn \
- pk.asn
+ $(ASN_FILES)
-DISTCLEANFILES = \
+CLEANFILES = \
$(BUILT_SOURCES)
# --------------------------------------------------------------------
@@ -61,7 +61,6 @@ libegg_asn1x_la_SOURCES = \
$(BUILT_SOURCES)
libegg_asn1x_la_CFLAGS = \
- $(LIBTASN1_CFLAGS) \
$(GLIB_CFLAGS)
libegg_entry_buffer_la_SOURCES = \
diff --git a/egg/egg-asn1-defs.c b/egg/egg-asn1-defs.c
new file mode 100644
index 0000000..8295ec0
--- /dev/null
+++ b/egg/egg-asn1-defs.c
@@ -0,0 +1,33 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* egg-asn1-defs.c - ASN.1 definitions
+
+ 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 "egg-asn1-defs.h"
+
+#include <stdlib.h>
+
+typedef struct _EggAsn1xDef ASN1_ARRAY_TYPE;
+
+#include "pk.asn.h"
+#include "pkix.asn.h"
diff --git a/egg/egg-asn1-defs.h b/egg/egg-asn1-defs.h
index 02fe427..ec47287 100644
--- a/egg/egg-asn1-defs.h
+++ b/egg/egg-asn1-defs.h
@@ -24,9 +24,13 @@
#ifndef EGG_ASN1_DEFS_H_
#define EGG_ASN1_DEFS_H_
-#include <libtasn1.h>
+struct _EggAsn1xDef {
+ const char *name;
+ unsigned int type;
+ const void *value;
+};
-extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
-extern const ASN1_ARRAY_TYPE pk_asn1_tab[];
+extern const struct _EggAsn1xDef pkix_asn1_tab[];
+extern const struct _EggAsn1xDef pk_asn1_tab[];
-#endif /*EGG_ASN1_DEFS_H_*/
+#endif /* EGG_ASN1_DEFS_H_ */
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index 2f481d2..1f2eda2 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -48,13 +48,34 @@
#include "config.h"
#include "egg-asn1x.h"
+#include "egg-asn1-defs.h"
#include "egg-timegm.h"
-#include <libtasn1.h>
-
#include <stdlib.h>
#include <string.h>
+/* From libtasn1's libtasn.h */
+
+#define ASN1_CLASS_UNIVERSAL 0x00
+#define ASN1_CLASS_APPLICATION 0x40
+#define ASN1_CLASS_CONTEXT_SPECIFIC 0x80
+#define ASN1_CLASS_PRIVATE 0xC0
+#define ASN1_CLASS_STRUCTURED 0x20
+
+#define ASN1_TAG_BOOLEAN 0x01
+#define ASN1_TAG_INTEGER 0x02
+#define ASN1_TAG_SEQUENCE 0x10
+#define ASN1_TAG_SET 0x11
+#define ASN1_TAG_OCTET_STRING 0x04
+#define ASN1_TAG_BIT_STRING 0x03
+#define ASN1_TAG_UTCTime 0x17
+#define ASN1_TAG_GENERALIZEDTime 0x18
+#define ASN1_TAG_OBJECT_ID 0x06
+#define ASN1_TAG_ENUMERATED 0x0A
+#define ASN1_TAG_NULL 0x05
+#define ASN1_TAG_GENERALSTRING 0x1B
+
+
/* From libtasn1's int.h */
enum {
TYPE_CONSTANT = 1,
@@ -135,8 +156,8 @@ struct _Atlv {
};
struct _Anode {
- const ASN1_ARRAY_TYPE *def;
- const ASN1_ARRAY_TYPE *join;
+ const EggAsn1xDef *def;
+ const EggAsn1xDef *join;
GList *opts;
Atlv *tlv;
@@ -179,7 +200,7 @@ atoin (const char *p, gint digits)
}
static GNode*
-anode_new (const ASN1_ARRAY_TYPE *def)
+anode_new (const EggAsn1xDef *def)
{
Anode *an = g_slice_new0 (Anode);
an->def = def;
@@ -270,7 +291,7 @@ anode_def_value (GNode *node)
}
static gulong
-anode_def_value_as_ulong (const ASN1_ARRAY_TYPE *def)
+anode_def_value_as_ulong (const EggAsn1xDef *def)
{
gchar *end = NULL;
gulong lval;
@@ -295,17 +316,20 @@ anode_child_with_name (GNode *node, const gchar *name)
}
static void
-anode_opt_add (GNode *node, const ASN1_ARRAY_TYPE *def)
+anode_opt_add (GNode *node,
+ const EggAsn1xDef *def)
{
Anode *an = node->data;
an->opts = g_list_append (an->opts, (gpointer)def);
}
-static ASN1_ARRAY_TYPE*
-anode_opt_lookup (GNode *node, gint type, const gchar *name)
+static EggAsn1xDef *
+anode_opt_lookup (GNode *node,
+ gint type,
+ const gchar *name)
{
Anode *an = node->data;
- ASN1_ARRAY_TYPE* def;
+ EggAsn1xDef *def;
GList *l;
for (l = an->opts; l; l = g_list_next (l)) {
@@ -319,11 +343,13 @@ anode_opt_lookup (GNode *node, gint type, const gchar *name)
return NULL;
}
-static ASN1_ARRAY_TYPE*
-anode_opt_lookup_value (GNode *node, gint type, const gchar *value)
+static EggAsn1xDef *
+anode_opt_lookup_value (GNode *node,
+ gint type,
+ const gchar *value)
{
Anode *an = node->data;
- ASN1_ARRAY_TYPE* def;
+ EggAsn1xDef *def;
GList *l;
for (l = an->opts; l; l = g_list_next (l)) {
@@ -341,7 +367,7 @@ static GList*
anode_opts_lookup (GNode *node, gint type, const gchar *name)
{
Anode *an = node->data;
- ASN1_ARRAY_TYPE* def;
+ EggAsn1xDef *def;
GList *l, *res = NULL;
for (l = an->opts; l; l = g_list_next (l)) {
@@ -530,7 +556,7 @@ anode_destroy (GNode *node)
static gulong
anode_calc_tag_for_flags (GNode *node, gint flags)
{
- ASN1_ARRAY_TYPE *def;
+ EggAsn1xDef *def;
/* A context specific tag */
if (flags & FLAG_TAG) {
@@ -601,7 +627,7 @@ anode_calc_tag (GNode *node)
static gboolean
anode_calc_explicit_for_flags (GNode *node, gint flags)
{
- const ASN1_ARRAY_TYPE *opt;
+ const EggAsn1xDef *opt;
if ((flags & FLAG_TAG) != FLAG_TAG)
return FALSE;
opt = anode_opt_lookup (node, TYPE_TAG, NULL);
@@ -2546,7 +2572,7 @@ egg_asn1x_have (GNode *node)
gboolean
egg_asn1x_get_boolean (GNode *node, gboolean *value)
{
- ASN1_ARRAY_TYPE *opt;
+ EggAsn1xDef *opt;
Atlv *tlv;
g_return_val_if_fail (node, FALSE);
@@ -2610,7 +2636,7 @@ GQuark
egg_asn1x_get_enumerated (GNode *node)
{
gchar buf[sizeof (gulong) * 3];
- ASN1_ARRAY_TYPE *opt;
+ EggAsn1xDef *opt;
gulong val;
Atlv *tlv;
@@ -2644,7 +2670,7 @@ egg_asn1x_get_enumerated (GNode *node)
gboolean
egg_asn1x_set_enumerated (GNode *node, GQuark value)
{
- ASN1_ARRAY_TYPE *opt;
+ EggAsn1xDef *opt;
const gchar *name;
gpointer data;
gsize n_data;
@@ -2679,7 +2705,7 @@ egg_asn1x_set_enumerated (GNode *node, GQuark value)
gboolean
egg_asn1x_get_integer_as_ulong (GNode *node, gulong *value)
{
- const ASN1_ARRAY_TYPE *opt;
+ const EggAsn1xDef *opt;
const gchar *defval;
Atlv *tlv;
gchar *end;
@@ -3426,7 +3452,7 @@ egg_asn1x_set_choice (GNode *node, GNode *choice)
static gboolean
anode_parse_size (GNode *node, const gchar *text, gulong *value)
{
- ASN1_ARRAY_TYPE *def;
+ EggAsn1xDef *def;
gchar *end = NULL;
if (text == NULL) {
@@ -3450,7 +3476,7 @@ anode_parse_size (GNode *node, const gchar *text, gulong *value)
static gboolean
anode_validate_size (GNode *node, gulong length)
{
- ASN1_ARRAY_TYPE *size;
+ EggAsn1xDef *size;
gulong value1 = 0;
gulong value2 = G_MAXULONG;
@@ -3784,8 +3810,8 @@ compare_nodes_by_tag (gconstpointer a, gconstpointer b)
return (taga < tagb) ? -1 : 1;
}
-static const ASN1_ARRAY_TYPE*
-adef_next_sibling (const ASN1_ARRAY_TYPE *def)
+static const EggAsn1xDef *
+adef_next_sibling (const EggAsn1xDef *def)
{
int depth = 0;
@@ -3812,8 +3838,8 @@ adef_next_sibling (const ASN1_ARRAY_TYPE *def)
return def;
}
-static const ASN1_ARRAY_TYPE*
-adef_first_child (const ASN1_ARRAY_TYPE *def)
+static const EggAsn1xDef *
+adef_first_child (const EggAsn1xDef *def)
{
g_assert (def);
g_assert (def->value || def->type || def->name);
@@ -3826,10 +3852,12 @@ adef_first_child (const ASN1_ARRAY_TYPE *def)
return def;
}
-static const ASN1_ARRAY_TYPE*
-lookup_def_of_type (const ASN1_ARRAY_TYPE *defs, const gchar *name, gint type)
+static const EggAsn1xDef *
+lookup_def_of_type (const EggAsn1xDef *defs,
+ const gchar *name,
+ gint type)
{
- const ASN1_ARRAY_TYPE *def;
+ const EggAsn1xDef *def;
g_assert (defs);
g_assert (defs->value || defs->type || defs->name);
@@ -3845,8 +3873,8 @@ lookup_def_of_type (const ASN1_ARRAY_TYPE *defs, const gchar *name, gint type)
static gboolean
traverse_and_prepare (GNode *node, gpointer data)
{
- const ASN1_ARRAY_TYPE *defs = data;
- const ASN1_ARRAY_TYPE *def;
+ const EggAsn1xDef *defs = data;
+ const EggAsn1xDef *def;
const gchar *identifier;
Anode *an, *anj;
GNode *join = NULL;
@@ -3932,12 +3960,14 @@ traverse_and_prepare (GNode *node, gpointer data)
return FALSE;
}
-static const ASN1_ARRAY_TYPE*
-match_oid_in_definition (const ASN1_ARRAY_TYPE *def, GHashTable *names,
- const gchar *match, const gchar **problem)
+static const EggAsn1xDef *
+match_oid_in_definition (const EggAsn1xDef *def,
+ GHashTable *names,
+ const gchar *match,
+ const gchar **problem)
{
- const ASN1_ARRAY_TYPE *result = NULL;
- const ASN1_ARRAY_TYPE *odef;
+ const EggAsn1xDef *result = NULL;
+ const EggAsn1xDef *odef;
const gchar *value;
GString *oid = NULL;
@@ -3983,11 +4013,12 @@ match_oid_in_definition (const ASN1_ARRAY_TYPE *def, GHashTable *names,
return result;
}
-static const ASN1_ARRAY_TYPE*
-match_oid_in_definitions (const ASN1_ARRAY_TYPE *defs, const gchar *match)
+static const EggAsn1xDef *
+match_oid_in_definitions (const EggAsn1xDef *defs,
+ const gchar *match)
{
- const ASN1_ARRAY_TYPE *def;
- const ASN1_ARRAY_TYPE *result;
+ const EggAsn1xDef *def;
+ const EggAsn1xDef *result;
GHashTable *names;
gboolean progress;
const gchar *problem;
@@ -4049,9 +4080,10 @@ is_oid_number (const gchar *p)
}
GNode*
-egg_asn1x_create (const ASN1_ARRAY_TYPE *defs, const gchar *type)
+egg_asn1x_create (const EggAsn1xDef *defs,
+ const gchar *type)
{
- const ASN1_ARRAY_TYPE *def;
+ const EggAsn1xDef *def;
GNode *root, *parent, *node;
int flags;
@@ -4112,14 +4144,15 @@ egg_asn1x_create (const ASN1_ARRAY_TYPE *defs, const gchar *type)
}
GNode*
-egg_asn1x_create_quark (const ASN1_ARRAY_TYPE *defs, GQuark type)
+egg_asn1x_create_quark (const EggAsn1xDef *defs,
+ GQuark type)
{
g_return_val_if_fail (type, NULL);
return egg_asn1x_create (defs, g_quark_to_string (type));
}
GNode*
-egg_asn1x_create_and_decode (const ASN1_ARRAY_TYPE *defs,
+egg_asn1x_create_and_decode (const EggAsn1xDef *defs,
const gchar *identifier,
EggBytes *data)
{
@@ -4170,7 +4203,7 @@ dump_append_flags (GString *output, gint flags)
static gboolean
traverse_and_dump (GNode *node, gpointer unused)
{
- ASN1_ARRAY_TYPE *def;
+ EggAsn1xDef *def;
guint i, depth;
GString *output;
gchar *string;
diff --git a/egg/egg-asn1x.h b/egg/egg-asn1x.h
index e211b6d..4849eda 100644
--- a/egg/egg-asn1x.h
+++ b/egg/egg-asn1x.h
@@ -33,15 +33,15 @@ typedef void* (*EggAllocator) (void* p, gsize);
#define HAVE_EGG_ALLOCATOR
#endif
-struct static_struct_asn;
+typedef struct _EggAsn1xDef EggAsn1xDef;
-GNode* egg_asn1x_create (const struct static_struct_asn *defs,
+GNode* egg_asn1x_create (const EggAsn1xDef *defs,
const gchar *type);
-GNode* egg_asn1x_create_quark (const struct static_struct_asn *defs,
+GNode* egg_asn1x_create_quark (const EggAsn1xDef *defs,
GQuark type);
-GNode* egg_asn1x_create_and_decode (const struct static_struct_asn *defs,
+GNode* egg_asn1x_create_and_decode (const EggAsn1xDef *defs,
const gchar *type,
EggBytes *data);
diff --git a/egg/tests/Makefile.am b/egg/tests/Makefile.am
index 536958d..e736f85 100644
--- a/egg/tests/Makefile.am
+++ b/egg/tests/Makefile.am
@@ -1,7 +1,12 @@
include $(top_srcdir)/Makefile.decl
-asn1-def-test.c: test.asn
- $(ASN1PARSER) -o asn1-def-test.c $(srcdir)/test.asn
+ASN_FILES = \
+ test.asn
+
+ASN_SRCS = $(ASN_FILES:.asn=.asn.h)
+
+BUILT_SOURCES = \
+ $(ASN_SRCS)
INCLUDES = \
-I$(top_builddir) \
@@ -30,7 +35,7 @@ TEST_PROGS = \
test_asn1_SOURCES = \
test-asn1.c \
- asn1-def-test.c
+ $(ASN_SRCS)
check_PROGRAMS = $(TEST_PROGS)
@@ -44,11 +49,11 @@ check-memory: perform-memcheck
all-local: $(check_PROGRAMS)
EXTRA_DIST = \
- test.asn \
+ $(ASN_FILES) \
files
-DISTCLEANFILES = \
- asn1-def-test.c
+CLEANFILES = \
+ $(ASN_SRCS)
# ------------------------------------------------------------------------------
@@ -60,5 +65,4 @@ test_asn1x_SOURCES = \
test_asn1x_LDADD = \
$(top_builddir)/egg/libegg-asn1x.la \
- $(LIBTASN1_LIBS) \
$(LDADD)
diff --git a/egg/tests/test-asn1.c b/egg/tests/test-asn1.c
index 222042b..480501f 100644
--- a/egg/tests/test-asn1.c
+++ b/egg/tests/test-asn1.c
@@ -28,13 +28,13 @@
#include "egg/egg-testing.h"
#include <glib.h>
-#include <libtasn1.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-extern const ASN1_ARRAY_TYPE test_asn1_tab[];
+typedef struct _EggAsn1xDef ASN1_ARRAY_TYPE;
+#include "test.asn.h"
const gchar I33[] = "\x02\x01\x2A";
const gchar I253[] = "\x02\x02\x00\xFD";
diff --git a/egg/tests/test-asn1x.c b/egg/tests/test-asn1x.c
index cc60c7f..720d62a 100644
--- a/egg/tests/test-asn1x.c
+++ b/egg/tests/test-asn1x.c
@@ -64,7 +64,9 @@ build_personal_name (void)
#endif
static void
-test_some_asn1_stuff (const ASN1_ARRAY_TYPE *defs, const gchar *file, const gchar *identifier)
+test_some_asn1_stuff (const EggAsn1xDef *defs,
+ const gchar *file,
+ const gchar *identifier)
{
GNode *asn;
EggBytes *encoded;
diff --git a/egg/tests/test-dn.c b/egg/tests/test-dn.c
index 7f95439..530d342 100644
--- a/egg/tests/test-dn.c
+++ b/egg/tests/test-dn.c
@@ -30,7 +30,6 @@
#include <glib.h>
#include <gcrypt.h>
-#include <libtasn1.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/gcr/gcr-parser.c b/gcr/gcr-parser.c
index 4b4e450..0ef9216 100644
--- a/gcr/gcr-parser.c
+++ b/gcr/gcr-parser.c
@@ -951,7 +951,7 @@ done:
*/
static GNode *
-decode_pkcs12_asn1_accepting_invalid_crap (const ASN1_ARRAY_TYPE *defs,
+decode_pkcs12_asn1_accepting_invalid_crap (const EggAsn1xDef *defs,
const gchar *identifier,
EggBytes *data)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]