/src/openssl/include/openssl/objects.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #ifndef OPENSSL_OBJECTS_H |
11 | | # define OPENSSL_OBJECTS_H |
12 | | # pragma once |
13 | | |
14 | | # include <openssl/macros.h> |
15 | | # ifndef OPENSSL_NO_DEPRECATED_3_0 |
16 | | # define HEADER_OBJECTS_H |
17 | | # endif |
18 | | |
19 | | # include <openssl/obj_mac.h> |
20 | | # include <openssl/bio.h> |
21 | | # include <openssl/asn1.h> |
22 | | # include <openssl/objectserr.h> |
23 | | |
24 | | # define OBJ_NAME_TYPE_UNDEF 0x00 |
25 | 6 | # define OBJ_NAME_TYPE_MD_METH 0x01 |
26 | 6 | # define OBJ_NAME_TYPE_CIPHER_METH 0x02 |
27 | | # define OBJ_NAME_TYPE_PKEY_METH 0x03 |
28 | | # define OBJ_NAME_TYPE_COMP_METH 0x04 |
29 | | # define OBJ_NAME_TYPE_MAC_METH 0x05 |
30 | 6 | # define OBJ_NAME_TYPE_KDF_METH 0x06 |
31 | | # define OBJ_NAME_TYPE_NUM 0x07 |
32 | | |
33 | 0 | # define OBJ_NAME_ALIAS 0x8000 |
34 | | |
35 | | # define OBJ_BSEARCH_VALUE_ON_NOMATCH 0x01 |
36 | | # define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH 0x02 |
37 | | |
38 | | |
39 | | #ifdef __cplusplus |
40 | | extern "C" { |
41 | | #endif |
42 | | |
43 | | typedef struct obj_name_st { |
44 | | int type; |
45 | | int alias; |
46 | | const char *name; |
47 | | const char *data; |
48 | | } OBJ_NAME; |
49 | | |
50 | | # define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) |
51 | | |
52 | | int OBJ_NAME_init(void); |
53 | | int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), |
54 | | int (*cmp_func) (const char *, const char *), |
55 | | void (*free_func) (const char *, int, const char *)); |
56 | | const char *OBJ_NAME_get(const char *name, int type); |
57 | | int OBJ_NAME_add(const char *name, int type, const char *data); |
58 | | int OBJ_NAME_remove(const char *name, int type); |
59 | | void OBJ_NAME_cleanup(int type); /* -1 for everything */ |
60 | | void OBJ_NAME_do_all(int type, void (*fn) (const OBJ_NAME *, void *arg), |
61 | | void *arg); |
62 | | void OBJ_NAME_do_all_sorted(int type, |
63 | | void (*fn) (const OBJ_NAME *, void *arg), |
64 | | void *arg); |
65 | | |
66 | | DECLARE_ASN1_DUP_FUNCTION_name(ASN1_OBJECT, OBJ) |
67 | | ASN1_OBJECT *OBJ_nid2obj(int n); |
68 | | const char *OBJ_nid2ln(int n); |
69 | | const char *OBJ_nid2sn(int n); |
70 | | int OBJ_obj2nid(const ASN1_OBJECT *o); |
71 | | ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name); |
72 | | int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name); |
73 | | int OBJ_txt2nid(const char *s); |
74 | | int OBJ_ln2nid(const char *s); |
75 | | int OBJ_sn2nid(const char *s); |
76 | | int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b); |
77 | | const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, |
78 | | int (*cmp) (const void *, const void *)); |
79 | | const void *OBJ_bsearch_ex_(const void *key, const void *base, int num, |
80 | | int size, |
81 | | int (*cmp) (const void *, const void *), |
82 | | int flags); |
83 | | |
84 | | # define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \ |
85 | | static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \ |
86 | | static int nm##_cmp(type1 const *, type2 const *); \ |
87 | | scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) |
88 | | |
89 | | # define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \ |
90 | | _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp) |
91 | | # define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ |
92 | | type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) |
93 | | |
94 | | /*- |
95 | | * Unsolved problem: if a type is actually a pointer type, like |
96 | | * nid_triple is, then its impossible to get a const where you need |
97 | | * it. Consider: |
98 | | * |
99 | | * typedef int nid_triple[3]; |
100 | | * const void *a_; |
101 | | * const nid_triple const *a = a_; |
102 | | * |
103 | | * The assignment discards a const because what you really want is: |
104 | | * |
105 | | * const int const * const *a = a_; |
106 | | * |
107 | | * But if you do that, you lose the fact that a is an array of 3 ints, |
108 | | * which breaks comparison functions. |
109 | | * |
110 | | * Thus we end up having to cast, sadly, or unpack the |
111 | | * declarations. Or, as I finally did in this case, declare nid_triple |
112 | | * to be a struct, which it should have been in the first place. |
113 | | * |
114 | | * Ben, August 2008. |
115 | | * |
116 | | * Also, strictly speaking not all types need be const, but handling |
117 | | * the non-constness means a lot of complication, and in practice |
118 | | * comparison routines do always not touch their arguments. |
119 | | */ |
120 | | |
121 | | # define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm) \ |
122 | | static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ |
123 | 4.70M | { \ |
124 | 4.70M | type1 const *a = a_; \ |
125 | 4.70M | type2 const *b = b_; \ |
126 | 4.70M | return nm##_cmp(a,b); \ |
127 | 4.70M | } \ obj_dat.c:obj_cmp_BSEARCH_CMP_FN Line | Count | Source | 123 | 3.91M | { \ | 124 | 3.91M | type1 const *a = a_; \ | 125 | 3.91M | type2 const *b = b_; \ | 126 | 3.91M | return nm##_cmp(a,b); \ | 127 | 3.91M | } \ |
Unexecuted instantiation: obj_dat.c:ln_cmp_BSEARCH_CMP_FN Unexecuted instantiation: obj_dat.c:sn_cmp_BSEARCH_CMP_FN Unexecuted instantiation: a_strnid.c:table_cmp_BSEARCH_CMP_FN ameth_lib.c:ameth_cmp_BSEARCH_CMP_FN Line | Count | Source | 123 | 61.9k | { \ | 124 | 61.9k | type1 const *a = a_; \ | 125 | 61.9k | type2 const *b = b_; \ | 126 | 61.9k | return nm##_cmp(a,b); \ | 127 | 61.9k | } \ |
Unexecuted instantiation: pmeth_lib.c:pmeth_func_cmp_BSEARCH_CMP_FN obj_xref.c:sig_cmp_BSEARCH_CMP_FN Line | Count | Source | 123 | 15.5k | { \ | 124 | 15.5k | type1 const *a = a_; \ | 125 | 15.5k | type2 const *b = b_; \ | 126 | 15.5k | return nm##_cmp(a,b); \ | 127 | 15.5k | } \ |
Unexecuted instantiation: obj_xref.c:sigx_cmp_BSEARCH_CMP_FN v3_lib.c:ext_cmp_BSEARCH_CMP_FN Line | Count | Source | 123 | 714k | { \ | 124 | 714k | type1 const *a = a_; \ | 125 | 714k | type2 const *b = b_; \ | 126 | 714k | return nm##_cmp(a,b); \ | 127 | 714k | } \ |
Unexecuted instantiation: v3_purp.c:nid_cmp_BSEARCH_CMP_FN Unexecuted instantiation: x509_vpm.c:table_cmp_BSEARCH_CMP_FN Unexecuted instantiation: evp_pbe.c:pbe2_cmp_BSEARCH_CMP_FN |
128 | | static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ |
129 | 556k | { \ |
130 | 556k | return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ |
131 | 556k | nm##_cmp_BSEARCH_CMP_FN); \ |
132 | 556k | } \ obj_dat.c:OBJ_bsearch_obj Line | Count | Source | 129 | 402k | { \ | 130 | 402k | return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ | 131 | 402k | nm##_cmp_BSEARCH_CMP_FN); \ | 132 | 402k | } \ |
Unexecuted instantiation: obj_dat.c:OBJ_bsearch_ln Unexecuted instantiation: obj_dat.c:OBJ_bsearch_sn Unexecuted instantiation: a_strnid.c:OBJ_bsearch_table ameth_lib.c:OBJ_bsearch_ameth Line | Count | Source | 129 | 14.0k | { \ | 130 | 14.0k | return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ | 131 | 14.0k | nm##_cmp_BSEARCH_CMP_FN); \ | 132 | 14.0k | } \ |
Unexecuted instantiation: pmeth_lib.c:OBJ_bsearch_pmeth_func obj_xref.c:OBJ_bsearch_sig Line | Count | Source | 129 | 3.03k | { \ | 130 | 3.03k | return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ | 131 | 3.03k | nm##_cmp_BSEARCH_CMP_FN); \ | 132 | 3.03k | } \ |
Unexecuted instantiation: obj_xref.c:OBJ_bsearch_sigx Line | Count | Source | 129 | 137k | { \ | 130 | 137k | return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ | 131 | 137k | nm##_cmp_BSEARCH_CMP_FN); \ | 132 | 137k | } \ |
Unexecuted instantiation: v3_purp.c:OBJ_bsearch_nid Unexecuted instantiation: x509_vpm.c:OBJ_bsearch_table Unexecuted instantiation: evp_pbe.c:OBJ_bsearch_pbe2 |
133 | | extern void dummy_prototype(void) |
134 | | |
135 | | # define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ |
136 | | static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ |
137 | | { \ |
138 | | type1 const *a = a_; \ |
139 | | type2 const *b = b_; \ |
140 | | return nm##_cmp(a,b); \ |
141 | | } \ |
142 | | type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ |
143 | | { \ |
144 | | return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ |
145 | | nm##_cmp_BSEARCH_CMP_FN); \ |
146 | | } \ |
147 | | extern void dummy_prototype(void) |
148 | | |
149 | | # define OBJ_bsearch(type1,key,type2,base,num,cmp) \ |
150 | | ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ |
151 | | num,sizeof(type2), \ |
152 | | ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ |
153 | | (void)CHECKED_PTR_OF(type2,cmp##_type_2), \ |
154 | | cmp##_BSEARCH_CMP_FN))) |
155 | | |
156 | | # define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags) \ |
157 | | ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ |
158 | | num,sizeof(type2), \ |
159 | | ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ |
160 | | (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \ |
161 | | cmp##_BSEARCH_CMP_FN)),flags) |
162 | | |
163 | | int OBJ_new_nid(int num); |
164 | | int OBJ_add_object(const ASN1_OBJECT *obj); |
165 | | int OBJ_create(const char *oid, const char *sn, const char *ln); |
166 | | #ifndef OPENSSL_NO_DEPRECATED_1_1_0 |
167 | | # define OBJ_cleanup() while(0) continue |
168 | | #endif |
169 | | int OBJ_create_objects(BIO *in); |
170 | | |
171 | | size_t OBJ_length(const ASN1_OBJECT *obj); |
172 | | const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj); |
173 | | |
174 | | int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid); |
175 | | int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid); |
176 | | int OBJ_add_sigid(int signid, int dig_id, int pkey_id); |
177 | | void OBJ_sigid_free(void); |
178 | | |
179 | | |
180 | | # ifdef __cplusplus |
181 | | } |
182 | | # endif |
183 | | #endif |