diff options
Diffstat (limited to 'src/lib/libcrypto/man/OBJ_NAME_add.3')
| -rw-r--r-- | src/lib/libcrypto/man/OBJ_NAME_add.3 | 307 |
1 files changed, 0 insertions, 307 deletions
diff --git a/src/lib/libcrypto/man/OBJ_NAME_add.3 b/src/lib/libcrypto/man/OBJ_NAME_add.3 deleted file mode 100644 index 0b46010c49..0000000000 --- a/src/lib/libcrypto/man/OBJ_NAME_add.3 +++ /dev/null | |||
| @@ -1,307 +0,0 @@ | |||
| 1 | .\" $OpenBSD: OBJ_NAME_add.3,v 1.6 2024/01/31 08:02:53 tb Exp $ | ||
| 2 | .\" | ||
| 3 | .\" Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org> | ||
| 4 | .\" | ||
| 5 | .\" Permission to use, copy, modify, and distribute this software for any | ||
| 6 | .\" purpose with or without fee is hereby granted, provided that the above | ||
| 7 | .\" copyright notice and this permission notice appear in all copies. | ||
| 8 | .\" | ||
| 9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | .\" | ||
| 17 | .Dd $Mdocdate: January 31 2024 $ | ||
| 18 | .Dt OBJ_NAME_ADD 3 | ||
| 19 | .Os | ||
| 20 | .Sh NAME | ||
| 21 | .Nm OBJ_NAME_add , | ||
| 22 | .Nm OBJ_NAME_remove , | ||
| 23 | .Nm OBJ_NAME_get , | ||
| 24 | .Nm OBJ_NAME_new_index , | ||
| 25 | .Nm OBJ_NAME_init , | ||
| 26 | .Nm OBJ_NAME_cleanup | ||
| 27 | .Nd global associative array | ||
| 28 | .Sh SYNOPSIS | ||
| 29 | .In openssl/objects.h | ||
| 30 | .Ft int | ||
| 31 | .Fo OBJ_NAME_add | ||
| 32 | .Fa "const char *name" | ||
| 33 | .Fa "int type" | ||
| 34 | .Fa "const char *value" | ||
| 35 | .Fc | ||
| 36 | .Ft int | ||
| 37 | .Fo OBJ_NAME_remove | ||
| 38 | .Fa "const char *name" | ||
| 39 | .Fa "int type" | ||
| 40 | .Fc | ||
| 41 | .Ft const char * | ||
| 42 | .Fo OBJ_NAME_get | ||
| 43 | .Fa "const char *name" | ||
| 44 | .Fa "int type" | ||
| 45 | .Fc | ||
| 46 | .Ft int | ||
| 47 | .Fo OBJ_NAME_new_index | ||
| 48 | .Fa "unsigned long (*hash_func)(const char *name)" | ||
| 49 | .Fa "int (*cmp_func)(const char *name1, const char *name2)" | ||
| 50 | .Fa "void (*free_func)(const char *name, int type, const char *value)" | ||
| 51 | .Fc | ||
| 52 | .Ft int | ||
| 53 | .Fn OBJ_NAME_init void | ||
| 54 | .Ft void | ||
| 55 | .Fn OBJ_NAME_cleanup "int type" | ||
| 56 | .Bd -literal | ||
| 57 | typedef struct { | ||
| 58 | int type; | ||
| 59 | int alias; | ||
| 60 | const char *name; | ||
| 61 | const char *data; | ||
| 62 | } OBJ_NAME; | ||
| 63 | .Ed | ||
| 64 | .Sh DESCRIPTION | ||
| 65 | These functions implement a single, static associative array | ||
| 66 | with the following properties: | ||
| 67 | .Bl -bullet | ||
| 68 | .It | ||
| 69 | The keys are ordered pairs consisting of a NUL-terminated string | ||
| 70 | .Pq called the Fa name | ||
| 71 | and an | ||
| 72 | .Vt int | ||
| 73 | number | ||
| 74 | .Pq called the Fa type . | ||
| 75 | Two types are predefined and used internally by the library: | ||
| 76 | .Dv OBJ_NAME_TYPE_MD_METH | ||
| 77 | and | ||
| 78 | .Dv OBJ_NAME_TYPE_CIPHER_METH . | ||
| 79 | Two additional types are predefined but not used internally: | ||
| 80 | .Dv OBJ_NAME_TYPE_PKEY_METH | ||
| 81 | and | ||
| 82 | .Dv OBJ_NAME_TYPE_COMP_METH . | ||
| 83 | All predefined types are greater than | ||
| 84 | .Dv OBJ_NAME_TYPE_UNDEF | ||
| 85 | and smaller than | ||
| 86 | .Dv OBJ_NAME_TYPE_NUM . | ||
| 87 | .It | ||
| 88 | The values are pointers. | ||
| 89 | Formally, they are of the type | ||
| 90 | .Vt const char * , | ||
| 91 | but in practice, pointers of other types, for example | ||
| 92 | .Vt EVP_CIPHER * | ||
| 93 | or | ||
| 94 | .Vt EVP_MD * , | ||
| 95 | are often stored as values | ||
| 96 | and cast back to the correct type on retrieval. | ||
| 97 | .It | ||
| 98 | The array supports type-specific aliases for names. | ||
| 99 | .El | ||
| 100 | .Pp | ||
| 101 | .Fn OBJ_NAME_add | ||
| 102 | removes the key-value pair or alias with the key | ||
| 103 | .Pq Fa name , type | ||
| 104 | in the same way as | ||
| 105 | .Fn OBJ_NAME_remove | ||
| 106 | and inserts a key-value pair with the specified | ||
| 107 | .Fa name , | ||
| 108 | .Fa type , | ||
| 109 | and | ||
| 110 | .Fa value . | ||
| 111 | If the bit | ||
| 112 | .Dv OBJ_NAME_ALIAS | ||
| 113 | is set in the | ||
| 114 | .Fa type | ||
| 115 | argument, that bit is cleared before using the | ||
| 116 | .Fa type | ||
| 117 | and the key | ||
| 118 | .Pq Fa name , type | ||
| 119 | becomes an alias for the key | ||
| 120 | .Pq Fa value , type | ||
| 121 | instead of setting a value. | ||
| 122 | It is not checked whether the key | ||
| 123 | .Pq Fa value , type | ||
| 124 | already exists. | ||
| 125 | Consequently, it is possible to define an alias | ||
| 126 | before setting the associated value. | ||
| 127 | .Pp | ||
| 128 | .Fn OBJ_NAME_remove | ||
| 129 | removes the key-value pair or alias with the key | ||
| 130 | .Pq Fa name , type | ||
| 131 | from the array, if it exists. | ||
| 132 | Otherwise, it has no effect. | ||
| 133 | If the bit | ||
| 134 | .Dv OBJ_NAME_ALIAS | ||
| 135 | is set in the | ||
| 136 | .Fa type | ||
| 137 | argument, it is ignored and cleared before using the | ||
| 138 | .Fa type . | ||
| 139 | If the | ||
| 140 | .Fa type | ||
| 141 | is an application-defined type added with | ||
| 142 | .Fn OBJ_NAME_new_index | ||
| 143 | and the | ||
| 144 | .Fa free_func | ||
| 145 | associated with the | ||
| 146 | .Fa type | ||
| 147 | is not a | ||
| 148 | .Dv NULL | ||
| 149 | pointer, it is called with the | ||
| 150 | .Fa name , | ||
| 151 | .Fa type , | ||
| 152 | and | ||
| 153 | .Fa value | ||
| 154 | of the key-value pair being removed or with the | ||
| 155 | .Fa name , | ||
| 156 | .Fa type , | ||
| 157 | and alias target name of the alias being removed. | ||
| 158 | In typical usage, this function might free the | ||
| 159 | .Fa name , | ||
| 160 | and it might free the | ||
| 161 | .Fa value | ||
| 162 | in a type-specific way. | ||
| 163 | .Pp | ||
| 164 | .Fn OBJ_NAME_get | ||
| 165 | looks up the key | ||
| 166 | .Pq Fa name , type , | ||
| 167 | recursively resolving up to ten aliases if needed. | ||
| 168 | If the bit | ||
| 169 | .Dv OBJ_NAME_ALIAS | ||
| 170 | is set in the | ||
| 171 | .Fa type | ||
| 172 | argument, it is cleared before using the | ||
| 173 | .Fa type , | ||
| 174 | processing of aliases is disabled, and if | ||
| 175 | .Pq Fa name , type | ||
| 176 | is an alias, the target name of the alias is returned instead of a value. | ||
| 177 | .Pp | ||
| 178 | .Fn OBJ_NAME_new_index | ||
| 179 | assigns the smallest unassigned positive integer number | ||
| 180 | to represent a new, application-defined | ||
| 181 | .Fa type . | ||
| 182 | The three function pointers will be used, respectively, | ||
| 183 | to hash a name for this type, to compare two names for this type, | ||
| 184 | and to free the contents of a key-value pair holding the given | ||
| 185 | .Fa name , | ||
| 186 | .Fa type , | ||
| 187 | and | ||
| 188 | .Fa value . | ||
| 189 | If the | ||
| 190 | .Fa hash_func | ||
| 191 | argument is a | ||
| 192 | .Dv NULL | ||
| 193 | pointer, | ||
| 194 | .Xr lh_strhash 3 | ||
| 195 | is used instead. | ||
| 196 | If the | ||
| 197 | .Fa cmp_func | ||
| 198 | argument is a | ||
| 199 | .Dv NULL | ||
| 200 | pointer, | ||
| 201 | .Xr strcmp 3 | ||
| 202 | is used instead. | ||
| 203 | If the | ||
| 204 | .Fa free_func | ||
| 205 | argument is a | ||
| 206 | .Dv NULL | ||
| 207 | pointer, the | ||
| 208 | .Fa name | ||
| 209 | and | ||
| 210 | .Fa value | ||
| 211 | pointers contained in the key-value pair are not freed, | ||
| 212 | only the structure representing the pair itself is. | ||
| 213 | This default behaviour is also used for the built-in types. | ||
| 214 | .Pp | ||
| 215 | .Fn OBJ_NAME_init | ||
| 216 | initializes the array. | ||
| 217 | After initialization, the array is empty. | ||
| 218 | Calling | ||
| 219 | .Fn OBJ_NAME_init | ||
| 220 | when the array is already initialized has no effect. | ||
| 221 | Application programs do not need to call this function because | ||
| 222 | .Fn OBJ_NAME_add | ||
| 223 | and | ||
| 224 | .Fn OBJ_NAME_get | ||
| 225 | automatically call it whenever needed. | ||
| 226 | .Pp | ||
| 227 | .Fn OBJ_NAME_cleanup | ||
| 228 | removes all key-value pairs and aliases of the given | ||
| 229 | .Fa type | ||
| 230 | from the array by calling | ||
| 231 | .Fn OBJ_NAME_remove | ||
| 232 | on every such pair and alias. | ||
| 233 | If the | ||
| 234 | .Fa type | ||
| 235 | argument is negative, it removes all key-value pairs and aliases | ||
| 236 | of any type and also reverses all effects of | ||
| 237 | .Fn OBJ_NAME_new_index | ||
| 238 | and | ||
| 239 | .Fn OBJ_NAME_init , | ||
| 240 | in particular resetting the list of types to the predefined types | ||
| 241 | and releasing all memory reserved by these functions. | ||
| 242 | .Pp | ||
| 243 | The | ||
| 244 | .Vt OBJ_NAME | ||
| 245 | structure represents one key-value pair or one alias with the key | ||
| 246 | .Pq Fa name , type . | ||
| 247 | If the | ||
| 248 | .Fa alias | ||
| 249 | field is 0, the | ||
| 250 | .Fa data | ||
| 251 | field contains the value; otherwise, it contains the alias target name. | ||
| 252 | .Sh RETURN VALUES | ||
| 253 | .Fn OBJ_NAME_add | ||
| 254 | and | ||
| 255 | .Fn OBJ_NAME_init | ||
| 256 | return 1 on success or 0 if memory allocation fails. | ||
| 257 | .Pp | ||
| 258 | .Fn OBJ_NAME_remove | ||
| 259 | returns 1 if one key-value pair or alias was removed or 0 otherwise. | ||
| 260 | .Pp | ||
| 261 | .Fn OBJ_NAME_get | ||
| 262 | returns the | ||
| 263 | .Fa value | ||
| 264 | associated with the key | ||
| 265 | .Pq Fa name , type | ||
| 266 | or | ||
| 267 | .Dv NULL | ||
| 268 | if | ||
| 269 | .Fa name | ||
| 270 | is | ||
| 271 | .Dv NULL , | ||
| 272 | if the array does not contain a value for this key, | ||
| 273 | or if more than ten aliases are encountered before finding a value. | ||
| 274 | .Pp | ||
| 275 | .Fn OBJ_NAME_new_index | ||
| 276 | returns a positive integer greater than or equal to | ||
| 277 | .Dv OBJ_NAME_TYPE_NUM | ||
| 278 | representing the new type or 0 if memory allocation fails. | ||
| 279 | .Sh SEE ALSO | ||
| 280 | .Xr EVP_cleanup 3 , | ||
| 281 | .Xr EVP_get_cipherbyname 3 , | ||
| 282 | .Xr EVP_get_digestbyname 3 , | ||
| 283 | .Xr lh_new 3 , | ||
| 284 | .Xr OBJ_create 3 , | ||
| 285 | .Xr OBJ_nid2obj 3 | ||
| 286 | .Sh BUGS | ||
| 287 | Calling | ||
| 288 | .Fn OBJ_NAME_get | ||
| 289 | with the bit | ||
| 290 | .Dv OBJ_NAME_ALIAS | ||
| 291 | is not very useful because there is no way to tell | ||
| 292 | whether the returned pointer points to a value or to a name, | ||
| 293 | short of calling the function again without setting the bit | ||
| 294 | and comparing the two returned pointers. | ||
| 295 | .Pp | ||
| 296 | The | ||
| 297 | .Fa free_func | ||
| 298 | has no way to tell whether its | ||
| 299 | .Fa value | ||
| 300 | argument is indeed of the given | ||
| 301 | .Fa type | ||
| 302 | or whether it is merely the target name of an alias. | ||
| 303 | Consequently, to use values of a type | ||
| 304 | that requires more cleanup than merely calling | ||
| 305 | .Xr free 3 | ||
| 306 | on it, instances of the type need to begin with a magic number or string | ||
| 307 | that cannot occur at the beginning of a name. | ||
