]>
Commit | Line | Data |
---|---|---|
21dcbebc | 1 | /* |
d2ba8123 | 2 | * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. |
d02b48c6 | 3 | * |
48f4ad77 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
21dcbebc RS |
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 | |
d02b48c6 RE |
8 | */ |
9 | ||
10 | #ifndef HEADER_OBJECTS_H | |
0f113f3e MC |
11 | # define HEADER_OBJECTS_H |
12 | ||
2f0ca54c | 13 | # include <openssl/obj_mac.h> |
0f113f3e MC |
14 | # include <openssl/bio.h> |
15 | # include <openssl/asn1.h> | |
52df25cf | 16 | # include <openssl/objectserr.h> |
d02b48c6 | 17 | |
0f113f3e MC |
18 | # define OBJ_NAME_TYPE_UNDEF 0x00 |
19 | # define OBJ_NAME_TYPE_MD_METH 0x01 | |
20 | # define OBJ_NAME_TYPE_CIPHER_METH 0x02 | |
21 | # define OBJ_NAME_TYPE_PKEY_METH 0x03 | |
22 | # define OBJ_NAME_TYPE_COMP_METH 0x04 | |
567db2c1 | 23 | # define OBJ_NAME_TYPE_MAC_METH 0x05 |
d2ba8123 SL |
24 | # define OBJ_NAME_TYPE_KDF_METH 0x06 |
25 | # define OBJ_NAME_TYPE_NUM 0x07 | |
dfeab068 | 26 | |
0f113f3e | 27 | # define OBJ_NAME_ALIAS 0x8000 |
ea5240a5 | 28 | |
0f113f3e MC |
29 | # define OBJ_BSEARCH_VALUE_ON_NOMATCH 0x01 |
30 | # define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH 0x02 | |
dfeab068 RE |
31 | |
32 | ||
82271cee RL |
33 | #ifdef __cplusplus |
34 | extern "C" { | |
35 | #endif | |
36 | ||
0f113f3e MC |
37 | typedef struct obj_name_st { |
38 | int type; | |
39 | int alias; | |
40 | const char *name; | |
41 | const char *data; | |
42 | } OBJ_NAME; | |
58964a49 | 43 | |
0f113f3e | 44 | # define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) |
d02b48c6 | 45 | |
dfeab068 | 46 | int OBJ_NAME_init(void); |
0f113f3e MC |
47 | int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), |
48 | int (*cmp_func) (const char *, const char *), | |
49 | void (*free_func) (const char *, int, const char *)); | |
50 | const char *OBJ_NAME_get(const char *name, int type); | |
51 | int OBJ_NAME_add(const char *name, int type, const char *data); | |
52 | int OBJ_NAME_remove(const char *name, int type); | |
dfeab068 | 53 | void OBJ_NAME_cleanup(int type); /* -1 for everything */ |
0f113f3e MC |
54 | void OBJ_NAME_do_all(int type, void (*fn) (const OBJ_NAME *, void *arg), |
55 | void *arg); | |
56 | void OBJ_NAME_do_all_sorted(int type, | |
57 | void (*fn) (const OBJ_NAME *, void *arg), | |
58 | void *arg); | |
59 | ||
9fdcc21f | 60 | DECLARE_ASN1_DUP_FUNCTION_name(ASN1_OBJECT, OBJ) |
0f113f3e MC |
61 | ASN1_OBJECT *OBJ_nid2obj(int n); |
62 | const char *OBJ_nid2ln(int n); | |
63 | const char *OBJ_nid2sn(int n); | |
64 | int OBJ_obj2nid(const ASN1_OBJECT *o); | |
65 | ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name); | |
66 | int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name); | |
67 | int OBJ_txt2nid(const char *s); | |
68 | int OBJ_ln2nid(const char *s); | |
69 | int OBJ_sn2nid(const char *s); | |
70 | int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b); | |
71 | const void *OBJ_bsearch_(const void *key, const void *base, int num, int size, | |
72 | int (*cmp) (const void *, const void *)); | |
73 | const void *OBJ_bsearch_ex_(const void *key, const void *base, int num, | |
74 | int size, | |
75 | int (*cmp) (const void *, const void *), | |
76 | int flags); | |
77 | ||
78 | # define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \ | |
e19106f5 DSH |
79 | static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \ |
80 | static int nm##_cmp(type1 const *, type2 const *); \ | |
81 | scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) | |
babb3798 | 82 | |
0f113f3e | 83 | # define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \ |
babb3798 | 84 | _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp) |
0f113f3e | 85 | # define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ |
e19106f5 | 86 | type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) |
babb3798 | 87 | |
1d97c843 | 88 | /*- |
babb3798 BL |
89 | * Unsolved problem: if a type is actually a pointer type, like |
90 | * nid_triple is, then its impossible to get a const where you need | |
91 | * it. Consider: | |
92 | * | |
93 | * typedef int nid_triple[3]; | |
94 | * const void *a_; | |
95 | * const nid_triple const *a = a_; | |
96 | * | |
69687aa8 | 97 | * The assignment discards a const because what you really want is: |
babb3798 BL |
98 | * |
99 | * const int const * const *a = a_; | |
100 | * | |
101 | * But if you do that, you lose the fact that a is an array of 3 ints, | |
102 | * which breaks comparison functions. | |
103 | * | |
104 | * Thus we end up having to cast, sadly, or unpack the | |
69687aa8 | 105 | * declarations. Or, as I finally did in this case, declare nid_triple |
babb3798 BL |
106 | * to be a struct, which it should have been in the first place. |
107 | * | |
108 | * Ben, August 2008. | |
109 | * | |
110 | * Also, strictly speaking not all types need be const, but handling | |
111 | * the non-constness means a lot of complication, and in practice | |
112 | * comparison routines do always not touch their arguments. | |
113 | */ | |
06ddf8eb | 114 | |
0f113f3e MC |
115 | # define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm) \ |
116 | static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ | |
babb3798 | 117 | { \ |
606f6c47 DSH |
118 | type1 const *a = a_; \ |
119 | type2 const *b = b_; \ | |
e19106f5 DSH |
120 | return nm##_cmp(a,b); \ |
121 | } \ | |
06ddf8eb | 122 | static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ |
e19106f5 DSH |
123 | { \ |
124 | return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ | |
0f113f3e | 125 | nm##_cmp_BSEARCH_CMP_FN); \ |
606f6c47 DSH |
126 | } \ |
127 | extern void dummy_prototype(void) | |
babb3798 | 128 | |
0f113f3e MC |
129 | # define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \ |
130 | static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \ | |
06ddf8eb DSH |
131 | { \ |
132 | type1 const *a = a_; \ | |
133 | type2 const *b = b_; \ | |
134 | return nm##_cmp(a,b); \ | |
135 | } \ | |
136 | type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \ | |
137 | { \ | |
138 | return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \ | |
0f113f3e | 139 | nm##_cmp_BSEARCH_CMP_FN); \ |
06ddf8eb DSH |
140 | } \ |
141 | extern void dummy_prototype(void) | |
babb3798 | 142 | |
0f113f3e | 143 | # define OBJ_bsearch(type1,key,type2,base,num,cmp) \ |
babb3798 | 144 | ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ |
0f113f3e MC |
145 | num,sizeof(type2), \ |
146 | ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ | |
147 | (void)CHECKED_PTR_OF(type2,cmp##_type_2), \ | |
148 | cmp##_BSEARCH_CMP_FN))) | |
d02b48c6 | 149 | |
0f113f3e | 150 | # define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags) \ |
606f6c47 | 151 | ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \ |
0f113f3e MC |
152 | num,sizeof(type2), \ |
153 | ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \ | |
154 | (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \ | |
155 | cmp##_BSEARCH_CMP_FN)),flags) | |
1ea6472e | 156 | |
0f113f3e MC |
157 | int OBJ_new_nid(int num); |
158 | int OBJ_add_object(const ASN1_OBJECT *obj); | |
159 | int OBJ_create(const char *oid, const char *sn, const char *ln); | |
fcd2d5a6 | 160 | #if !OPENSSL_API_1_1_0 |
6457615a | 161 | # define OBJ_cleanup() while(0) continue |
7b8cc9b3 | 162 | #endif |
0f113f3e | 163 | int OBJ_create_objects(BIO *in); |
d02b48c6 | 164 | |
2e430277 DSH |
165 | size_t OBJ_length(const ASN1_OBJECT *obj); |
166 | const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj); | |
167 | ||
d2027098 DSH |
168 | int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid); |
169 | int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid); | |
0ee2166c DSH |
170 | int OBJ_add_sigid(int signid, int dig_id, int pkey_id); |
171 | void OBJ_sigid_free(void); | |
d2027098 | 172 | |
6d311938 | 173 | |
0cd0a820 | 174 | # ifdef __cplusplus |
d02b48c6 | 175 | } |
0cd0a820 | 176 | # endif |
d02b48c6 | 177 | #endif |