aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <JBottomley@Parallels.com>2012-12-10 23:13:43 +0000
committerJames Bottomley <JBottomley@Parallels.com>2012-12-12 00:23:50 +0000
commitcd5b2642941438e24c1f2d007778b9d61e6b8e1d (patch)
tree2f1eda432d17efa8dbc73dc35b6aa542c5b34813
parent7190d1a291dd6eb507f66b79b96d96c33f50d89f (diff)
downloadefitools-cd5b2642941438e24c1f2d007778b9d61e6b8e1d.tar.gz
asn1: more updates to pare the parser down
-rw-r--r--lib/asn1/asn1.c40
-rw-r--r--lib/asn1/asn1.h2
-rw-r--r--lib/asn1/asn1_parser.c31
-rw-r--r--lib/asn1/asn1_parser.h2
4 files changed, 38 insertions, 37 deletions
diff --git a/lib/asn1/asn1.c b/lib/asn1/asn1.c
index c9f6fce..8edc1dd 100644
--- a/lib/asn1/asn1.c
+++ b/lib/asn1/asn1.c
@@ -18,9 +18,11 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include <stdlib.h>
-#include <debug.h>
-
+#include "typedefs.h"
+#include "enumerator.h"
+#include "chunk.h"
#include "oid.h"
#include "asn1.h"
#include "asn1_parser.h"
@@ -222,7 +224,7 @@ size_t asn1_length(chunk_t *blob)
if (blob->len < 2)
{
- DBG2(DBG_ASN, "insufficient number of octets to parse ASN.1 length");
+ DEBUG("insufficient number of octets to parse ASN.1 length");
return ASN1_INVALID_LENGTH;
}
@@ -235,7 +237,7 @@ size_t asn1_length(chunk_t *blob)
{ /* single length octet */
if (n > blob->len)
{
- DBG2(DBG_ASN, "length is larger than remaining blob size");
+ DEBUG("length is larger than remaining blob size");
return ASN1_INVALID_LENGTH;
}
return n;
@@ -246,13 +248,13 @@ size_t asn1_length(chunk_t *blob)
if (n == 0 || n > blob->len)
{
- DBG2(DBG_ASN, "number of length octets invalid");
+ DEBUG("number of length octets invalid");
return ASN1_INVALID_LENGTH;
}
if (n > sizeof(len))
{
- DBG2(DBG_ASN, "number of length octets is larger than limit of"
+ DEBUG("number of length octets is larger than limit of"
" %d octets", (int)sizeof(len));
return ASN1_INVALID_LENGTH;
}
@@ -266,7 +268,7 @@ size_t asn1_length(chunk_t *blob)
}
if (len > blob->len)
{
- DBG2(DBG_ASN, "length is larger than remaining blob size");
+ DEBUG("length is larger than remaining blob size");
return ASN1_INVALID_LENGTH;
}
return len;
@@ -477,12 +479,12 @@ void asn1_debug_simple_object(chunk_t object, asn1_t type, bool private)
{
break;
}
- DBG2(DBG_ASN, " %s", oid_str);
+ DEBUG(" %s", oid_str);
free(oid_str);
}
else
{
- DBG2(DBG_ASN, " '%s'", oid_names[oid].name);
+ DEBUG(" '%s'", oid_names[oid].name);
}
return;
case ASN1_UTF8STRING:
@@ -490,14 +492,14 @@ void asn1_debug_simple_object(chunk_t object, asn1_t type, bool private)
case ASN1_PRINTABLESTRING:
case ASN1_T61STRING:
case ASN1_VISIBLESTRING:
- DBG2(DBG_ASN, " '%.*s'", (int)object.len, object.ptr);
+ DEBUG(" '%.*s'", (int)object.len, object.ptr);
return;
case ASN1_UTCTIME:
case ASN1_GENERALIZEDTIME:
{
time_t time = asn1_to_time(&object, type);
- DBG2(DBG_ASN, " '%T'", &time, TRUE);
+ DEBUG(" '%T'", &time, TRUE);
}
return;
default:
@@ -505,11 +507,11 @@ void asn1_debug_simple_object(chunk_t object, asn1_t type, bool private)
}
if (private)
{
- DBG4(DBG_ASN, "%B", &object);
+ DEBUG("%B", &object);
}
else
{
- DBG3(DBG_ASN, "%B", &object);
+ DEBUG("%B", &object);
}
}
@@ -523,14 +525,14 @@ bool asn1_parse_simple_object(chunk_t *object, asn1_t type, u_int level, const c
/* an ASN.1 object must possess at least a tag and length field */
if (object->len < 2)
{
- DBG2(DBG_ASN, "L%d - %s: ASN.1 object smaller than 2 octets", level,
+ DEBUG("L%d - %s: ASN.1 object smaller than 2 octets", level,
name);
return FALSE;
}
if (*object->ptr != type)
{
- DBG2(DBG_ASN, "L%d - %s: ASN1 tag 0x%02x expected, but is 0x%02x",
+ DEBUG("L%d - %s: ASN1 tag 0x%02x expected, but is 0x%02x",
level, name, type, *object->ptr);
return FALSE;
}
@@ -539,12 +541,12 @@ bool asn1_parse_simple_object(chunk_t *object, asn1_t type, u_int level, const c
if (len == ASN1_INVALID_LENGTH || object->len < len)
{
- DBG2(DBG_ASN, "L%d - %s: length of ASN.1 object invalid or too large",
+ DEBUG("L%d - %s: length of ASN.1 object invalid or too large",
level, name);
return FALSE;
}
- DBG2(DBG_ASN, "L%d - %s:", level, name);
+ DEBUG("L%d - %s:", level, name);
asn1_debug_simple_object(*object, type, FALSE);
return TRUE;
}
@@ -620,7 +622,7 @@ bool is_asn1(chunk_t blob)
tag = *blob.ptr;
if (tag != ASN1_SEQUENCE && tag != ASN1_SET && tag != ASN1_OCTET_STRING)
{
- DBG2(DBG_ASN, " file content is not binary ASN.1");
+ DEBUG(" file content is not binary ASN.1");
return FALSE;
}
@@ -638,7 +640,7 @@ bool is_asn1(chunk_t blob)
return TRUE;
}
- DBG2(DBG_ASN, " file size does not match ASN.1 coded length");
+ DEBUG(" file size does not match ASN.1 coded length");
return FALSE;
}
diff --git a/lib/asn1/asn1.h b/lib/asn1/asn1.h
index 15ffff6..b6cd9be 100644
--- a/lib/asn1/asn1.h
+++ b/lib/asn1/asn1.h
@@ -25,8 +25,6 @@
#include <stdarg.h>
-#include <library.h>
-
/**
* Definition of some primitive ASN1 types
*/
diff --git a/lib/asn1/asn1_parser.c b/lib/asn1/asn1_parser.c
index 40e11b3..108c0f1 100644
--- a/lib/asn1/asn1_parser.c
+++ b/lib/asn1/asn1_parser.c
@@ -18,9 +18,10 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include <stdlib.h>
-#include <debug.h>
-
+#include "typedefs.h"
+#include "chunk.h"
#include "asn1.h"
#include "asn1_parser.h"
@@ -120,7 +121,7 @@ METHOD(asn1_parser_t, iterate, bool,
if ((obj.flags & ASN1_DEF) && (blob->len == 0 || *start_ptr != obj.type) )
{
/* field is missing */
- DBG2(DBG_ASN, "L%d - %s:", level, obj.name);
+ DEBUG("L%d - %s:", level, obj.name);
if (obj.type & ASN1_CONSTRUCTED)
{
this->line++ ; /* skip context-specific tag */
@@ -147,8 +148,8 @@ METHOD(asn1_parser_t, iterate, bool,
if (blob->len < 2)
{
- DBG1(DBG_ASN, "L%d - %s: ASN.1 object smaller than 2 octets",
- level, obj.name);
+ DEBUG("L%d - %s: ASN.1 object smaller than 2 octets",
+ level, obj.name);
this->success = FALSE;
goto end;
}
@@ -157,7 +158,7 @@ METHOD(asn1_parser_t, iterate, bool,
if (blob1->len == ASN1_INVALID_LENGTH)
{
- DBG1(DBG_ASN, "L%d - %s: length of ASN.1 object invalid or too large",
+ DEBUG("L%d - %s: length of ASN.1 object invalid or too large",
level, obj.name);
this->success = FALSE;
}
@@ -170,7 +171,7 @@ METHOD(asn1_parser_t, iterate, bool,
if (obj.flags & ASN1_RAW)
{
- DBG2(DBG_ASN, "L%d - %s:", level, obj.name);
+ DEBUG("L%d - %s:", level, obj.name);
object->ptr = start_ptr;
object->len = (size_t)(blob->ptr - start_ptr);
goto end;
@@ -178,14 +179,14 @@ METHOD(asn1_parser_t, iterate, bool,
if (*start_ptr != obj.type && !(this->implicit && this->line == 0))
{
- DBG2(DBG_ASN, "L%d - %s: ASN1 tag 0x%02x expected, but is 0x%02x",
+ DEBUG("L%d - %s: ASN1 tag 0x%02x expected, but is 0x%02x",
level, obj.name, obj.type, *start_ptr);
- DBG3(DBG_ASN, "%b", start_ptr, (u_int)(blob->ptr - start_ptr));
+ DEBUG("%b", start_ptr, (u_int)(blob->ptr - start_ptr));
this->success = FALSE;
goto end;
}
- DBG2(DBG_ASN, "L%d - %s:", level, obj.name);
+ DEBUG("L%d - %s:", level, obj.name);
/* In case of "SEQUENCE OF" or "SET OF" start a loop */
if (obj.flags & ASN1_LOOP)
@@ -214,11 +215,11 @@ METHOD(asn1_parser_t, iterate, bool,
object->len = (size_t)(blob->ptr - start_ptr);
if (this->private)
{
- DBG4(DBG_ASN, "%B", object);
+ DEBUG("%B", object);
}
else
{
- DBG3(DBG_ASN, "%B", object);
+ DEBUG("%B", object);
}
}
else if (obj.flags & ASN1_BODY)
@@ -270,7 +271,9 @@ asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, chunk_t blob)
{
private_asn1_parser_t *this;
- INIT(this,
+ this = malloc(sizeof(*this));
+
+ *this = (private_asn1_parser_t) {
.public = {
.iterate = _iterate,
.get_level = _get_level,
@@ -283,7 +286,7 @@ asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, chunk_t blob)
.blobs[0] = blob,
.line = -1,
.success = TRUE,
- );
+ };
return &this->public;
}
diff --git a/lib/asn1/asn1_parser.h b/lib/asn1/asn1_parser.h
index 0edc22c..4b5320f 100644
--- a/lib/asn1/asn1_parser.h
+++ b/lib/asn1/asn1_parser.h
@@ -25,8 +25,6 @@
#include <stdarg.h>
-#include <library.h>
-
#include "asn1.h"
/**