diff options
| author | schwarze <> | 2023-09-05 13:50:22 +0000 |
|---|---|---|
| committer | schwarze <> | 2023-09-05 13:50:22 +0000 |
| commit | c35e7737d63cdb4c5739ac2b93f4c792dbb20d6e (patch) | |
| tree | 25e6bcfc3b4d16fc849914ae43946ea38f4f88d8 /src/lib/libc | |
| parent | 5bb5b247d4771880865de4eb2d298b7074785ebb (diff) | |
| download | openbsd-c35e7737d63cdb4c5739ac2b93f4c792dbb20d6e.tar.gz openbsd-c35e7737d63cdb4c5739ac2b93f4c792dbb20d6e.tar.bz2 openbsd-c35e7737d63cdb4c5739ac2b93f4c792dbb20d6e.zip | |
Partial rewrite:
* Integrate the leftovers of the former NOTES section into the main text,
resulting in a more logical order of information.
* Make many descriptions more precise and tweak many wordings.
For example, the description of OBJ_cmp(3) was totally misleading.
Add a CAVEATS section explaining the scary ownership contracts
of the functions returning ASN1_OBJECT pointers.
Move the discussion of NID_undef to the BUGS section because the
statement "objects which are not in the table have the NID value
NID_undef" was misleading in more than one way.
Considering that an API as fundamental as this one contains such a
gigantic amount of quirks and traps and gaps makes me shudder.
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/man/OBJ_nid2obj.3 | 371 |
1 files changed, 231 insertions, 140 deletions
diff --git a/src/lib/libcrypto/man/OBJ_nid2obj.3 b/src/lib/libcrypto/man/OBJ_nid2obj.3 index 62d67ac740..4e420b8311 100644 --- a/src/lib/libcrypto/man/OBJ_nid2obj.3 +++ b/src/lib/libcrypto/man/OBJ_nid2obj.3 | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | .\" $OpenBSD: OBJ_nid2obj.3,v 1.20 2023/07/21 05:02:53 tb Exp $ | 1 | .\" $OpenBSD: OBJ_nid2obj.3,v 1.21 2023/09/05 13:50:22 schwarze Exp $ |
| 2 | .\" full merge up to: OpenSSL c264592d May 14 11:28:00 2006 +0000 | 2 | .\" full merge up to: OpenSSL c264592d May 14 11:28:00 2006 +0000 |
| 3 | .\" selective merge up to: OpenSSL 35fd9953 May 28 14:49:38 2019 +0200 | 3 | .\" selective merge up to: OpenSSL 35fd9953 May 28 14:49:38 2019 +0200 |
| 4 | .\" | 4 | .\" |
| 5 | .\" This file is a derived work. | 5 | .\" This file is a derived work. |
| 6 | .\" The changes are covered by the following Copyright and license: | 6 | .\" The changes are covered by the following Copyright and license: |
| 7 | .\" | 7 | .\" |
| 8 | .\" Copyright (c) 2017, 2021 Ingo Schwarze <schwarze@openbsd.org> | 8 | .\" Copyright (c) 2017, 2021, 2023 Ingo Schwarze <schwarze@openbsd.org> |
| 9 | .\" | 9 | .\" |
| 10 | .\" Permission to use, copy, modify, and distribute this software for any | 10 | .\" Permission to use, copy, modify, and distribute this software for any |
| 11 | .\" purpose with or without fee is hereby granted, provided that the above | 11 | .\" purpose with or without fee is hereby granted, provided that the above |
| @@ -67,7 +67,7 @@ | |||
| 67 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 67 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 68 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | 68 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. |
| 69 | .\" | 69 | .\" |
| 70 | .Dd $Mdocdate: July 21 2023 $ | 70 | .Dd $Mdocdate: September 5 2023 $ |
| 71 | .Dt OBJ_NID2OBJ 3 | 71 | .Dt OBJ_NID2OBJ 3 |
| 72 | .Os | 72 | .Os |
| 73 | .Sh NAME | 73 | .Sh NAME |
| @@ -89,19 +89,19 @@ | |||
| 89 | .In openssl/objects.h | 89 | .In openssl/objects.h |
| 90 | .Ft ASN1_OBJECT * | 90 | .Ft ASN1_OBJECT * |
| 91 | .Fo OBJ_nid2obj | 91 | .Fo OBJ_nid2obj |
| 92 | .Fa "int n" | 92 | .Fa "int nid" |
| 93 | .Fc | 93 | .Fc |
| 94 | .Ft const char * | 94 | .Ft const char * |
| 95 | .Fo OBJ_nid2ln | 95 | .Fo OBJ_nid2ln |
| 96 | .Fa "int n" | 96 | .Fa "int nid" |
| 97 | .Fc | 97 | .Fc |
| 98 | .Ft const char * | 98 | .Ft const char * |
| 99 | .Fo OBJ_nid2sn | 99 | .Fo OBJ_nid2sn |
| 100 | .Fa "int n" | 100 | .Fa "int nid" |
| 101 | .Fc | 101 | .Fc |
| 102 | .Ft int | 102 | .Ft int |
| 103 | .Fo OBJ_obj2nid | 103 | .Fo OBJ_obj2nid |
| 104 | .Fa "const ASN1_OBJECT *o" | 104 | .Fa "const ASN1_OBJECT *object" |
| 105 | .Fc | 105 | .Fc |
| 106 | .Ft int | 106 | .Ft int |
| 107 | .Fo OBJ_ln2nid | 107 | .Fo OBJ_ln2nid |
| @@ -124,7 +124,7 @@ | |||
| 124 | .Fo OBJ_obj2txt | 124 | .Fo OBJ_obj2txt |
| 125 | .Fa "char *buf" | 125 | .Fa "char *buf" |
| 126 | .Fa "int buf_len" | 126 | .Fa "int buf_len" |
| 127 | .Fa "const ASN1_OBJECT *a" | 127 | .Fa "const ASN1_OBJECT *object" |
| 128 | .Fa "int no_name" | 128 | .Fa "int no_name" |
| 129 | .Fc | 129 | .Fc |
| 130 | .Ft int | 130 | .Ft int |
| @@ -134,86 +134,102 @@ | |||
| 134 | .Fc | 134 | .Fc |
| 135 | .Ft ASN1_OBJECT * | 135 | .Ft ASN1_OBJECT * |
| 136 | .Fo OBJ_dup | 136 | .Fo OBJ_dup |
| 137 | .Fa "const ASN1_OBJECT *o" | 137 | .Fa "const ASN1_OBJECT *object" |
| 138 | .Fc | 138 | .Fc |
| 139 | .In openssl/asn1.h | 139 | .In openssl/asn1.h |
| 140 | .Ft int | 140 | .Ft int |
| 141 | .Fo i2t_ASN1_OBJECT | 141 | .Fo i2t_ASN1_OBJECT |
| 142 | .Fa "char *buf" | 142 | .Fa "char *buf" |
| 143 | .Fa "int buf_len" | 143 | .Fa "int buf_len" |
| 144 | .Fa "const ASN1_OBJECT *a" | 144 | .Fa "const ASN1_OBJECT *object" |
| 145 | .Fc | 145 | .Fc |
| 146 | .Ft int | 146 | .Ft int |
| 147 | .Fo i2a_ASN1_OBJECT | 147 | .Fo i2a_ASN1_OBJECT |
| 148 | .Fa "BIO *out_bio" | 148 | .Fa "BIO *out_bio" |
| 149 | .Fa "const ASN1_OBJECT *a" | 149 | .Fa "const ASN1_OBJECT *object" |
| 150 | .Fc | 150 | .Fc |
| 151 | .Sh DESCRIPTION | 151 | .Sh DESCRIPTION |
| 152 | The ASN.1 object utility functions process | 152 | The ASN.1 object utility functions process |
| 153 | .Vt ASN1_OBJECT | 153 | .Vt ASN1_OBJECT |
| 154 | structures which are a representation of the ASN.1 OBJECT IDENTIFIER | 154 | structures, in the following called |
| 155 | (OID) type. | 155 | .Dq objects . |
| 156 | For convenience, OIDs are usually represented in source code as | 156 | An object represents an ASN.1 |
| 157 | numeric identifiers, or NIDs. | 157 | .Vt OBJECT IDENTIFIER |
| 158 | OpenSSL has an internal table of OIDs that are generated when the | 158 | .Pq OID . |
| 159 | library is built, and their corresponding NIDs are available as | 159 | The library maintains an internal global table of objects. |
| 160 | defined constants. | 160 | Many of these objects are built into the library |
| 161 | For the functions below, application code should treat all returned | 161 | and contained in the global table by default. |
| 162 | values \(em OIDs, NIDs, or names \(em as constants. | 162 | The application program can add additional objects to the global table |
| 163 | by using functions documented in the | ||
| 164 | .Xr OBJ_create 3 | ||
| 165 | manual page. | ||
| 166 | Consequently, there are three classes of objects: | ||
| 167 | built-in table objects, user-defined table objects, and non-table objects. | ||
| 163 | .Pp | 168 | .Pp |
| 164 | .Fn OBJ_nid2obj , | 169 | In addition to the OID, each object can hold |
| 165 | .Fn OBJ_nid2ln , | 170 | a long name, a short name, and a numerical identifier (NID). |
| 171 | Even though the concept of NIDs is specific to the library | ||
| 172 | and not standardized, using the NID is often the most convenient way | ||
| 173 | for source code to refer to a specific OID. | ||
| 174 | The NIDs of the built-in objects are available as defined constants. | ||
| 175 | .Pp | ||
| 176 | Built-in table objects have certain advantages | ||
| 177 | over objects that are not in the global table: | ||
| 178 | for example, their NIDs can be used in C language switch statements. | ||
| 179 | They are also shared: | ||
| 180 | there is only a single static constant structure for each built-on OID. | ||
| 181 | .Pp | ||
| 182 | Some functions operate on table objects only: | ||
| 183 | .Pp | ||
| 184 | .Fn OBJ_nid2obj | ||
| 185 | retrieves the table object associated with the | ||
| 186 | .Fa nid . | ||
| 187 | .Fn OBJ_nid2ln | ||
| 166 | and | 188 | and |
| 167 | .Fn OBJ_nid2sn | 189 | .Fn OBJ_nid2sn |
| 168 | convert the NID | 190 | retrieve its long and short name, respectively. |
| 169 | .Fa n | ||
| 170 | to an | ||
| 171 | .Vt ASN1_OBJECT | ||
| 172 | structure, its long name, and its short name, respectively, or return | ||
| 173 | .Dv NULL | ||
| 174 | if an error occurred. | ||
| 175 | .Pp | 191 | .Pp |
| 176 | .Fn OBJ_obj2nid , | 192 | .Fn OBJ_obj2nid |
| 177 | .Fn OBJ_ln2nid , | 193 | retrieves the NID associated with the given |
| 194 | .Fa object , | ||
| 195 | which is either the NID stored in the | ||
| 196 | .Fa object | ||
| 197 | itself, if any, or otherwise the NID stored in a table object | ||
| 198 | containing the same OID. | ||
| 199 | .Pp | ||
| 200 | .Fn OBJ_ln2nid | ||
| 178 | and | 201 | and |
| 179 | .Fn OBJ_sn2nid | 202 | .Fn OBJ_sn2nid |
| 180 | return the corresponding NID for the object | 203 | retrieve the NID from the table object with the long name |
| 181 | .Fa o , | 204 | .Fa ln |
| 182 | the long name | ||
| 183 | .Fa ln , | ||
| 184 | or the short name | 205 | or the short name |
| 185 | .Fa sn , | 206 | .Fa sn , |
| 186 | respectively, or | 207 | respectively. |
| 187 | .Dv NID_undef | ||
| 188 | if an error occurred. | ||
| 189 | .Pp | 208 | .Pp |
| 190 | .Fn OBJ_txt2nid | 209 | .Fn OBJ_txt2nid |
| 191 | returns the NID corresponding to text string | 210 | retrieves the NID from the table object described by the text string |
| 192 | .Fa s . | 211 | .Fa s , |
| 193 | .Fa s | 212 | which can be a long name, a short name, |
| 194 | can be a long name, a short name, or the numerical representation | 213 | or the numerical representation of an OID. |
| 195 | of an object. | 214 | .Pp |
| 215 | The remaining functions can be used both on table objects | ||
| 216 | and on objects that are not in the global table: | ||
| 196 | .Pp | 217 | .Pp |
| 197 | .Fn OBJ_txt2obj | 218 | .Fn OBJ_txt2obj |
| 198 | converts the text string | 219 | retrieves or creates an object matching the text string |
| 199 | .Fa s | 220 | .Fa s . |
| 200 | into an | ||
| 201 | .Vt ASN1_OBJECT | ||
| 202 | structure. | ||
| 203 | If | 221 | If |
| 204 | .Fa no_name | 222 | .Fa no_name |
| 205 | is 0 then long names and short names will be interpreted as well as | 223 | is 1, only the numerical representation of an OID is accepted. |
| 206 | numerical forms. | ||
| 207 | If | 224 | If |
| 208 | .Fa no_name | 225 | .Fa no_name |
| 209 | is 1, only the numerical form is acceptable. | 226 | is 0, long names and short names are accepted as well. |
| 210 | .Pp | 227 | .Pp |
| 211 | .Fn OBJ_obj2txt | 228 | .Fn OBJ_obj2txt |
| 212 | converts the | 229 | writes a NUL terminated textual representation |
| 213 | .Vt ASN1_OBJECT | 230 | of the OID contained in the given |
| 214 | .Fa a | 231 | .Fa object |
| 215 | into a textual representation. | 232 | into |
| 216 | The representation is written as a NUL terminated string to | ||
| 217 | .Fa buf . | 233 | .Fa buf . |
| 218 | At most | 234 | At most |
| 219 | .Fa buf_len | 235 | .Fa buf_len |
| @@ -221,8 +237,13 @@ bytes are written, truncating the result if necessary. | |||
| 221 | The total amount of space required is returned. | 237 | The total amount of space required is returned. |
| 222 | If | 238 | If |
| 223 | .Fa no_name | 239 | .Fa no_name |
| 224 | is 0 and the object has a long or short name, then that will be used, | 240 | is 0 and the table object containing the same OID |
| 225 | otherwise the numerical form will be used. | 241 | contains a long name, the long name is written. |
| 242 | Otherwise, if | ||
| 243 | .Fa no_name | ||
| 244 | is 0 and the table object containing the same OID | ||
| 245 | contains a short name, the short name is written. | ||
| 246 | Otherwise, the numerical representation of the OID is written. | ||
| 226 | .Pp | 247 | .Pp |
| 227 | .Fn i2t_ASN1_OBJECT | 248 | .Fn i2t_ASN1_OBJECT |
| 228 | is the same as | 249 | is the same as |
| @@ -232,18 +253,18 @@ with | |||
| 232 | set to 0. | 253 | set to 0. |
| 233 | .Pp | 254 | .Pp |
| 234 | .Fn i2a_ASN1_OBJECT | 255 | .Fn i2a_ASN1_OBJECT |
| 235 | writes a textual representation of | 256 | writes a textual representation of the OID contained in the given |
| 236 | .Fa a | 257 | .Fa object |
| 237 | to | 258 | to |
| 238 | .Fa out_bio | 259 | .Fa out_bio |
| 239 | using | 260 | using |
| 240 | .Xr BIO_write 3 . | 261 | .Xr BIO_write 3 . |
| 241 | It does not write a terminating NUL byte. | 262 | It does not write a terminating NUL byte. |
| 242 | If | 263 | If the |
| 243 | .Fa a | 264 | .Fa object |
| 244 | is | 265 | argument is |
| 245 | .Dv NULL | 266 | .Dv NULL |
| 246 | or contains no data, it writes the 4-byte string | 267 | or contains no OID, it writes the 4-byte string |
| 247 | .Qq NULL . | 268 | .Qq NULL . |
| 248 | If | 269 | If |
| 249 | .Fn i2t_ASN1_OBJECT | 270 | .Fn i2t_ASN1_OBJECT |
| @@ -255,104 +276,129 @@ Otherwise, it writes the string constructed with | |||
| 255 | .Fn i2t_ASN1_OBJECT . | 276 | .Fn i2t_ASN1_OBJECT . |
| 256 | .Pp | 277 | .Pp |
| 257 | .Fn OBJ_cmp | 278 | .Fn OBJ_cmp |
| 258 | compares | 279 | tests whether |
| 259 | .Fa a | 280 | .Fa a |
| 260 | to | 281 | and |
| 261 | .Fa b . | 282 | .Fa b |
| 262 | If the two are identical, 0 is returned. | 283 | represent the same ASN.1 |
| 284 | .Vt OBJECT IDENTIFIER . | ||
| 285 | Any names and NIDs contained in the two objects are ignored, | ||
| 286 | even if they differ between both objects. | ||
| 263 | .Pp | 287 | .Pp |
| 264 | .Fn OBJ_dup | 288 | .Fn OBJ_dup |
| 265 | returns a deep copy of | 289 | returns a deep copy of the given |
| 266 | .Fa o | 290 | .Fa object |
| 267 | if | 291 | if it is marked as dynamically allocated. |
| 268 | .Fa o | 292 | The new object and all data contained in it are marked as dynamically |
| 269 | is marked as dynamically allocated. | ||
| 270 | The new object and all data contained in it is marked as dynamically | ||
| 271 | allocated. | 293 | allocated. |
| 272 | If | 294 | If the given |
| 273 | .Fa o | 295 | .Fa object |
| 274 | is not marked as dynamically allocated, | 296 | is not marked as dynamically allocated, |
| 275 | .Fn OBJ_dup | 297 | .Fn OBJ_dup |
| 276 | just returns | 298 | just returns a pointer to the |
| 277 | .Fa o | 299 | .Fa object |
| 278 | itself. | 300 | itself. |
| 279 | .Pp | ||
| 280 | Objects can have a short name, a long name, and a numerical | ||
| 281 | identifier (NID) associated with them. | ||
| 282 | A standard set of objects is represented in an internal table. | ||
| 283 | The appropriate values are defined in the header file | ||
| 284 | .In openssl/objects.h . | ||
| 285 | .Pp | ||
| 286 | For example, the OID for commonName has the following definitions: | ||
| 287 | .Bd -literal | ||
| 288 | #define SN_commonName "CN" | ||
| 289 | #define LN_commonName "commonName" | ||
| 290 | #define NID_commonName 13 | ||
| 291 | .Ed | ||
| 292 | .Pp | ||
| 293 | New objects can be added by calling | ||
| 294 | .Xr OBJ_create 3 . | ||
| 295 | .Pp | ||
| 296 | Table objects have certain advantages over other objects: for example | ||
| 297 | their NIDs can be used in a C language switch statement. | ||
| 298 | They are also static constant structures which are shared: that is there | ||
| 299 | is only a single constant structure for each table object. | ||
| 300 | .Pp | ||
| 301 | Objects which are not in the table have the NID value | ||
| 302 | .Dv NID_undef . | ||
| 303 | .Pp | ||
| 304 | Objects do not need to be in the internal tables to be processed: | ||
| 305 | the functions | ||
| 306 | .Fn OBJ_txt2obj | ||
| 307 | and | ||
| 308 | .Fn OBJ_obj2txt | ||
| 309 | can process the numerical form of an OID. | ||
| 310 | .Sh RETURN VALUES | 301 | .Sh RETURN VALUES |
| 311 | .Fn OBJ_nid2obj , | 302 | Application code should treat all returned values \(em |
| 312 | .Fn OBJ_txt2obj , | 303 | objects, names, and NIDs \(em as constants. |
| 313 | and | 304 | .Pp |
| 314 | .Fn OBJ_dup | 305 | .Fn OBJ_nid2obj |
| 315 | return an | 306 | returns a pointer to a table object owned by the library or |
| 316 | .Vt ASN1_OBJECT | ||
| 317 | object or | ||
| 318 | .Dv NULL | 307 | .Dv NULL |
| 319 | if an error occurs. | 308 | if no matching table object is found. |
| 320 | .Pp | 309 | .Pp |
| 321 | .Fn OBJ_nid2ln | 310 | .Fn OBJ_nid2ln |
| 322 | and | 311 | and |
| 323 | .Fn OBJ_nid2sn | 312 | .Fn OBJ_nid2sn |
| 324 | return a valid string or | 313 | return a pointer to a string owned by a table object or |
| 325 | .Dv NULL | 314 | .Dv NULL |
| 326 | on error. | 315 | if no matching table object is found. |
| 316 | For | ||
| 317 | .Dv NID_undef , | ||
| 318 | they return the constant static strings | ||
| 319 | .Qq undefined | ||
| 320 | and | ||
| 321 | .Qq UNDEF , | ||
| 322 | respectively. | ||
| 327 | .Pp | 323 | .Pp |
| 328 | .Fn OBJ_obj2nid , | 324 | .Fn OBJ_obj2nid |
| 329 | .Fn OBJ_ln2nid , | 325 | returns an NID on success, or |
| 330 | .Fn OBJ_sn2nid , | 326 | .Dv NID_undef |
| 327 | if | ||
| 328 | .Fa object | ||
| 329 | is | ||
| 330 | .Dv NULL , | ||
| 331 | does not contain an OID, | ||
| 332 | if no table object matching the OID is found, | ||
| 333 | or if the matching object does not contain an NID. | ||
| 334 | .Pp | ||
| 335 | .Fn OBJ_ln2nid | ||
| 331 | and | 336 | and |
| 337 | .Fn OBJ_sn2nid | ||
| 338 | return an NID on success or | ||
| 339 | .Dv NID_undef | ||
| 340 | if no matching table object is found | ||
| 341 | or if the matching object does not contain an NID. | ||
| 342 | .Pp | ||
| 332 | .Fn OBJ_txt2nid | 343 | .Fn OBJ_txt2nid |
| 333 | return a NID or | 344 | returns an NID on success or |
| 334 | .Dv NID_undef | 345 | .Dv NID_undef |
| 335 | on error. | 346 | if parsing of |
| 347 | .Fa s | ||
| 348 | or memory allocation fails, if no matching table object is found, | ||
| 349 | or if the matching object does not contain an NID. | ||
| 350 | .Pp | ||
| 351 | .Fn OBJ_txt2obj | ||
| 352 | returns a pointer to a table object owned by the library if lookup of | ||
| 353 | .Fa s | ||
| 354 | as a long or short name succeeds. | ||
| 355 | Otherwise, it returns a newly created object, | ||
| 356 | transferring ownership to the caller, or | ||
| 357 | .Dv NULL | ||
| 358 | if parsing of | ||
| 359 | .Fa s | ||
| 360 | or memory allocation fails. | ||
| 336 | .Pp | 361 | .Pp |
| 337 | .Fn OBJ_obj2txt | 362 | .Fn OBJ_obj2txt |
| 338 | and | 363 | and |
| 339 | .Fn i2t_ASN1_OBJECT | 364 | .Fn i2t_ASN1_OBJECT |
| 340 | return the amount of space required in bytes, | 365 | return the amount of space required in bytes, |
| 341 | including the terminating NUL byte. | 366 | including the terminating NUL byte, |
| 367 | or zero if an error occurs before the required space can be calculated, | ||
| 368 | in particular if | ||
| 369 | .Fa buf_len | ||
| 370 | is negative, | ||
| 371 | .Fa object | ||
| 372 | is | ||
| 373 | .Dv NULL | ||
| 374 | or does not contain an OID, | ||
| 375 | or if memory allocation fails. | ||
| 376 | .Pp | ||
| 377 | .Fn OBJ_cmp | ||
| 378 | returns 0 if both objects refer to the same OID | ||
| 379 | or neither of them are associated with any OID, | ||
| 380 | or a non-zero value if at least one of them refers to an OID | ||
| 381 | but the other one does not refer to the same OID. | ||
| 382 | .Pp | ||
| 383 | .Fn OBJ_dup | ||
| 384 | returns the pointer to the original | ||
| 385 | .Fa object | ||
| 386 | if it is not marked as dynamically allocated. | ||
| 387 | Otherwise, it returns a newly created object, | ||
| 388 | transferring ownership to the caller, or | ||
| 389 | .Dv NULL | ||
| 390 | if | ||
| 391 | .Fa object | ||
| 392 | is | ||
| 393 | .Dv NULL | ||
| 394 | or memory allocation fails. | ||
| 342 | .Pp | 395 | .Pp |
| 343 | .Fn i2a_ASN1_OBJECT | 396 | .Fn i2a_ASN1_OBJECT |
| 344 | returns the number of bytes written, even if | 397 | returns the number of bytes written, even if the given |
| 345 | .Fa a | 398 | .Fa object |
| 346 | is invalid or contains invalid data, | 399 | is invalid or contains invalid data, |
| 347 | but a negative value if memory allocation or a write operation fails. | 400 | but a negative value if memory allocation or a write operation fails. |
| 348 | .Pp | 401 | .Pp |
| 349 | .Fn OBJ_cmp | ||
| 350 | returns 0 if the contents of | ||
| 351 | .Fa a | ||
| 352 | and | ||
| 353 | .Fa b | ||
| 354 | are identical, or non-zero otherwise. | ||
| 355 | .Pp | ||
| 356 | In some cases of failure of | 402 | In some cases of failure of |
| 357 | .Fn OBJ_nid2obj , | 403 | .Fn OBJ_nid2obj , |
| 358 | .Fn OBJ_nid2ln , | 404 | .Fn OBJ_nid2ln , |
| @@ -367,23 +413,23 @@ and | |||
| 367 | the reason can be determined with | 413 | the reason can be determined with |
| 368 | .Xr ERR_get_error 3 . | 414 | .Xr ERR_get_error 3 . |
| 369 | .Sh EXAMPLES | 415 | .Sh EXAMPLES |
| 370 | Create an object for | 416 | Retrieve the object for |
| 371 | .Sy commonName : | 417 | .Sy commonName : |
| 372 | .Bd -literal -offset indent | 418 | .Bd -literal -offset indent |
| 373 | ASN1_OBJECT *o; | 419 | ASN1_OBJECT *object; |
| 374 | o = OBJ_nid2obj(NID_commonName); | 420 | object = OBJ_nid2obj(NID_commonName); |
| 375 | .Ed | 421 | .Ed |
| 376 | .Pp | 422 | .Pp |
| 377 | Check if an object is | 423 | Check whether an object contains the OID for |
| 378 | .Sy commonName : | 424 | .Sy commonName : |
| 379 | .Bd -literal -offset indent | 425 | .Bd -literal -offset indent |
| 380 | if (OBJ_obj2nid(obj) == NID_commonName) | 426 | if (OBJ_obj2nid(object) == NID_commonName) |
| 381 | /* Do something */ | 427 | /* Do something */ |
| 382 | .Ed | 428 | .Ed |
| 383 | .Pp | 429 | .Pp |
| 384 | Create a new object directly: | 430 | Create a new object directly: |
| 385 | .Bd -literal -offset indent | 431 | .Bd -literal -offset indent |
| 386 | obj = OBJ_txt2obj("1.2.3.4", 1); | 432 | object = OBJ_txt2obj("1.2.3.4", 1); |
| 387 | .Ed | 433 | .Ed |
| 388 | .Sh SEE ALSO | 434 | .Sh SEE ALSO |
| 389 | .Xr ASN1_OBJECT_new 3 , | 435 | .Xr ASN1_OBJECT_new 3 , |
| @@ -416,7 +462,52 @@ first appeared in OpenSSL 0.9.2b. | |||
| 416 | first appeared in OpenSSL 0.9.4. | 462 | first appeared in OpenSSL 0.9.4. |
| 417 | Both functions have been available since | 463 | Both functions have been available since |
| 418 | .Ox 2.6 . | 464 | .Ox 2.6 . |
| 465 | .Sh CAVEATS | ||
| 466 | The API contract of | ||
| 467 | .Fn OBJ_txt2obj | ||
| 468 | when called with a | ||
| 469 | .Fa no_name | ||
| 470 | argument of 0 and of | ||
| 471 | .Fn OBJ_dup | ||
| 472 | is scary in so far as the caller cannot find out from the returned | ||
| 473 | object whether it is owned by the library or whether ownership was | ||
| 474 | transferred to the caller. | ||
| 475 | Consequently, it is best practice to assume that ownership of the object | ||
| 476 | may have been transferred and call | ||
| 477 | .Xr ASN1_OBJECT_free 3 | ||
| 478 | on the returned object when the caller no longer needs it. | ||
| 479 | In case the library retained ownership of the returned object, | ||
| 480 | .Xr ASN1_OBJECT_free 3 | ||
| 481 | has no effect and is harmless. | ||
| 482 | .Pp | ||
| 483 | Objects returned from | ||
| 484 | .Fn OBJ_txt2obj | ||
| 485 | with a | ||
| 486 | .Fa no_name | ||
| 487 | argument of 1 always require | ||
| 488 | .Xr ASN1_OBJECT_free 3 | ||
| 489 | to prevent memory leaks. | ||
| 490 | .Pp | ||
| 491 | Objects returned from | ||
| 492 | .Fn OBJ_nid2obj | ||
| 493 | never require | ||
| 494 | .Xr ASN1_OBJECT_free 3 , | ||
| 495 | but calling it anyway has no effect and is harmless. | ||
| 419 | .Sh BUGS | 496 | .Sh BUGS |
| 497 | Usually, an object is expected to contain an NID other than | ||
| 498 | .Dv NID_undef | ||
| 499 | if and only if it is a table object. | ||
| 500 | However, this is not an invariant guaranteed by the API. | ||
| 501 | In particular, | ||
| 502 | .Xr ASN1_OBJECT_create 3 | ||
| 503 | allows the creation of non-table objects containing bogus NIDs. | ||
| 504 | .Fn OBJ_obj2nid | ||
| 505 | returns such bogus NIDs even though | ||
| 506 | .Fn OBJ_nid2obj | ||
| 507 | cannot use them for retrieval. | ||
| 508 | On top of that, the global table contains one built-in object with an NID of | ||
| 509 | .Dv NID_undef . | ||
| 510 | .Pp | ||
| 420 | .Fn OBJ_obj2txt | 511 | .Fn OBJ_obj2txt |
| 421 | is awkward and messy to use: it doesn't follow the convention of other | 512 | is awkward and messy to use: it doesn't follow the convention of other |
| 422 | OpenSSL functions where the buffer can be set to | 513 | OpenSSL functions where the buffer can be set to |
