int OBJ_create(const char *oid, const char *sn, const char *ln) { int ok=0; ASN1_OBJECT *op=NULL; unsigned char *buf; int i; i=a2d_ASN1_OBJECT(NULL,0,oid,-1); if (i <= 0) return(0); if ((buf=(unsigned char *)OPENSSL_malloc(i)) == NULL) { OBJerr(OBJ_F_OBJ_CREATE,ERR_R_MALLOC_FAILURE); return(0); } i=a2d_ASN1_OBJECT(buf,i,oid,-1); if (i == 0) goto err; op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln); if (op == NULL) goto err; ok=OBJ_add_object(op); err: ASN1_OBJECT_free(op); OPENSSL_free(buf); return(ok); }
static void *construct_method(const char *algorithm_name, const OSSL_DISPATCH *fns, OSSL_PROVIDER *prov, void *data) { struct method_data_st *methdata = data; void *method = NULL; int nid = OBJ_sn2nid(algorithm_name); if (nid == NID_undef) { /* Create a new NID for that name on the fly */ ASN1_OBJECT tmpobj; /* This is the same as OBJ_create() but without requiring a OID */ tmpobj.nid = OBJ_new_nid(1); tmpobj.sn = tmpobj.ln = methdata->name; tmpobj.flags = ASN1_OBJECT_FLAG_DYNAMIC; tmpobj.length = 0; tmpobj.data = NULL; nid = OBJ_add_object(&tmpobj); } if (nid == NID_undef) return NULL; method = methdata->method_from_dispatch(nid, fns, prov); if (method == NULL) return NULL; return method; }
/* Create a new NID when we have no OID for that mechanism */ static int t4_add_NID(char *sn, char *ln) { ASN1_OBJECT *o; int nid; if ((o = ASN1_OBJECT_create(OBJ_new_nid(1), (unsigned char *)"", 1, sn, ln)) == NULL) { T4err(T4_F_ADD_NID, T4_R_ASN1_OBJECT_CREATE); return (0); } /* Will return NID_undef on error */ nid = OBJ_add_object(o); ASN1_OBJECT_free(o); return (nid); }