#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,
};
struct _Anode {
- const ASN1_ARRAY_TYPE *def;
- const ASN1_ARRAY_TYPE *join;
+ const EggAsn1xDef *def;
+ const EggAsn1xDef *join;
GList *opts;
Atlv *tlv;
}
static GNode*
-anode_new (const ASN1_ARRAY_TYPE *def)
+anode_new (const EggAsn1xDef *def)
{
Anode *an = g_slice_new0 (Anode);
an->def = def;
}
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;
}
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)) {
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)) {
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)) {
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) {
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);
gboolean
egg_asn1x_get_boolean (GNode *node, gboolean *value)
{
- ASN1_ARRAY_TYPE *opt;
+ EggAsn1xDef *opt;
Atlv *tlv;
g_return_val_if_fail (node, FALSE);
egg_asn1x_get_enumerated (GNode *node)
{
gchar buf[sizeof (gulong) * 3];
- ASN1_ARRAY_TYPE *opt;
+ EggAsn1xDef *opt;
gulong val;
Atlv *tlv;
gboolean
egg_asn1x_set_enumerated (GNode *node, GQuark value)
{
- ASN1_ARRAY_TYPE *opt;
+ EggAsn1xDef *opt;
const gchar *name;
gpointer data;
gsize n_data;
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;
static gboolean
anode_parse_size (GNode *node, const gchar *text, gulong *value)
{
- ASN1_ARRAY_TYPE *def;
+ EggAsn1xDef *def;
gchar *end = NULL;
if (text == NULL) {
static gboolean
anode_validate_size (GNode *node, gulong length)
{
- ASN1_ARRAY_TYPE *size;
+ EggAsn1xDef *size;
gulong value1 = 0;
gulong value2 = G_MAXULONG;
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;
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);
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);
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;
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;
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;
}
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;
}
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)
{
static gboolean
traverse_and_dump (GNode *node, gpointer unused)
{
- ASN1_ARRAY_TYPE *def;
+ EggAsn1xDef *def;
guint i, depth;
GString *output;
gchar *string;