]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
asn1: Allow suppressing log messages when parsing algorithm identifiers
authorTobias Brunner <tobias@strongswan.org>
Fri, 24 Mar 2023 16:00:10 +0000 (17:00 +0100)
committerTobias Brunner <tobias@strongswan.org>
Thu, 30 Mar 2023 08:46:46 +0000 (10:46 +0200)
src/libstrongswan/asn1/asn1.c
src/libstrongswan/asn1/asn1.h
src/libstrongswan/tests/suites/test_asn1.c

index ef1dd9eaab0a7319356c97cae0441a7c0eeeaa84..cf684e72036c774e6f6ec93a7faed6ae627ee27e 100644 (file)
@@ -648,18 +648,27 @@ int asn1_parse_algorithmIdentifier(chunk_t blob, int level0, chunk_t *parameters
 
        if (asn1_unwrap(&blob, &blob) == ASN1_SEQUENCE)
        {
-               DBG2(DBG_ASN, "L%d - algorithmIdentifier:", level0);
+               if (level0 >= 0)
+               {
+                       DBG2(DBG_ASN, "L%d - algorithmIdentifier:", level0);
+               }
 
                if (asn1_unwrap(&blob, &object) == ASN1_OID)
                {
-                       DBG2(DBG_ASN, "L%d - algorithm:", level0+1);
-                       asn1_debug_simple_object(object, ASN1_OID, FALSE);
+                       if (level0 >= 0)
+                       {
+                               DBG2(DBG_ASN, "L%d - algorithm:", level0+1);
+                               asn1_debug_simple_object(object, ASN1_OID, FALSE);
+                       }
                        alg = asn1_known_oid(object);
 
                        if (blob.len)
                        {
-                               DBG2(DBG_ASN, "L%d - parameters:", level0+1);
-                               DBG3(DBG_ASN, "%B", &blob);
+                               if (level0 >= 0)
+                               {
+                                       DBG2(DBG_ASN, "L%d - parameters:", level0+1);
+                                       DBG3(DBG_ASN, "%B", &blob);
+                               }
                                if (parameters)
                                {
                                        *parameters = blob;
index cb5d86c5c979dc95e18e434a23990cdce627dc47..a94c82e302cf405e5afc88dec509723727a0ea43 100644 (file)
@@ -163,7 +163,7 @@ int asn1_unwrap(chunk_t *blob, chunk_t *content);
  * Parses an ASN.1 algorithmIdentifier object
  *
  * @param blob         ASN.1 coded blob
- * @param level0       top-most level offset
+ * @param level0       top-most level offset (-1 to suppress log messages)
  * @param params       returns optional [ASN.1 coded] parameters
  * @return                     known OID index or OID_UNKNOWN
  */
index 7cedf8e0f3473736a5b1b97d82eb63b726159b40..fc207355d7e7640e2ef4fc73e14f45446ef5a1d7 100644 (file)
@@ -81,11 +81,11 @@ START_TEST(test_asn1_parse_algorithmIdentifier)
                parameters = chunk_empty;
                if (i == 2)
                {
-                       alg = asn1_parse_algorithmIdentifier(algid, 0, NULL);
+                       alg = asn1_parse_algorithmIdentifier(algid, _i, NULL);
                }
                else
                {
-                       alg = asn1_parse_algorithmIdentifier(algid, 0, &parameters);
+                       alg = asn1_parse_algorithmIdentifier(algid, _i, &parameters);
                        if (test[i].empty)
                        {
                                ck_assert(parameters.len == 0 && parameters.ptr == NULL);
@@ -824,7 +824,7 @@ Suite *asn1_suite_create()
        suite_add_tcase(s, tc);
 
        tc = tcase_create("parse_algorithmIdentifier");
-       tcase_add_test(tc, test_asn1_parse_algorithmIdentifier);
+       tcase_add_loop_test(tc, test_asn1_parse_algorithmIdentifier, -1, 1);
        suite_add_tcase(s, tc);
 
        tc = tcase_create("known_oid");