OBJ_nid2obj(3) OpenSSL OBJ_nid2obj(3) NNAAMMEE OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid, OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup - ASN1 object utility functions SSYYNNOOPPSSIISS #include ASN1_OBJECT * OBJ_nid2obj(int n); const char * OBJ_nid2ln(int n); const char * OBJ_nid2sn(int n); int OBJ_obj2nid(const ASN1_OBJECT *o); int OBJ_ln2nid(const char *ln); int OBJ_sn2nid(const char *sn); int OBJ_txt2nid(const char *s); ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name); int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name); int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b); ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o); int OBJ_create(const char *oid,const char *sn,const char *ln); void OBJ_cleanup(void); DDEESSCCRRIIPPTTIIOONN The ASN1 object utility functions process ASN1_OBJECT structures which are a representation of the ASN1 OBJECT IDENTIFIER (OID) type. _O_B_J___n_i_d_2_o_b_j_(_), _O_B_J___n_i_d_2_l_n_(_) and _O_B_J___n_i_d_2_s_n_(_) convert the NID nn to an ASN1_OBJECT structure, its long name and its short name respectively, or NNUULLLL is an error occurred. _O_B_J___o_b_j_2_n_i_d_(_), _O_B_J___l_n_2_n_i_d_(_), _O_B_J___s_n_2_n_i_d_(_) return the corresponding NID for the object oo, the long name or the short name respec- tively or NID_undef if an error occurred. _O_B_J___t_x_t_2_n_i_d_(_) returns NID corresponding to text string . ss can be a long name, a short name or the numerical respresentation of an object. _O_B_J___t_x_t_2_o_b_j_(_) converts the text string ss into an ASN1_OBJECT structure. If nnoo__nnaammee is 0 then long names and short names will be interpreted as well as numerical forms. If nnoo__nnaammee is 1 only the numerical form is acceptable. _O_B_J___o_b_j_2_t_x_t_(_) converts the AASSNN11__OOBBJJEECCTT aa into a textual representation. The representation is written as a null terminated string to bbuuff at most bbuuff__lleenn bytes are written, truncating the result if necessary. The total amount of space required is returned. If nnoo__nnaammee is 0 then if the object has a long or short name then that will be used, otherwise the numerical form will be used. If nnoo__nnaammee is 1 then the numerical form will always be used. _O_B_J___c_m_p_(_) compares aa to bb. If the two are identical 0 is returned. _O_B_J___d_u_p_(_) returns a copy of oo. _O_B_J___c_r_e_a_t_e_(_) adds a new object to the internal table. ooiidd is the numer- ical form of the object, ssnn the short name and llnn the long name. A new NID is returned for the created object. _O_B_J___c_l_e_a_n_u_p_(_) cleans up OpenSSLs internal object table: this should be called before an application exits if any new objects were added using _O_B_J___c_r_e_a_t_e_(_). NNOOTTEESS Objects in OpenSSL can have a short name, a long name and a numerical identifier (NID) associated with them. A standard set of objects is represented in an internal table. The appropriate values are defined in the header file oobbjjeeccttss..hh. For example the OID for commonName has the following definitions: #define SN_commonName "CN" #define LN_commonName "commonName" #define NID_commonName 13 New objects can be added by calling _O_B_J___c_r_e_a_t_e_(_). Table objects have certain advantages over other objects: for example their NIDs can be used in a C language switch statement. They are also static constant structures which are shared: that is there is only a single constant structure for each table object. Objects which are not in the table have the NID value NID_undef. Objects do not need to be in the internal tables to be processed, the functions _O_B_J___t_x_t_2_o_b_j_(_) and _O_B_J___o_b_j_2_t_x_t_(_) can process the numerical form of an OID. EEXXAAMMPPLLEESS Create an object for ccoommmmoonnNNaammee: ASN1_OBJECT *o; o = OBJ_nid2obj(NID_commonName); Check if an object is ccoommmmoonnNNaammee if (OBJ_obj2nid(obj) == NID_commonName) /* Do something */ Create a new NID and initialize an object from it: int new_nid; ASN1_OBJECT *obj; new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier"); obj = OBJ_nid2obj(new_nid); Create a new object directly: obj = OBJ_txt2obj("1.2.3.4", 1); BBUUGGSS _O_B_J___o_b_j_2_t_x_t_(_) is awkward and messy to use: it doesn't follow the con- vention of other OpenSSL functions where the buffer can be set to NNUULLLL to determine the amount of data that should be written. Instead bbuuff must point to a valid buffer and bbuuff__lleenn should be set to a positive value. A buffer length of 80 should be more than enough to handle any OID encountered in practice. RREETTUURRNN VVAALLUUEESS _O_B_J___n_i_d_2_o_b_j_(_) returns an AASSNN11__OOBBJJEECCTT structure or NNUULLLL is an error occurred. _O_B_J___n_i_d_2_l_n_(_) and _O_B_J___n_i_d_2_s_n_(_) returns a valid string or NNUULLLL on error. _O_B_J___o_b_j_2_n_i_d_(_), _O_B_J___l_n_2_n_i_d_(_), _O_B_J___s_n_2_n_i_d_(_) and _O_B_J___t_x_t_2_n_i_d_(_) return a NID or NNIIDD__uunnddeeff on error. SSEEEE AALLSSOO _E_R_R___g_e_t___e_r_r_o_r(3) HHIISSTTOORRYY TBA 1.0.1u 2016-09-22 OBJ_nid2obj(3)