implemented asn1_get_known_oid(), mapping OID index to ASN1 OID
authorMartin Willi <martin@strongswan.org>
Tue, 14 Apr 2009 13:50:23 +0000 (13:50 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 14 Apr 2009 13:50:23 +0000 (13:50 -0000)
src/libstrongswan/asn1/asn1.c
src/libstrongswan/asn1/asn1.h
src/libstrongswan/asn1/oid.pl

index 85695bb..ee11f01 100644 (file)
@@ -220,6 +220,35 @@ int asn1_known_oid(chunk_t object)
 /*
  * Defined in header.
  */
+chunk_t asn1_get_known_oid(int n)
+{
+       chunk_t oid;
+       int i;
+       
+       if (n < 0 || n >= OID_MAX)
+       {
+               return chunk_empty;
+       }
+       
+       i = oid_names[n].level + 1;
+       oid = chunk_alloc(i);
+       do
+       {
+               if (oid_names[n].level >= i)
+               {
+                       n--;
+                       continue;
+               }
+               oid.ptr[--i] = oid_names[n--].octet;
+       }
+       while (i > 0);
+       
+       return oid;
+}
+
+/*
+ * Defined in header.
+ */
 u_int asn1_length(chunk_t *blob)
 {
        u_char n;
index eb03966..1ff9fcb 100644 (file)
@@ -107,6 +107,14 @@ chunk_t asn1_algorithmIdentifier(int oid);
 int asn1_known_oid(chunk_t object);
 
 /**
+ * Converts an known OID index to ASN.1 OID
+ *
+ * @param n                    index into the oid_names[] table
+ * @return                     allocated OID chunk, chunk_empty if index out of range
+ */
+chunk_t asn1_get_known_oid(int n);
+
+/**
  * Returns the length of an ASN.1 object
  * The blob pointer is advanced past the tag length fields
  *
index 373101c..027a850 100644 (file)
@@ -38,6 +38,7 @@ print OID_H "/* Object identifiers (OIDs) used by strongSwan\n",
            "    u_char octet;\n",
            "    u_int  next;\n",
            "    u_int  down;\n",
+           "    u_int  level;\n",
            "    const u_char *name;\n",
            "} oid_t;\n",
            "\n",
@@ -77,6 +78,8 @@ while ($line = <SRC>)
     $counter++;
 }
 
+printf OID_H "\n#define OID_MAX%s%d\n", "\t" x 8, $counter;
+
 print OID_H "\n#endif /* OID_H_ */\n";
 
 close SRC;
@@ -113,12 +116,13 @@ for ($c = 0; $c < $counter; $c++)
        }
     }
 
-    printf OID_C "  {%s%s,%s%3d, %d, %s%s}%s  /* %3d */\n"
+    printf OID_C " {%s%s,%s%3d, %d, %2d, %s%s}%s /* %3d */\n"
        ,' '  x @order[$c]
        , @octet[$c]
        , ' ' x (1 + $max_order - @order[$c])
        , @next[$c]
        , @order[$c+1] > @order[$c]
+       , @order[$c] / 2
        , @name[$c]
        , ' ' x ($max_name - length(@name[$c]))
        , $c != $counter-1 ? "," : " "