]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Some cleanups.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 23 Mar 2003 17:03:40 +0000 (17:03 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 23 Mar 2003 17:03:40 +0000 (17:03 +0000)
lib/x509/common.c
lib/x509/common.h
lib/x509/privkey_pkcs8.c
lib/x509/xml.c

index b76fc49996cdb3b899cec815cfa4629bb73d9758..15191beb7a11bb870ec95ebac52f729994a7b704 100644 (file)
 #include <common.h>
 
 typedef struct _oid2string {
-       const char * OID;
-       const char * DESC;
+       const char * oid;
        const char * ldap_desc;
        int choice;
        int printable;
 } oid2string;
 
-static const oid2string OID2STR[] = {
-       {"2.5.4.6", "X520countryName", "C", 0, 1},
-       {"2.5.4.12", "X520title", "T", 1, 1},
-       {"2.5.4.10", "X520OrganizationName", "O", 1, 1},
-       {"2.5.4.11", "X520OrganizationalUnitName", "OU", 1, 1},
-       {"2.5.4.3", "X520CommonName", "CN", 1, 1},
-       {"2.5.4.7", "X520LocalityName", "L", 1, 1},
-       {"2.5.4.8", "X520StateOrProvinceName", "ST", 1, 1},
-       {"2.5.4.5", "X520serialNumber", "serialNumber", 0, 1},
-       {"2.5.4.20", "X520telephoneNumber", "telephoneNumber", 0, 1},
-
-       {"0.9.2342.19200300.100.1.25", "dc", "DC", 0, 1}, /* FIXME: CHOICE? */
-       {"0.9.2342.19200300.100.1.1", "uid", "UID", 0, 1}, /* FIXME: CHOICE? */
-       {"1.2.840.113549.1.9.1", "Pkcs9email", "EMAIL", 0, 1},
-       {"1.2.840.113549.1.9.7", "Pkcs9challengePassword", NULL, 1, 1},
-       {PKIX1_RSA_OID, "rsaEncryption", NULL, 0, 0},
-
-       {RSA_MD5_OID, "md5WithRSAEncryption", NULL, 0, 0},
-       {RSA_SHA1_OID, "sha1WithRSAEncryption", NULL, 0, 0},
-       {DSA_SHA1_OID, "id-dsa-with-sha1", NULL, 0, 0},
-       {DSA_OID, "id-dsa", NULL, 0, 0},
-       {NULL, NULL, NULL, 0, 0}
+static const oid2string _oid2str[] = {
+       {"2.5.4.6", "C", 0, 1},
+       {"2.5.4.12", "T", 1, 1},
+       {"2.5.4.10", "O", 1, 1},
+       {"2.5.4.11", "OU", 1, 1},
+       {"2.5.4.3", "CN", 1, 1},
+       {"2.5.4.7", "L", 1, 1},
+       {"2.5.4.8", "ST", 1, 1},
+       {"2.5.4.5", "serialNumber", 0, 1},
+       {"2.5.4.20", "telephoneNumber", 0, 1},
+
+       {"0.9.2342.19200300.100.1.25", "DC", 0, 1}, /* FIXME: CHOICE? */
+       {"0.9.2342.19200300.100.1.1", "UID", 0, 1}, /* FIXME: CHOICE? */
+       {"1.2.840.113549.1.9.1", "EMAIL", 0, 1},
+       {"1.2.840.113549.1.9.7", NULL, 1, 1},
+       {PKIX1_RSA_OID, NULL, 0, 0},
+
+       {RSA_MD5_OID, NULL, 0, 0},
+       {RSA_SHA1_OID, NULL, 0, 0},
+       {DSA_SHA1_OID, NULL, 0, 0},
+       {DSA_OID, NULL, 0, 0},
+       {NULL, NULL, 0, 0}
 };
 
 /* Returns 1 if the data defined by the OID are printable.
  */
-int _gnutls_x509_oid_data_printable( const char* OID) {
+int _gnutls_x509_oid_data_printable( const char* oid) {
 int i = 0;
 
        do {
-               if ( strcmp(OID2STR[i].OID, OID)==0)
-                       return OID2STR[i].printable;
+               if ( strcmp(_oid2str[i].oid, oid)==0)
+                       return _oid2str[i].printable;
                i++;
-       } while( OID2STR[i].OID != NULL);
+       } while( _oid2str[i].oid != NULL);
 
        return 0;
 }
@@ -78,38 +77,26 @@ int i = 0;
 /* Returns 1 if the data defined by the OID are of a choice
  * type.
  */
-int _gnutls_x509_oid_data_choice( const char* OID) {
+int _gnutls_x509_oid_data_choice( const char* oid) {
 int i = 0;
 
        do {
-               if ( strcmp(OID2STR[i].OID, OID)==0)
-                       return OID2STR[i].choice;
+               if ( strcmp(_oid2str[i].oid, oid)==0)
+                       return _oid2str[i].choice;
                i++;
-       } while( OID2STR[i].OID != NULL);
+       } while( _oid2str[i].oid != NULL);
 
        return 0;
 }
 
-const char* _gnutls_x509_oid2string( const char* OID) {
+const char* _gnutls_x509_oid2ldap_string( const char* oid) {
 int i = 0;
 
        do {
-               if ( strcmp(OID2STR[i].OID, OID)==0)
-                       return OID2STR[i].DESC;
+               if ( strcmp(_oid2str[i].oid, oid)==0)
+                       return _oid2str[i].ldap_desc;
                i++;
-       } while( OID2STR[i].OID != NULL);
-
-       return NULL;
-}
-
-const char* _gnutls_x509_oid2ldap_string( const char* OID) {
-int i = 0;
-
-       do {
-               if ( strcmp(OID2STR[i].OID, OID)==0)
-                       return OID2STR[i].ldap_desc;
-               i++;
-       } while( OID2STR[i].OID != NULL);
+       } while( _oid2str[i].oid != NULL);
 
        return NULL;
 }
@@ -120,7 +107,7 @@ int i = 0;
  * res may be null. This will just return the res_size, needed to
  * hold the string.
  */
-int _gnutls_x509_oid_data2string( const char* OID, void* value, 
+int _gnutls_x509_oid_data2string( const char* oid, void* value, 
        int value_size, char * res, int *res_size) {
 
 int result;
@@ -137,13 +124,13 @@ ASN1_TYPE tmpasn = ASN1_TYPE_EMPTY;
        
        res[0] = 0;
        
-       if ( _gnutls_x509_oid_data_printable( OID) == 0) {
+       if ( _gnutls_x509_oid_data_printable( oid) == 0) {
                gnutls_assert();
                return GNUTLS_E_INTERNAL_ERROR;
        }
 
-       ANAME = _gnutls_x509_oid2string( OID);
-       CHOICE = _gnutls_x509_oid_data_choice( OID);
+       ANAME = asn1_find_structure_from_oid( _gnutls_get_pkix(), oid);
+       CHOICE = _gnutls_x509_oid_data_choice( oid);
 
        if (ANAME==NULL) {
                gnutls_assert();
index 6c484c7bd1ec6a739f6f586a5daf164155fd4c5c..0661c4d15379b6e99b4642ed71bed24b39497590 100644 (file)
@@ -20,7 +20,6 @@ time_t _gnutls_x509_generalTime2gtime(char *ttime);
 int _gnutls_x509_oid_data2string( const char* OID, void* value, 
        int value_size, char * res, int *res_size);
 
-const char* _gnutls_x509_oid2string( const char* OID);
 const char* _gnutls_x509_oid2ldap_string( const char* OID);
 
 int _gnutls_x509_oid_data_choice( const char* OID);
index 453c305f1e5f270c8e5f65ccbbe96e43041e035b..a1b31826774a94d00a42cb84b0e1c788497d1d39 100644 (file)
@@ -210,8 +210,8 @@ static int encode_to_private_key_info( gnutls_x509_privkey pkey, gnutls_datum* d
 /* Converts a PKCS #8 private key info to
  * a PKCS #8 EncryptedPrivateKeyInfo.
  */
-static ASN1_TYPE encode_to_pkcs8_key( gnutls_x509_privkey pkey, 
-       const gnutls_datum *raw_key, char* password, unsigned int flags)
+static ASN1_TYPE encode_to_pkcs8_key( const gnutls_datum *raw_key, 
+       char* password, unsigned int flags)
 {
        int result;
        gnutls_datum key = {NULL, 0};
@@ -319,7 +319,7 @@ gnutls_datum tmp;
        }
 
 
-       pkcs8_asn = encode_to_pkcs8_key( key, &tmp, password, flags);
+       pkcs8_asn = encode_to_pkcs8_key( &tmp, password, flags);
        _gnutls_free_datum( &tmp);
 
        if (pkcs8_asn == NULL) {
index 0cb2945c39a5a2635e8d3ead601e6d318523b800..d29add0b3ad2f5183bfd16a859da39361b914f98 100644 (file)
@@ -41,6 +41,9 @@
 #include <x509.h>
 #include <common.h>
 
+const char*  asn1_find_structure_from_oid(ASN1_TYPE definitions,
+                   const char *oidValue);
+
 static int _gnutls_x509_expand_extensions(ASN1_TYPE* rasn, const char *root);
 
 static const void *find_default_value(ASN1_TYPE x)
@@ -151,7 +154,7 @@ static int normalize_name( ASN1_TYPE p, char* output, int output_size)
                         up->type & CONST_DEFINED_BY &&
                         type_field(up->left->type)==TYPE_OBJECT_ID) {
 
-                        tmp = _gnutls_x509_oid2string(up->left->value);
+                        tmp = asn1_find_structure_from_oid( _gnutls_get_pkix(), up->left->value);
                         if ( tmp != NULL)
                                 _gnutls_str_cpy( output, output_size, tmp);
                         else {