summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509/x509name.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/x509/x509name.c')
-rw-r--r--src/lib/libcrypto/x509/x509name.c324
1 files changed, 182 insertions, 142 deletions
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c
index 729fb060f8..3d90fd67fe 100644
--- a/src/lib/libcrypto/x509/x509name.c
+++ b/src/lib/libcrypto/x509/x509name.c
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -64,97 +64,110 @@
64#include <openssl/evp.h> 64#include <openssl/evp.h>
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66 66
67int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) 67int
68X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len)
68{ 69{
69 ASN1_OBJECT *obj; 70 ASN1_OBJECT *obj;
70 71
71 obj=OBJ_nid2obj(nid); 72 obj = OBJ_nid2obj(nid);
72 if (obj == NULL) return(-1); 73 if (obj == NULL)
73 return(X509_NAME_get_text_by_OBJ(name,obj,buf,len)); 74 return (-1);
75 return (X509_NAME_get_text_by_OBJ(name, obj, buf, len));
74} 76}
75 77
76int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf, 78int
77 int len) 79X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf,
80 int len)
78{ 81{
79 int i; 82 int i;
80 ASN1_STRING *data; 83 ASN1_STRING *data;
81 84
82 i=X509_NAME_get_index_by_OBJ(name,obj,-1); 85 i = X509_NAME_get_index_by_OBJ(name, obj, -1);
83 if (i < 0) return(-1); 86 if (i < 0)
84 data=X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i)); 87 return (-1);
85 i=(data->length > (len-1))?(len-1):data->length; 88 data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i));
86 if (buf == NULL) return(data->length); 89 i = (data->length > (len - 1)) ? (len - 1) : data->length;
87 memcpy(buf,data->data,i); 90 if (buf == NULL)
88 buf[i]='\0'; 91 return (data->length);
89 return(i); 92 memcpy(buf, data->data, i);
93 buf[i] = '\0';
94 return (i);
90} 95}
91 96
92int X509_NAME_entry_count(X509_NAME *name) 97int
98X509_NAME_entry_count(X509_NAME *name)
93{ 99{
94 if (name == NULL) return(0); 100 if (name == NULL)
95 return(sk_X509_NAME_ENTRY_num(name->entries)); 101 return (0);
102 return (sk_X509_NAME_ENTRY_num(name->entries));
96} 103}
97 104
98int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos) 105int
106X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)
99{ 107{
100 ASN1_OBJECT *obj; 108 ASN1_OBJECT *obj;
101 109
102 obj=OBJ_nid2obj(nid); 110 obj = OBJ_nid2obj(nid);
103 if (obj == NULL) return(-2); 111 if (obj == NULL)
104 return(X509_NAME_get_index_by_OBJ(name,obj,lastpos)); 112 return (-2);
113 return (X509_NAME_get_index_by_OBJ(name, obj, lastpos));
105} 114}
106 115
107/* NOTE: you should be passsing -1, not 0 as lastpos */ 116/* NOTE: you should be passsing -1, not 0 as lastpos */
108int X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, 117int
109 int lastpos) 118X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int lastpos)
110{ 119{
111 int n; 120 int n;
112 X509_NAME_ENTRY *ne; 121 X509_NAME_ENTRY *ne;
113 STACK_OF(X509_NAME_ENTRY) *sk; 122 STACK_OF(X509_NAME_ENTRY) *sk;
114 123
115 if (name == NULL) return(-1); 124 if (name == NULL)
125 return (-1);
116 if (lastpos < 0) 126 if (lastpos < 0)
117 lastpos= -1; 127 lastpos = -1;
118 sk=name->entries; 128 sk = name->entries;
119 n=sk_X509_NAME_ENTRY_num(sk); 129 n = sk_X509_NAME_ENTRY_num(sk);
120 for (lastpos++; lastpos < n; lastpos++) { 130 for (lastpos++; lastpos < n; lastpos++) {
121 ne=sk_X509_NAME_ENTRY_value(sk,lastpos); 131 ne = sk_X509_NAME_ENTRY_value(sk, lastpos);
122 if (OBJ_cmp(ne->object,obj) == 0) 132 if (OBJ_cmp(ne->object, obj) == 0)
123 return(lastpos); 133 return (lastpos);
124 } 134 }
125 return(-1); 135 return (-1);
126} 136}
127 137
128X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc) 138X509_NAME_ENTRY *
139X509_NAME_get_entry(X509_NAME *name, int loc)
129{ 140{
130 if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc 141 if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc ||
131 || loc < 0) 142 loc < 0)
132 return(NULL); 143 return (NULL);
133 else 144 else
134 return(sk_X509_NAME_ENTRY_value(name->entries,loc)); 145 return (sk_X509_NAME_ENTRY_value(name->entries, loc));
135} 146}
136 147
137X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc) 148X509_NAME_ENTRY *
149X509_NAME_delete_entry(X509_NAME *name, int loc)
138{ 150{
139 X509_NAME_ENTRY *ret; 151 X509_NAME_ENTRY *ret;
140 int i,n,set_prev,set_next; 152 int i, n, set_prev, set_next;
141 STACK_OF(X509_NAME_ENTRY) *sk; 153 STACK_OF(X509_NAME_ENTRY) *sk;
142 154
143 if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc 155 if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc ||
144 || loc < 0) 156 loc < 0)
145 return(NULL); 157 return (NULL);
146 sk=name->entries; 158 sk = name->entries;
147 ret=sk_X509_NAME_ENTRY_delete(sk,loc); 159 ret = sk_X509_NAME_ENTRY_delete(sk, loc);
148 n=sk_X509_NAME_ENTRY_num(sk); 160 n = sk_X509_NAME_ENTRY_num(sk);
149 name->modified=1; 161 name->modified = 1;
150 if (loc == n) return(ret); 162 if (loc == n)
163 return (ret);
151 164
152 /* else we need to fixup the set field */ 165 /* else we need to fixup the set field */
153 if (loc != 0) 166 if (loc != 0)
154 set_prev=(sk_X509_NAME_ENTRY_value(sk,loc-1))->set; 167 set_prev = (sk_X509_NAME_ENTRY_value(sk, loc - 1))->set;
155 else 168 else
156 set_prev=ret->set-1; 169 set_prev = ret->set - 1;
157 set_next=sk_X509_NAME_ENTRY_value(sk,loc)->set; 170 set_next = sk_X509_NAME_ENTRY_value(sk, loc)->set;
158 171
159 /* set_prev is the previous set 172 /* set_prev is the previous set
160 * set is the current set 173 * set is the current set
@@ -164,43 +177,52 @@ X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc)
164 * next 1 1 2 2 2 2 3 2 177 * next 1 1 2 2 2 2 3 2
165 * so basically only if prev and next differ by 2, then 178 * so basically only if prev and next differ by 2, then
166 * re-number down by 1 */ 179 * re-number down by 1 */
167 if (set_prev+1 < set_next) 180 if (set_prev + 1 < set_next)
168 for (i=loc; i<n; i++) 181 for (i = loc; i < n; i++)
169 sk_X509_NAME_ENTRY_value(sk,i)->set--; 182 sk_X509_NAME_ENTRY_value(sk, i)->set--;
170 return(ret); 183 return (ret);
171} 184}
172 185
173int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, 186int
174 unsigned char *bytes, int len, int loc, int set) 187X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
188 unsigned char *bytes, int len, int loc, int set)
175{ 189{
176 X509_NAME_ENTRY *ne; 190 X509_NAME_ENTRY *ne;
177 int ret; 191 int ret;
192
178 ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len); 193 ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len);
179 if(!ne) return 0; 194 if (!ne)
195 return 0;
180 ret = X509_NAME_add_entry(name, ne, loc, set); 196 ret = X509_NAME_add_entry(name, ne, loc, set);
181 X509_NAME_ENTRY_free(ne); 197 X509_NAME_ENTRY_free(ne);
182 return ret; 198 return ret;
183} 199}
184 200
185int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, 201int
186 unsigned char *bytes, int len, int loc, int set) 202X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
203 unsigned char *bytes, int len, int loc, int set)
187{ 204{
188 X509_NAME_ENTRY *ne; 205 X509_NAME_ENTRY *ne;
189 int ret; 206 int ret;
207
190 ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len); 208 ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len);
191 if(!ne) return 0; 209 if (!ne)
210 return 0;
192 ret = X509_NAME_add_entry(name, ne, loc, set); 211 ret = X509_NAME_add_entry(name, ne, loc, set);
193 X509_NAME_ENTRY_free(ne); 212 X509_NAME_ENTRY_free(ne);
194 return ret; 213 return ret;
195} 214}
196 215
197int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, 216int
198 const unsigned char *bytes, int len, int loc, int set) 217X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type,
218 const unsigned char *bytes, int len, int loc, int set)
199{ 219{
200 X509_NAME_ENTRY *ne; 220 X509_NAME_ENTRY *ne;
201 int ret; 221 int ret;
222
202 ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len); 223 ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len);
203 if(!ne) return 0; 224 if (!ne)
225 return 0;
204 ret = X509_NAME_add_entry(name, ne, loc, set); 226 ret = X509_NAME_add_entry(name, ne, loc, set);
205 X509_NAME_ENTRY_free(ne); 227 X509_NAME_ENTRY_free(ne);
206 return ret; 228 return ret;
@@ -208,159 +230,177 @@ int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type,
208 230
209/* if set is -1, append to previous set, 0 'a new one', and 1, 231/* if set is -1, append to previous set, 0 'a new one', and 1,
210 * prepend to the guy we are about to stomp on. */ 232 * prepend to the guy we are about to stomp on. */
211int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, 233int
212 int set) 234X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, int set)
213{ 235{
214 X509_NAME_ENTRY *new_name=NULL; 236 X509_NAME_ENTRY *new_name = NULL;
215 int n,i,inc; 237 int n, i, inc;
216 STACK_OF(X509_NAME_ENTRY) *sk; 238 STACK_OF(X509_NAME_ENTRY) *sk;
217 239
218 if (name == NULL) return(0); 240 if (name == NULL)
219 sk=name->entries; 241 return (0);
220 n=sk_X509_NAME_ENTRY_num(sk); 242 sk = name->entries;
221 if (loc > n) loc=n; 243 n = sk_X509_NAME_ENTRY_num(sk);
222 else if (loc < 0) loc=n; 244 if (loc > n)
245 loc = n;
246 else if (loc < 0)
247 loc = n;
223 248
224 name->modified=1; 249 name->modified = 1;
225 250
226 if (set == -1) { 251 if (set == -1) {
227 if (loc == 0) { 252 if (loc == 0) {
228 set=0; 253 set = 0;
229 inc=1; 254 inc = 1;
230 } else { 255 } else {
231 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set; 256 set = sk_X509_NAME_ENTRY_value(sk, loc - 1)->set;
232 inc=0; 257 inc = 0;
233 } 258 }
234 } else /* if (set >= 0) */ { 259 } else /* if (set >= 0) */ {
235 if (loc >= n) { 260 if (loc >= n) {
236 if (loc != 0) 261 if (loc != 0)
237 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set+1; 262 set = sk_X509_NAME_ENTRY_value(sk, loc - 1)->set + 1;
238 else 263 else
239 set=0; 264 set = 0;
240 } else 265 } else
241 set=sk_X509_NAME_ENTRY_value(sk,loc)->set; 266 set = sk_X509_NAME_ENTRY_value(sk, loc)->set;
242 inc=(set == 0)?1:0; 267 inc = (set == 0) ? 1 : 0;
243 } 268 }
244 269
245 if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL) 270 if ((new_name = X509_NAME_ENTRY_dup(ne)) == NULL)
246 goto err; 271 goto err;
247 new_name->set=set; 272 new_name->set = set;
248 if (!sk_X509_NAME_ENTRY_insert(sk,new_name,loc)) { 273 if (!sk_X509_NAME_ENTRY_insert(sk, new_name, loc)) {
249 X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE); 274 X509err(X509_F_X509_NAME_ADD_ENTRY, ERR_R_MALLOC_FAILURE);
250 goto err; 275 goto err;
251 } 276 }
252 if (inc) { 277 if (inc) {
253 n=sk_X509_NAME_ENTRY_num(sk); 278 n = sk_X509_NAME_ENTRY_num(sk);
254 for (i=loc+1; i<n; i++) 279 for (i = loc + 1; i < n; i++)
255 sk_X509_NAME_ENTRY_value(sk,i-1)->set+=1; 280 sk_X509_NAME_ENTRY_value(sk, i - 1)->set += 1;
256 } 281 }
257 return(1); 282 return (1);
283
258err: 284err:
259 if (new_name != NULL) 285 if (new_name != NULL)
260 X509_NAME_ENTRY_free(new_name); 286 X509_NAME_ENTRY_free(new_name);
261 return(0); 287 return (0);
262} 288}
263 289
264X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, 290X509_NAME_ENTRY *
265 const char *field, int type, const unsigned char *bytes, int len) 291X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
292 const char *field, int type, const unsigned char *bytes, int len)
266{ 293{
267 ASN1_OBJECT *obj; 294 ASN1_OBJECT *obj;
268 X509_NAME_ENTRY *nentry; 295 X509_NAME_ENTRY *nentry;
269 296
270 obj=OBJ_txt2obj(field, 0); 297 obj = OBJ_txt2obj(field, 0);
271 if (obj == NULL) { 298 if (obj == NULL) {
272 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT, 299 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT,
273 X509_R_INVALID_FIELD_NAME); 300 X509_R_INVALID_FIELD_NAME);
274 ERR_add_error_data(2, "name=", field); 301 ERR_add_error_data(2, "name=", field);
275 return(NULL); 302 return (NULL);
276 } 303 }
277 nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len); 304 nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len);
278 ASN1_OBJECT_free(obj); 305 ASN1_OBJECT_free(obj);
279 return nentry; 306 return nentry;
280} 307}
281 308
282X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, 309X509_NAME_ENTRY *
283 int type, unsigned char *bytes, int len) 310X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type,
311 unsigned char *bytes, int len)
284{ 312{
285 ASN1_OBJECT *obj; 313 ASN1_OBJECT *obj;
286 X509_NAME_ENTRY *nentry; 314 X509_NAME_ENTRY *nentry;
287 315
288 obj=OBJ_nid2obj(nid); 316 obj = OBJ_nid2obj(nid);
289 if (obj == NULL) { 317 if (obj == NULL) {
290 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID); 318 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,
291 return(NULL); 319 X509_R_UNKNOWN_NID);
320 return (NULL);
292 } 321 }
293 nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len); 322 nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len);
294 ASN1_OBJECT_free(obj); 323 ASN1_OBJECT_free(obj);
295 return nentry; 324 return nentry;
296} 325}
297 326
298X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, 327X509_NAME_ENTRY *
299 ASN1_OBJECT *obj, int type, const unsigned char *bytes, int len) 328X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type,
329 const unsigned char *bytes, int len)
300{ 330{
301 X509_NAME_ENTRY *ret; 331 X509_NAME_ENTRY *ret;
302 332
303 if ((ne == NULL) || (*ne == NULL)) { 333 if ((ne == NULL) || (*ne == NULL)) {
304 if ((ret=X509_NAME_ENTRY_new()) == NULL) 334 if ((ret = X509_NAME_ENTRY_new()) == NULL)
305 return(NULL); 335 return (NULL);
306 } else 336 } else
307 ret= *ne; 337 ret= *ne;
308 338
309 if (!X509_NAME_ENTRY_set_object(ret,obj)) 339 if (!X509_NAME_ENTRY_set_object(ret, obj))
310 goto err; 340 goto err;
311 if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len)) 341 if (!X509_NAME_ENTRY_set_data(ret, type, bytes, len))
312 goto err; 342 goto err;
313 343
314 if ((ne != NULL) && (*ne == NULL)) *ne=ret; 344 if ((ne != NULL) && (*ne == NULL))
315 return(ret); 345 *ne = ret;
346 return (ret);
347
316err: 348err:
317 if ((ne == NULL) || (ret != *ne)) 349 if ((ne == NULL) || (ret != *ne))
318 X509_NAME_ENTRY_free(ret); 350 X509_NAME_ENTRY_free(ret);
319 return(NULL); 351 return (NULL);
320} 352}
321 353
322int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj) 354int
355X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj)
323{ 356{
324 if ((ne == NULL) || (obj == NULL)) { 357 if ((ne == NULL) || (obj == NULL)) {
325 X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT,ERR_R_PASSED_NULL_PARAMETER); 358 X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT,
326 return(0); 359 ERR_R_PASSED_NULL_PARAMETER);
360 return (0);
327 } 361 }
328 ASN1_OBJECT_free(ne->object); 362 ASN1_OBJECT_free(ne->object);
329 ne->object=OBJ_dup(obj); 363 ne->object = OBJ_dup(obj);
330 return((ne->object == NULL)?0:1); 364 return ((ne->object == NULL) ? 0 : 1);
331} 365}
332 366
333int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, 367int
334 const unsigned char *bytes, int len) 368X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
369 const unsigned char *bytes, int len)
335{ 370{
336 int i; 371 int i;
337 372
338 if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0); 373 if ((ne == NULL) || ((bytes == NULL) && (len != 0)))
339 if((type > 0) && (type & MBSTRING_FLAG)) 374 return (0);
340 return ASN1_STRING_set_by_NID(&ne->value, bytes, 375 if ((type > 0) && (type & MBSTRING_FLAG))
341 len, type, 376 return ASN1_STRING_set_by_NID(&ne->value, bytes, len, type,
342 OBJ_obj2nid(ne->object)) ? 1 : 0; 377 OBJ_obj2nid(ne->object)) ? 1 : 0;
343 if (len < 0) len=strlen((const char *)bytes); 378 if (len < 0)
344 i=ASN1_STRING_set(ne->value,bytes,len); 379 len = strlen((const char *)bytes);
345 if (!i) return(0); 380 i = ASN1_STRING_set(ne->value, bytes, len);
381 if (!i)
382 return (0);
346 if (type != V_ASN1_UNDEF) { 383 if (type != V_ASN1_UNDEF) {
347 if (type == V_ASN1_APP_CHOOSE) 384 if (type == V_ASN1_APP_CHOOSE)
348 ne->value->type=ASN1_PRINTABLE_type(bytes,len); 385 ne->value->type = ASN1_PRINTABLE_type(bytes, len);
349 else 386 else
350 ne->value->type=type; 387 ne->value->type = type;
351 } 388 }
352 return(1); 389 return (1);
353} 390}
354 391
355ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne) 392ASN1_OBJECT *
393X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne)
356{ 394{
357 if (ne == NULL) return(NULL); 395 if (ne == NULL)
358 return(ne->object); 396 return (NULL);
397 return (ne->object);
359} 398}
360 399
361ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne) 400ASN1_STRING *
401X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
362{ 402{
363 if (ne == NULL) return(NULL); 403 if (ne == NULL)
364 return(ne->value); 404 return (NULL);
405 return (ne->value);
365} 406}
366