1.\" $OpenBSD: OBJ_create.3,v 1.10 2024/01/31 08:02:53 tb Exp $ 2.\" full merge up to: 3.\" OpenSSL OBJ_nid2obj.pod 9b86974e Aug 17 15:21:33 2015 -0400 4.\" selective merge up to: 5.\" OpenSSL OBJ_nid2obj.pod 0c5bc96f Mar 15 13:57:22 2022 +0000 6.\" 7.\" This file is a derived work. 8.\" The changes are covered by the following Copyright and license: 9.\" 10.\" Copyright (c) 2017, 2021, 2023 Ingo Schwarze <schwarze@openbsd.org> 11.\" 12.\" Permission to use, copy, modify, and distribute this software for any 13.\" purpose with or without fee is hereby granted, provided that the above 14.\" copyright notice and this permission notice appear in all copies. 15.\" 16.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 17.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 18.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 19.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 20.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 21.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 22.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 23.\" 24.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>. 25.\" Copyright (c) 2002, 2006 The OpenSSL Project. 26.\" All rights reserved. 27.\" 28.\" Redistribution and use in source and binary forms, with or without 29.\" modification, are permitted provided that the following conditions 30.\" are met: 31.\" 32.\" 1. Redistributions of source code must retain the above copyright 33.\" notice, this list of conditions and the following disclaimer. 34.\" 35.\" 2. Redistributions in binary form must reproduce the above copyright 36.\" notice, this list of conditions and the following disclaimer in 37.\" the documentation and/or other materials provided with the 38.\" distribution. 39.\" 40.\" 3. All advertising materials mentioning features or use of this 41.\" software must display the following acknowledgment: 42.\" "This product includes software developed by the OpenSSL Project 43.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 44.\" 45.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 46.\" endorse or promote products derived from this software without 47.\" prior written permission. For written permission, please contact 48.\" openssl-core@openssl.org. 49.\" 50.\" 5. Products derived from this software may not be called "OpenSSL" 51.\" nor may "OpenSSL" appear in their names without prior written 52.\" permission of the OpenSSL Project. 53.\" 54.\" 6. Redistributions of any form whatsoever must retain the following 55.\" acknowledgment: 56.\" "This product includes software developed by the OpenSSL Project 57.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 58.\" 59.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 60.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 62.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 63.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 64.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 65.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 66.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 67.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 68.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 69.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 70.\" OF THE POSSIBILITY OF SUCH DAMAGE. 71.\" 72.Dd $Mdocdate: January 31 2024 $ 73.Dt OBJ_CREATE 3 74.Os 75.Sh NAME 76.Nm OBJ_new_nid , 77.Nm OBJ_add_object , 78.Nm OBJ_create , 79.\" OBJ_create_and_add_object is a deprecated, unused alias for OBJ_create(3). 80.Nm OBJ_create_objects , 81.Nm OBJ_cleanup 82.Nd modify the table of ASN.1 object identifiers 83.Sh SYNOPSIS 84.In openssl/objects.h 85.Ft int 86.Fn OBJ_new_nid "int increment" 87.Ft int 88.Fn OBJ_add_object "const ASN1_OBJECT *object" 89.Ft int 90.Fo OBJ_create 91.Fa "const char *oid" 92.Fa "const char *sn" 93.Fa "const char *ln" 94.Fc 95.Ft int 96.Fn OBJ_create_objects "BIO *in_bio" 97.Ft void 98.Fn OBJ_cleanup void 99.Sh DESCRIPTION 100.Fn OBJ_new_nid 101returns the smallest currently unassigned ASN.1 numeric 102object identifier (NID) and reserves 103.Fa increment 104consecutive NIDs starting with it. 105Passing an argument of 1 is usually recommended. 106The return value can be assigned to a new object by passing it as the 107.Fa nid 108argument to 109.Xr ASN1_OBJECT_create 3 110and by passing the resulting object to 111.Fn OBJ_add_object . 112.Pp 113.Fn OBJ_add_object 114adds a copy of the 115.Fa object 116to the internal table of ASN.1 object identifiers for use by 117.Xr OBJ_nid2obj 3 118and related functions. 119.Pp 120.Fn OBJ_create 121provides a simpler way to add a new object to the internal table. 122.Fa oid 123is the numerical form of the object, 124.Fa sn 125the short name and 126.Fa ln 127the long name. 128A new NID is automatically assigned using 129.Fn OBJ_new_nid . 130.Pp 131.Fn OBJ_create_objects 132reads text lines of the form 133.Pp 134.D1 Fa oid sn ln 135.Pp 136from 137.Fa in_bio 138and calls 139.Fn OBJ_create oid sn ln 140for every line read. 141The three fields of the input lines 142are separated by one or more whitespace characters. 143.Pp 144For all three functions, the objects added to the internal table and 145all the data contained in them is marked as not dynamically allocated. 146Consequently, retrieving them with 147.Xr OBJ_nid2obj 3 148or a similar function and then calling 149.Xr ASN1_OBJECT_free 3 150on the returned pointer will have no effect. 151.Pp 152.Fn OBJ_cleanup 153resets the internal object table to its default state, 154removing and freeing all objects that were added with 155.Fn OBJ_add_object , 156.Fn OBJ_create , 157or 158.Fn OBJ_create_objects . 159.Sh RETURN VALUES 160.Fn OBJ_new_nid 161returns the new NID. 162.Pp 163.Fn OBJ_add_object 164returns the NID of the added 165.Fa object 166or 167.Dv NID_undef 168if no object was added because the 169.Fa object 170argument was 171.Dv NULL , 172did not contain an NID, or memory allocation failed. 173.Pp 174.Fn OBJ_create 175returns the new NID or 176.Dv NID_undef 177if 178.Fa oid 179is not a valid representation of an object identifier 180or if memory allocation fails. 181.Pp 182.Fn OBJ_create_objects 183returns the number of objects added. 184.Pp 185In some cases of failure of 186.Fn OBJ_add_object , 187.Fn OBJ_create , 188and 189.Fn OBJ_create_objects , 190the reason can be determined with 191.Xr ERR_get_error 3 . 192.Sh EXAMPLES 193Create a new NID and initialize an object from it: 194.Bd -literal -offset indent 195int new_nid; 196ASN1_OBJECT *obj; 197 198new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier"); 199obj = OBJ_nid2obj(new_nid); 200.Ed 201.Sh SEE ALSO 202.Xr ASN1_OBJECT_new 3 , 203.Xr OBJ_nid2obj 3 204.Sh HISTORY 205.Fn OBJ_new_nid , 206.Fn OBJ_add_object , 207and 208.Fn OBJ_cleanup 209first appeared in SSLeay 0.8.0 and 210.Fn OBJ_create 211in SSLeay 0.9.0. 212These functions have been available since 213.Ox 2.4 . 214.Sh CAVEATS 215.Fn OBJ_add_object 216indicates success even after adding an incomplete object that was created with 217.Xr ASN1_OBJECT_create 3 218but lacks a short name, a long name, or an OID. 219.Pp 220Even 221.Fn OBJ_create 222tolerates 223.Dv NULL 224pointers being passed for the 225.Fa sn 226and/or 227.Fa ln 228arguments, in which case 229.Xr OBJ_nid2sn 3 230and 231.Xr OBJ_sn2nid 3 232or 233.Xr OBJ_nid2ln 3 234and 235.Xr OBJ_ln2nid 3 236will not work on the added object, respectively. 237.Sh BUGS 238.Fn OBJ_new_nid 239does not reserve any return value to indicate an error. 240Consequently, to avoid conflicting NID assignments and integer overflows, 241care must be taken to not pass negative, zero, or large arguments to 242.Fn OBJ_new_nid . 243.Pp 244.Fn OBJ_create_objects 245does not distinguish between end of file, I/O errors, temporary 246unavailability of data on a non-blocking BIO, invalid input syntax, 247and memory allocation failure. 248In all these cases, reading is aborted and the number of objects 249that were already added is returned. 250