create algorithmIdentifier dynamically from OID database
[strongswan.git] / src / libstrongswan / asn1 / asn1.c
index ea6702d..c565e14 100644 (file)
@@ -38,151 +38,14 @@ const chunk_t ASN1_INTEGER_0 = chunk_from_buf(ASN1_INTEGER_0_str);
 const chunk_t ASN1_INTEGER_1 = chunk_from_buf(ASN1_INTEGER_1_str);
 const chunk_t ASN1_INTEGER_2 = chunk_from_buf(ASN1_INTEGER_2_str);
 
-/**
- * some popular algorithmIdentifiers
- */
-
-static u_char ASN1_md2_id_str[] = {
-       0x30, 0x0c,
-                 0x06, 0x08,
-                               0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x02,
-                 0x05,0x00,
-};
-
-static u_char ASN1_md5_id_str[] = {
-       0x30, 0x0C,
-                 0x06, 0x08,
-                               0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05,
-                 0x05, 0x00
-};
-
-static u_char ASN1_sha1_id_str[] = {
-       0x30, 0x09,
-                 0x06, 0x05,
-                               0x2B, 0x0E,0x03, 0x02, 0x1A,
-                 0x05, 0x00
-};
-
-static u_char ASN1_sha256_id_str[] = {
-       0x30, 0x0d,
-                 0x06, 0x09,
-                               0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
-                 0x05, 0x00
-};
-
-static u_char ASN1_sha384_id_str[] = {
-       0x30, 0x0d,
-                 0x06, 0x09,
-                               0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
-                 0x05, 0x00
-};
-
-static u_char ASN1_sha512_id_str[] = {
-       0x30, 0x0d,
-                 0x06, 0x09,
-                               0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
-                 0x05,0x00
-};
-
-static u_char ASN1_md2WithRSA_id_str[] = {
-       0x30, 0x0D,
-                 0x06, 0x09,
-                               0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x02,
-                 0x05, 0x00
-};
-
-static u_char ASN1_md5WithRSA_id_str[] = {
-       0x30, 0x0D,
-                 0x06, 0x09,
-                               0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x04,
-                 0x05, 0x00
-};
-
-static u_char ASN1_sha1WithRSA_id_str[] = {
-       0x30, 0x0D,
-                 0x06, 0x09,
-                               0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05,
-                 0x05, 0x00
-};
-
-static u_char ASN1_sha256WithRSA_id_str[] = {
-       0x30, 0x0D,
-                 0x06, 0x09,
-                               0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
-                 0x05, 0x00
-};
-
-static u_char ASN1_sha384WithRSA_id_str[] = {
-       0x30, 0x0D,
-                 0x06, 0x09,
-                               0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0C,
-                 0x05, 0x00
-};
-
-static u_char ASN1_sha512WithRSA_id_str[] = {
-       0x30, 0x0D,
-                 0x06, 0x09,
-                               0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0D,
-                 0x05, 0x00
-};
-
-static u_char ASN1_rsaEncryption_id_str[] = {
-       0x30, 0x0D,
-                 0x06, 0x09,
-                               0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01,
-                 0x05, 0x00
-};
-
-static const chunk_t ASN1_md2_id    = chunk_from_buf(ASN1_md2_id_str);
-static const chunk_t ASN1_md5_id    = chunk_from_buf(ASN1_md5_id_str);
-static const chunk_t ASN1_sha1_id   = chunk_from_buf(ASN1_sha1_id_str);
-static const chunk_t ASN1_sha256_id = chunk_from_buf(ASN1_sha256_id_str);
-static const chunk_t ASN1_sha384_id = chunk_from_buf(ASN1_sha384_id_str);
-static const chunk_t ASN1_sha512_id = chunk_from_buf(ASN1_sha512_id_str);
-static const chunk_t ASN1_rsaEncryption_id = chunk_from_buf(ASN1_rsaEncryption_id_str);
-static const chunk_t ASN1_md2WithRSA_id = chunk_from_buf(ASN1_md2WithRSA_id_str);
-static const chunk_t ASN1_md5WithRSA_id = chunk_from_buf(ASN1_md5WithRSA_id_str);
-static const chunk_t ASN1_sha1WithRSA_id = chunk_from_buf(ASN1_sha1WithRSA_id_str);
-static const chunk_t ASN1_sha256WithRSA_id = chunk_from_buf(ASN1_sha256WithRSA_id_str);
-static const chunk_t ASN1_sha384WithRSA_id = chunk_from_buf(ASN1_sha384WithRSA_id_str);
-static const chunk_t ASN1_sha512WithRSA_id = chunk_from_buf(ASN1_sha512WithRSA_id_str);
-
 /*
  * Defined in header.
  */
 chunk_t asn1_algorithmIdentifier(int oid)
 {
-       switch (oid)
-       {
-               case OID_RSA_ENCRYPTION:
-                       return ASN1_rsaEncryption_id;
-               case OID_MD2_WITH_RSA:
-                       return ASN1_md2WithRSA_id;
-               case OID_MD5_WITH_RSA:
-                       return ASN1_md5WithRSA_id;
-               case OID_SHA1_WITH_RSA:
-                       return ASN1_sha1WithRSA_id;
-               case OID_SHA256_WITH_RSA:
-                       return ASN1_sha256WithRSA_id;
-               case OID_SHA384_WITH_RSA:
-                       return ASN1_sha384WithRSA_id;
-               case OID_SHA512_WITH_RSA:
-                       return ASN1_sha512WithRSA_id;
-               case OID_MD2:
-                       return ASN1_md2_id;
-               case OID_MD5:
-                       return ASN1_md5_id;
-               case OID_SHA1:
-                       return ASN1_sha1_id;
-               case OID_SHA256:
-                       return ASN1_sha256_id;
-               case OID_SHA384:
-                       return ASN1_sha384_id;
-               case OID_SHA512:
-                       return ASN1_sha512_id;
-               default:
-                       return chunk_empty;
-       }
+       return asn1_wrap(ASN1_SEQUENCE, "mm",
+                                       asn1_build_known_oid(oid),
+                                       asn1_wrap(ASN1_NULL, ""));
 }
 
 /*