Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Side by Side Diff: openssl/crypto/asn1/a_strnid.c

Issue 9254031: Upgrade chrome's OpenSSL to same version Android ships with. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/openssl/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « openssl/crypto/asn1/a_strex.c ('k') | openssl/crypto/asn1/a_time.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* a_strnid.c */ 1 /* a_strnid.c */
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
5 /* ==================================================================== 5 /* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include <ctype.h> 60 #include <ctype.h>
61 #include "cryptlib.h" 61 #include "cryptlib.h"
62 #include <openssl/asn1.h> 62 #include <openssl/asn1.h>
63 #include <openssl/objects.h> 63 #include <openssl/objects.h>
64 64
65 65
66 static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; 66 static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
67 static void st_free(ASN1_STRING_TABLE *tbl); 67 static void st_free(ASN1_STRING_TABLE *tbl);
68 static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, 68 static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
69 const ASN1_STRING_TABLE * const *b); 69 const ASN1_STRING_TABLE * const *b);
70 static int table_cmp(const void *a, const void *b);
71 70
72 71
73 /* This is the global mask for the mbstring functions: this is use to 72 /* This is the global mask for the mbstring functions: this is use to
74 * mask out certain types (such as BMPString and UTF8String) because 73 * mask out certain types (such as BMPString and UTF8String) because
75 * certain software (e.g. Netscape) has problems with them. 74 * certain software (e.g. Netscape) has problems with them.
76 */ 75 */
77 76
78 static unsigned long global_mask = 0xFFFFFFFFL; 77 static unsigned long global_mask = 0xFFFFFFFFL;
79 78
80 void ASN1_STRING_set_default_mask(unsigned long mask) 79 void ASN1_STRING_set_default_mask(unsigned long mask)
81 { 80 {
82 global_mask = mask; 81 global_mask = mask;
83 } 82 }
84 83
85 unsigned long ASN1_STRING_get_default_mask(void) 84 unsigned long ASN1_STRING_get_default_mask(void)
86 { 85 {
87 return global_mask; 86 return global_mask;
88 } 87 }
89 88
90 /* This function sets the default to various "flavours" of configuration. 89 /* This function sets the default to various "flavours" of configuration.
91 * based on an ASCII string. Currently this is: 90 * based on an ASCII string. Currently this is:
92 * MASK:XXXX : a numerical mask value. 91 * MASK:XXXX : a numerical mask value.
93 * nobmp : Don't use BMPStrings (just Printable, T61). 92 * nobmp : Don't use BMPStrings (just Printable, T61).
94 * pkix : PKIX recommendation in RFC2459. 93 * pkix : PKIX recommendation in RFC2459.
95 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004). 94 * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004).
96 * default: the default value, Printable, T61, BMP. 95 * default: the default value, Printable, T61, BMP.
97 */ 96 */
98 97
99 int ASN1_STRING_set_default_mask_asc(char *p) 98 int ASN1_STRING_set_default_mask_asc(const char *p)
100 { 99 {
101 unsigned long mask; 100 unsigned long mask;
102 char *end; 101 char *end;
103 if(!strncmp(p, "MASK:", 5)) { 102 if(!strncmp(p, "MASK:", 5)) {
104 if(!p[5]) return 0; 103 if(!p[5]) return 0;
105 mask = strtoul(p + 5, &end, 0); 104 mask = strtoul(p + 5, &end, 0);
106 if(*end) return 0; 105 if(*end) return 0;
107 } else if(!strcmp(p, "nombstr")) 106 } else if(!strcmp(p, "nombstr"))
108 mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8ST RING)); 107 mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8ST RING));
109 else if(!strcmp(p, "pkix")) 108 else if(!strcmp(p, "pkix"))
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 #define ub_state_name 128 150 #define ub_state_name 128
152 #define ub_organization_name 64 151 #define ub_organization_name 64
153 #define ub_organization_unit_name 64 152 #define ub_organization_unit_name 64
154 #define ub_title 64 153 #define ub_title 64
155 #define ub_email_address 128 154 #define ub_email_address 128
156 #define ub_serial_number 64 155 #define ub_serial_number 64
157 156
158 157
159 /* This table must be kept in NID order */ 158 /* This table must be kept in NID order */
160 159
161 static ASN1_STRING_TABLE tbl_standard[] = { 160 static const ASN1_STRING_TABLE tbl_standard[] = {
162 {NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0}, 161 {NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0},
163 {NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, 162 {NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
164 {NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0}, 163 {NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0},
165 {NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0}, 164 {NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0},
166 {NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0}, 165 {NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0},
167 {NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0} , 166 {NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0} ,
168 {NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO _MASK}, 167 {NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO _MASK},
169 {NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0}, 168 {NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0},
170 {NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0}, 169 {NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0},
171 {NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0}, 170 {NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0},
172 {NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0}, 171 {NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0},
173 {NID_surname, 1, ub_name, DIRSTRING_TYPE, 0}, 172 {NID_surname, 1, ub_name, DIRSTRING_TYPE, 0},
174 {NID_initials, 1, ub_name, DIRSTRING_TYPE, 0}, 173 {NID_initials, 1, ub_name, DIRSTRING_TYPE, 0},
175 {NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STA BLE_NO_MASK}, 174 {NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STA BLE_NO_MASK},
176 {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, 175 {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK},
177 {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, 176 {NID_name, 1, ub_name, DIRSTRING_TYPE, 0},
178 {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, 177 {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK},
179 {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, 178 {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK},
180 {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} 179 {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}
181 }; 180 };
182 181
183 static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, 182 static int sk_table_cmp(const ASN1_STRING_TABLE * const *a,
184 const ASN1_STRING_TABLE * const *b) 183 const ASN1_STRING_TABLE * const *b)
185 { 184 {
186 return (*a)->nid - (*b)->nid; 185 return (*a)->nid - (*b)->nid;
187 } 186 }
188 187
189 static int table_cmp(const void *a, const void *b) 188 DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table);
189
190 static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b)
190 { 191 {
191 » const ASN1_STRING_TABLE *sa = a, *sb = b; 192 » return a->nid - b->nid;
192 » return sa->nid - sb->nid;
193 } 193 }
194 194
195 IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table);
196
195 ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) 197 ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid)
196 { 198 {
197 int idx; 199 int idx;
198 ASN1_STRING_TABLE *ttmp; 200 ASN1_STRING_TABLE *ttmp;
199 ASN1_STRING_TABLE fnd; 201 ASN1_STRING_TABLE fnd;
200 fnd.nid = nid; 202 fnd.nid = nid;
201 » ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd, 203 » ttmp = OBJ_bsearch_table(&fnd, tbl_standard,
202 » » » » » (char *)tbl_standard, 204 » » » sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE));
203 » » » sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE),
204 » » » sizeof(ASN1_STRING_TABLE), table_cmp);
205 if(ttmp) return ttmp; 205 if(ttmp) return ttmp;
206 if(!stable) return NULL; 206 if(!stable) return NULL;
207 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); 207 idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
208 if(idx < 0) return NULL; 208 if(idx < 0) return NULL;
209 return sk_ASN1_STRING_TABLE_value(stable, idx); 209 return sk_ASN1_STRING_TABLE_value(stable, idx);
210 } 210 }
211 211
212 int ASN1_STRING_TABLE_add(int nid, 212 int ASN1_STRING_TABLE_add(int nid,
213 long minsize, long maxsize, unsigned long mask, 213 long minsize, long maxsize, unsigned long mask,
214 unsigned long flags) 214 unsigned long flags)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 281 }
282 282
283 for (tmp = tbl_standard, i = 0; 283 for (tmp = tbl_standard, i = 0;
284 i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) 284 i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++)
285 printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, 285 printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
286 OBJ_nid2ln(tmp->nid)); 286 OBJ_nid2ln(tmp->nid));
287 287
288 } 288 }
289 289
290 #endif 290 #endif
OLDNEW
« no previous file with comments | « openssl/crypto/asn1/a_strex.c ('k') | openssl/crypto/asn1/a_time.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698