Moved log message for unexpected ASN.1 objects to level 2.
[strongswan.git] / src / libstrongswan / asn1 / asn1_parser.c
index 3e5bbba..40e11b3 100644 (file)
@@ -78,10 +78,8 @@ struct private_asn1_parser_t {
        chunk_t blobs[ASN1_MAX_LEVEL + 2];
 };
 
-/**
- * Implementation of asn1_parser_t.iterate
- */
-static bool iterate(private_asn1_parser_t *this, int *objectID, chunk_t *object)
+METHOD(asn1_parser_t, iterate, bool,
+       private_asn1_parser_t *this, int *objectID, chunk_t *object)
 {
        chunk_t *blob, *blob1;
        u_char *start_ptr;
@@ -122,7 +120,7 @@ static bool iterate(private_asn1_parser_t *this, int *objectID, chunk_t *object)
        if ((obj.flags & ASN1_DEF) && (blob->len == 0 || *start_ptr != obj.type) )
        {
                /* field is missing */
-               DBG2(DBG_LIB, "L%d - %s:", level, obj.name);
+               DBG2(DBG_ASN, "L%d - %s:", level, obj.name);
                if (obj.type & ASN1_CONSTRUCTED)
                {
                        this->line++ ;  /* skip context-specific tag */
@@ -149,7 +147,7 @@ static bool iterate(private_asn1_parser_t *this, int *objectID, chunk_t *object)
 
        if (blob->len < 2)
        {
-               DBG1(DBG_LIB, "L%d - %s:  ASN.1 object smaller than 2 octets",
+               DBG1(DBG_ASN, "L%d - %s:  ASN.1 object smaller than 2 octets",
                                        level, obj.name);
                this->success = FALSE;
                goto end;
@@ -159,7 +157,7 @@ static bool iterate(private_asn1_parser_t *this, int *objectID, chunk_t *object)
 
        if (blob1->len == ASN1_INVALID_LENGTH)
        {
-               DBG1(DBG_LIB, "L%d - %s:  length of ASN.1 object invalid or too large",
+               DBG1(DBG_ASN, "L%d - %s:  length of ASN.1 object invalid or too large",
                                        level, obj.name);
                this->success = FALSE;
        }
@@ -172,7 +170,7 @@ static bool iterate(private_asn1_parser_t *this, int *objectID, chunk_t *object)
 
        if (obj.flags & ASN1_RAW)
        {
-               DBG2(DBG_LIB, "L%d - %s:", level, obj.name);
+               DBG2(DBG_ASN, "L%d - %s:", level, obj.name);
                object->ptr = start_ptr;
                object->len = (size_t)(blob->ptr - start_ptr);
                goto end;
@@ -180,14 +178,14 @@ static bool iterate(private_asn1_parser_t *this, int *objectID, chunk_t *object)
 
        if (*start_ptr != obj.type && !(this->implicit && this->line == 0))
        {
-               DBG1(DBG_LIB, "L%d - %s: ASN1 tag 0x%02x expected, but is 0x%02x",
+               DBG2(DBG_ASN, "L%d - %s: ASN1 tag 0x%02x expected, but is 0x%02x",
                                        level, obj.name, obj.type, *start_ptr);
-               DBG3(DBG_LIB, "%b", start_ptr, (u_int)(blob->ptr - start_ptr));
+               DBG3(DBG_ASN, "%b", start_ptr, (u_int)(blob->ptr - start_ptr));
                this->success = FALSE;
                goto end;
        }
 
-       DBG2(DBG_LIB, "L%d - %s:", level, obj.name);
+       DBG2(DBG_ASN, "L%d - %s:", level, obj.name);
 
        /* In case of "SEQUENCE OF" or "SET OF" start a loop */
        if (obj.flags & ASN1_LOOP)
@@ -216,11 +214,11 @@ static bool iterate(private_asn1_parser_t *this, int *objectID, chunk_t *object)
                object->len = (size_t)(blob->ptr - start_ptr);
                if (this->private)
                {
-                       DBG4(DBG_LIB, "%B", object);
+                       DBG4(DBG_ASN, "%B", object);
                }
                else
                {
-                       DBG3(DBG_LIB, "%B", object);
+                       DBG3(DBG_ASN, "%B", object);
                }
        }
        else if (obj.flags & ASN1_BODY)
@@ -234,43 +232,33 @@ end:
        return this->success;
 }
 
-/**
- * Implementation of asn1_parser_t.get_level
- */
-static u_int get_level(private_asn1_parser_t *this)
+METHOD(asn1_parser_t, get_level, u_int,
+private_asn1_parser_t *this)
 {
        return this->level0 + this->objects[this->line].level;
 }
 
-/**
- * Implementation of asn1_parser_t.set_top_level
- */
-static void set_top_level(private_asn1_parser_t *this, u_int level0)
+METHOD(asn1_parser_t, set_top_level, void,
+       private_asn1_parser_t *this, u_int level0)
 {
        this->level0 = level0;
 }
 
-/**
- * Implementation of asn1_parser_t.set_flags
- */
-static void set_flags(private_asn1_parser_t *this, bool implicit, bool private)
+METHOD(asn1_parser_t, set_flags, void,
+       private_asn1_parser_t *this, bool implicit, bool private)
 {
        this->implicit = implicit;
        this->private = private;
 }
 
-/**
- * Implementation of asn1_parser_t.success
- */
-static bool success(private_asn1_parser_t *this)
+METHOD(asn1_parser_t, success, bool,
+       private_asn1_parser_t *this)
 {
        return this->success;
 }
 
-/**
- * Implementation of asn1_parser_t.destroy
- */
-static void destroy(private_asn1_parser_t *this)
+METHOD(asn1_parser_t, destroy, void,
+       private_asn1_parser_t *this)
 {
        free(this);
 }
@@ -280,20 +268,22 @@ static void destroy(private_asn1_parser_t *this)
  */
 asn1_parser_t* asn1_parser_create(asn1Object_t const *objects, chunk_t blob)
 {
-       private_asn1_parser_t *this = malloc_thing(private_asn1_parser_t);
-
-       memset(this, '\0', sizeof(private_asn1_parser_t));
-       this->objects = objects;
-       this->blobs[0] = blob;
-       this->line = -1;
-       this->success = TRUE;
-
-       this->public.iterate = (bool (*)(asn1_parser_t*, int*, chunk_t*))iterate;
-       this->public.get_level = (u_int (*)(asn1_parser_t*))get_level;
-       this->public.set_top_level = (void (*)(asn1_parser_t*, u_int))set_top_level;
-       this->public.set_flags = (void (*)(asn1_parser_t*, bool, bool))set_flags;
-       this->public.success = (bool (*)(asn1_parser_t*))success;
-       this->public.destroy = (void (*)(asn1_parser_t*))destroy;
+       private_asn1_parser_t *this;
+
+       INIT(this,
+               .public = {
+                       .iterate = _iterate,
+                       .get_level = _get_level,
+                       .set_top_level = _set_top_level,
+                       .set_flags = _set_flags,
+                       .success = _success,
+                       .destroy = _destroy,
+               },
+               .objects = objects,
+               .blobs[0] = blob,
+               .line = -1,
+               .success = TRUE,
+       );
 
        return &this->public;
 }