OBJ_nid2obj.pod 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. =pod
  2. =head1 NAME
  3. OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid,
  4. OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup - ASN1 object utility
  5. functions
  6. =head1 SYNOPSIS
  7. #include <openssl/objects.h>
  8. ASN1_OBJECT * OBJ_nid2obj(int n);
  9. const char * OBJ_nid2ln(int n);
  10. const char * OBJ_nid2sn(int n);
  11. int OBJ_obj2nid(const ASN1_OBJECT *o);
  12. int OBJ_ln2nid(const char *ln);
  13. int OBJ_sn2nid(const char *sn);
  14. int OBJ_txt2nid(const char *s);
  15. ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
  16. int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
  17. int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
  18. ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
  19. int OBJ_create(const char *oid,const char *sn,const char *ln);
  20. void OBJ_cleanup(void);
  21. =head1 DESCRIPTION
  22. The ASN1 object utility functions process ASN1_OBJECT structures which are
  23. a representation of the ASN1 OBJECT IDENTIFIER (OID) type.
  24. For convenience, OIDs are usually represented in source code as numeric
  25. identifiers, or B<NID>s. OpenSSL has an internal table of OIDs that
  26. are generated when the library is built, and their corresponding NIDs
  27. are available as defined constants. For the functions below, application
  28. code should treat all returned values -- OIDs, NIDs, or names -- as
  29. constants.
  30. OBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID B<n> to
  31. an ASN1_OBJECT structure, its long name and its short name respectively,
  32. or B<NULL> is an error occurred.
  33. OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID
  34. for the object B<o>, the long name <ln> or the short name <sn> respectively
  35. or NID_undef if an error occurred.
  36. OBJ_txt2nid() returns NID corresponding to text string <s>. B<s> can be
  37. a long name, a short name or the numerical respresentation of an object.
  38. OBJ_txt2obj() converts the text string B<s> into an ASN1_OBJECT structure.
  39. If B<no_name> is 0 then long names and short names will be interpreted
  40. as well as numerical forms. If B<no_name> is 1 only the numerical form
  41. is acceptable.
  42. OBJ_obj2txt() converts the B<ASN1_OBJECT> B<a> into a textual representation.
  43. The representation is written as a null terminated string to B<buf>
  44. at most B<buf_len> bytes are written, truncating the result if necessary.
  45. The total amount of space required is returned. If B<no_name> is 0 then
  46. if the object has a long or short name then that will be used, otherwise
  47. the numerical form will be used. If B<no_name> is 1 then the numerical
  48. form will always be used.
  49. OBJ_cmp() compares B<a> to B<b>. If the two are identical 0 is returned.
  50. OBJ_dup() returns a copy of B<o>.
  51. OBJ_create() adds a new object to the internal table. B<oid> is the
  52. numerical form of the object, B<sn> the short name and B<ln> the
  53. long name. A new NID is returned for the created object.
  54. OBJ_cleanup() cleans up OpenSSLs internal object table: this should
  55. be called before an application exits if any new objects were added
  56. using OBJ_create().
  57. =head1 NOTES
  58. Objects in OpenSSL can have a short name, a long name and a numerical
  59. identifier (NID) associated with them. A standard set of objects is
  60. represented in an internal table. The appropriate values are defined
  61. in the header file B<objects.h>.
  62. For example the OID for commonName has the following definitions:
  63. #define SN_commonName "CN"
  64. #define LN_commonName "commonName"
  65. #define NID_commonName 13
  66. New objects can be added by calling OBJ_create().
  67. Table objects have certain advantages over other objects: for example
  68. their NIDs can be used in a C language switch statement. They are
  69. also static constant structures which are shared: that is there
  70. is only a single constant structure for each table object.
  71. Objects which are not in the table have the NID value NID_undef.
  72. Objects do not need to be in the internal tables to be processed,
  73. the functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
  74. form of an OID.
  75. Some objects are used to represent algorithms which do not have a
  76. corresponding ASN.1 OBJECT IDENTIFIER encoding (for example no OID currently
  77. exists for a particular algorithm). As a result they B<cannot> be encoded or
  78. decoded as part of ASN.1 structures. Applications can determine if there
  79. is a corresponding OBJECT IDENTIFIER by checking OBJ_length() is not zero.
  80. These functions cannot return B<const> because an B<ASN1_OBJECT> can
  81. represent both an internal, constant, OID and a dynamically-created one.
  82. The latter cannot be constant because it needs to be freed after use.
  83. =head1 EXAMPLES
  84. Create an object for B<commonName>:
  85. ASN1_OBJECT *o;
  86. o = OBJ_nid2obj(NID_commonName);
  87. Check if an object is B<commonName>
  88. if (OBJ_obj2nid(obj) == NID_commonName)
  89. /* Do something */
  90. Create a new NID and initialize an object from it:
  91. int new_nid;
  92. ASN1_OBJECT *obj;
  93. new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
  94. obj = OBJ_nid2obj(new_nid);
  95. Create a new object directly:
  96. obj = OBJ_txt2obj("1.2.3.4", 1);
  97. =head1 BUGS
  98. OBJ_obj2txt() is awkward and messy to use: it doesn't follow the
  99. convention of other OpenSSL functions where the buffer can be set
  100. to B<NULL> to determine the amount of data that should be written.
  101. Instead B<buf> must point to a valid buffer and B<buf_len> should
  102. be set to a positive value. A buffer length of 80 should be more
  103. than enough to handle any OID encountered in practice.
  104. =head1 RETURN VALUES
  105. OBJ_nid2obj() returns an B<ASN1_OBJECT> structure or B<NULL> is an
  106. error occurred.
  107. It returns a pointer to an internal table and does not
  108. allocate memory; ASN1_OBJECT_free() will have no effect.
  109. OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or B<NULL>
  110. on error.
  111. OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return
  112. a NID or B<NID_undef> on error.
  113. =head1 SEE ALSO
  114. L<ERR_get_error(3)|ERR_get_error(3)>
  115. =head1 HISTORY
  116. TBA
  117. =cut