implemented asn1_get_known_oid(), mapping OID index to ASN1 OID

This commit is contained in:
Martin Willi 2009-04-14 13:50:23 +00:00
parent 9c4387edcd
commit 56807f35b9
3 changed files with 42 additions and 1 deletions

View File

@ -217,6 +217,35 @@ int asn1_known_oid(chunk_t object)
return -1;
}
/*
* 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.
*/

View File

@ -106,6 +106,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

View 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 ? "," : " "