summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2023-12-14 14:04:47 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2023-12-14 14:04:47 +0000
commit2dad2285a5107fafe69e2925a03cb6fb49b1ffae (patch)
treed733ada394a7308e9a5aecca7125f826c125030f
parentac1729c4e7b13588635f67bda7028703e53df5a0 (diff)
Simplify OBJ_nid2obj()
This is now yet another identical copy of the same code... Next step will be to dedup. ok jsing
-rw-r--r--lib/libcrypto/objects/obj_dat.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/lib/libcrypto/objects/obj_dat.c b/lib/libcrypto/objects/obj_dat.c
index 336673aefef..94841b42651 100644
--- a/lib/libcrypto/objects/obj_dat.c
+++ b/lib/libcrypto/objects/obj_dat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: obj_dat.c,v 1.67 2023/12/14 14:02:57 tb Exp $ */
+/* $OpenBSD: obj_dat.c,v 1.68 2023/12/14 14:04:46 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -279,31 +279,34 @@ OBJ_add_object(const ASN1_OBJECT *obj)
LCRYPTO_ALIAS(OBJ_add_object);
ASN1_OBJECT *
-OBJ_nid2obj(int n)
+OBJ_nid2obj(int nid)
{
- ADDED_OBJ ad, *adp;
- ASN1_OBJECT ob;
+ if (nid >= 0 && nid < NUM_NID) {
+ if (nid == NID_undef || nid_objs[nid].nid != NID_undef)
+ return (ASN1_OBJECT *)&nid_objs[nid];
- if ((n >= 0) && (n < NUM_NID)) {
- if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
- OBJerror(OBJ_R_UNKNOWN_NID);
- return (NULL);
- }
- return ((ASN1_OBJECT *)&(nid_objs[n]));
- } else if (added == NULL)
- return (NULL);
- else {
- ad.type = ADDED_NID;
- ad.obj = &ob;
- ob.nid = n;
- adp = lh_ADDED_OBJ_retrieve(added, &ad);
- if (adp != NULL)
- return (adp->obj);
- else {
- OBJerror(OBJ_R_UNKNOWN_NID);
- return (NULL);
- }
+ goto unknown;
}
+
+ /* XXX - locking. */
+ if (added != NULL) {
+ ASN1_OBJECT aobj = {
+ .nid = nid,
+ };
+ ADDED_OBJ needle = {
+ .type = ADDED_NID,
+ .obj = &aobj,
+ };
+ ADDED_OBJ *found;
+
+ if ((found = lh_ADDED_OBJ_retrieve(added, &needle)) != NULL)
+ return found->obj;
+ }
+
+ unknown:
+ OBJerror(OBJ_R_UNKNOWN_NID);
+
+ return NULL;
}
LCRYPTO_ALIAS(OBJ_nid2obj);