summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-12-14 14:33:23 +0000
committertb <>2023-12-14 14:33:23 +0000
commit07fa1e73aee5fb447a989d049037204d9e133fd0 (patch)
tree8541984938cad98db2747facfbf6fa46616f82ad /src
parent1960eee722991b72b4bf5afa5fd1227f30c59f02 (diff)
downloadopenbsd-07fa1e73aee5fb447a989d049037204d9e133fd0.tar.gz
openbsd-07fa1e73aee5fb447a989d049037204d9e133fd0.tar.bz2
openbsd-07fa1e73aee5fb447a989d049037204d9e133fd0.zip
Dedup OBJ_nid2{obj,sn,ln}()
First get the obj corresponding to nid, then inspect its sn and ln. Shaves off 40 lines of code and will simplify locking.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c58
1 files changed, 9 insertions, 49 deletions
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index 94841b4265..5a2c34278e 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: obj_dat.c,v 1.68 2023/12/14 14:04:46 tb Exp $ */ 1/* $OpenBSD: obj_dat.c,v 1.69 2023/12/14 14:33:23 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -313,64 +313,24 @@ LCRYPTO_ALIAS(OBJ_nid2obj);
313const char * 313const char *
314OBJ_nid2sn(int nid) 314OBJ_nid2sn(int nid)
315{ 315{
316 if (nid >= 0 && nid < NUM_NID) { 316 ASN1_OBJECT *aobj;
317 if (nid == NID_undef || nid_objs[nid].nid != NID_undef)
318 return nid_objs[nid].sn;
319
320 goto unknown;
321 }
322 317
323 /* XXX - locking. */ 318 if ((aobj = OBJ_nid2obj(nid)) == NULL)
324 if (added != NULL) { 319 return NULL;
325 ASN1_OBJECT aobj = {
326 .nid = nid,
327 };
328 ADDED_OBJ needle = {
329 .type = ADDED_NID,
330 .obj = &aobj,
331 };
332 ADDED_OBJ *found;
333
334 if ((found = lh_ADDED_OBJ_retrieve(added, &needle)) != NULL)
335 return found->obj->sn;
336 }
337
338 unknown:
339 OBJerror(OBJ_R_UNKNOWN_NID);
340 320
341 return NULL; 321 return aobj->sn;
342} 322}
343LCRYPTO_ALIAS(OBJ_nid2sn); 323LCRYPTO_ALIAS(OBJ_nid2sn);
344 324
345const char * 325const char *
346OBJ_nid2ln(int nid) 326OBJ_nid2ln(int nid)
347{ 327{
348 if (nid >= 0 && nid < NUM_NID) { 328 ASN1_OBJECT *aobj;
349 if (nid == NID_undef || nid_objs[nid].nid != NID_undef)
350 return nid_objs[nid].ln;
351
352 goto unknown;
353 }
354 329
355 /* XXX - locking. */ 330 if ((aobj = OBJ_nid2obj(nid)) == NULL)
356 if (added != NULL) { 331 return NULL;
357 ASN1_OBJECT aobj = {
358 .nid = nid,
359 };
360 ADDED_OBJ needle = {
361 .type = ADDED_NID,
362 .obj = &aobj,
363 };
364 ADDED_OBJ *found;
365
366 if ((found = lh_ADDED_OBJ_retrieve(added, &needle)) != NULL)
367 return found->obj->ln;
368 }
369
370 unknown:
371 OBJerror(OBJ_R_UNKNOWN_NID);
372 332
373 return NULL; 333 return aobj->ln;
374} 334}
375LCRYPTO_ALIAS(OBJ_nid2ln); 335LCRYPTO_ALIAS(OBJ_nid2ln);
376 336