]> git.ipfire.org Git - thirdparty/openssl.git/blob - include/openssl/objects.h
265d8e5c2fd684dc5ca84c79ec55be4d7c0273c1
[thirdparty/openssl.git] / include / openssl / objects.h
1 /*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (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 HEADER_OBJECTS_H
11 # define HEADER_OBJECTS_H
12
13 # include <openssl/obj_mac.h>
14 # include <openssl/bio.h>
15 # include <openssl/asn1.h>
16
17 # define OBJ_NAME_TYPE_UNDEF 0x00
18 # define OBJ_NAME_TYPE_MD_METH 0x01
19 # define OBJ_NAME_TYPE_CIPHER_METH 0x02
20 # define OBJ_NAME_TYPE_PKEY_METH 0x03
21 # define OBJ_NAME_TYPE_COMP_METH 0x04
22 # define OBJ_NAME_TYPE_NUM 0x05
23
24 # define OBJ_NAME_ALIAS 0x8000
25
26 # define OBJ_BSEARCH_VALUE_ON_NOMATCH 0x01
27 # define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH 0x02
28
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 typedef struct obj_name_st {
35 int type;
36 int alias;
37 const char *name;
38 const char *data;
39 } OBJ_NAME;
40
41 # define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
42
43 int OBJ_NAME_init(void);
44 int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
45 int (*cmp_func) (const char *, const char *),
46 void (*free_func) (const char *, int, const char *));
47 const char *OBJ_NAME_get(const char *name, int type);
48 int OBJ_NAME_add(const char *name, int type, const char *data);
49 int OBJ_NAME_remove(const char *name, int type);
50 void OBJ_NAME_cleanup(int type); /* -1 for everything */
51 void OBJ_NAME_do_all(int type, void (*fn) (const OBJ_NAME *, void *arg),
52 void *arg);
53 void OBJ_NAME_do_all_sorted(int type,
54 void (*fn) (const OBJ_NAME *, void *arg),
55 void *arg);
56
57 ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o);
58 ASN1_OBJECT *OBJ_nid2obj(int n);
59 const char *OBJ_nid2ln(int n);
60 const char *OBJ_nid2sn(int n);
61 int OBJ_obj2nid(const ASN1_OBJECT *o);
62 ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name);
63 int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
64 int OBJ_txt2nid(const char *s);
65 int OBJ_ln2nid(const char *s);
66 int OBJ_sn2nid(const char *s);
67 int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
68 const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,
69 int (*cmp) (const void *, const void *));
70 const void *OBJ_bsearch_ex_(const void *key, const void *base, int num,
71 int size,
72 int (*cmp) (const void *, const void *),
73 int flags);
74
75 # define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm) \
76 static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \
77 static int nm##_cmp(type1 const *, type2 const *); \
78 scope type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
79
80 # define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \
81 _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp)
82 # define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \
83 type2 * OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
84
85 /*-
86 * Unsolved problem: if a type is actually a pointer type, like
87 * nid_triple is, then its impossible to get a const where you need
88 * it. Consider:
89 *
90 * typedef int nid_triple[3];
91 * const void *a_;
92 * const nid_triple const *a = a_;
93 *
94 * The assignment discards a const because what you really want is:
95 *
96 * const int const * const *a = a_;
97 *
98 * But if you do that, you lose the fact that a is an array of 3 ints,
99 * which breaks comparison functions.
100 *
101 * Thus we end up having to cast, sadly, or unpack the
102 * declarations. Or, as I finally did in this case, declare nid_triple
103 * to be a struct, which it should have been in the first place.
104 *
105 * Ben, August 2008.
106 *
107 * Also, strictly speaking not all types need be const, but handling
108 * the non-constness means a lot of complication, and in practice
109 * comparison routines do always not touch their arguments.
110 */
111
112 # define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm) \
113 static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \
114 { \
115 type1 const *a = a_; \
116 type2 const *b = b_; \
117 return nm##_cmp(a,b); \
118 } \
119 static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \
120 { \
121 return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \
122 nm##_cmp_BSEARCH_CMP_FN); \
123 } \
124 extern void dummy_prototype(void)
125
126 # define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \
127 static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \
128 { \
129 type1 const *a = a_; \
130 type2 const *b = b_; \
131 return nm##_cmp(a,b); \
132 } \
133 type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \
134 { \
135 return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2), \
136 nm##_cmp_BSEARCH_CMP_FN); \
137 } \
138 extern void dummy_prototype(void)
139
140 # define OBJ_bsearch(type1,key,type2,base,num,cmp) \
141 ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \
142 num,sizeof(type2), \
143 ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \
144 (void)CHECKED_PTR_OF(type2,cmp##_type_2), \
145 cmp##_BSEARCH_CMP_FN)))
146
147 # define OBJ_bsearch_ex(type1,key,type2,base,num,cmp,flags) \
148 ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1,key),CHECKED_PTR_OF(type2,base), \
149 num,sizeof(type2), \
150 ((void)CHECKED_PTR_OF(type1,cmp##_type_1), \
151 (void)type_2=CHECKED_PTR_OF(type2,cmp##_type_2), \
152 cmp##_BSEARCH_CMP_FN)),flags)
153
154 int OBJ_new_nid(int num);
155 int OBJ_add_object(const ASN1_OBJECT *obj);
156 int OBJ_create(const char *oid, const char *sn, const char *ln);
157 #if OPENSSL_API_COMPAT < 0x10100000L
158 # define OBJ_cleanup() while(0) continue
159 #endif
160 int OBJ_create_objects(BIO *in);
161
162 size_t OBJ_length(const ASN1_OBJECT *obj);
163 const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
164
165 int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid);
166 int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid);
167 int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
168 void OBJ_sigid_free(void);
169
170 /* BEGIN ERROR CODES */
171 /*
172 * The following lines are auto generated by the script mkerr.pl. Any changes
173 * made after this point may be overwritten when the script is next run.
174 */
175
176 int ERR_load_OBJ_strings(void);
177
178 /* Error codes for the OBJ functions. */
179
180 /* Function codes. */
181 # define OBJ_F_OBJ_ADD_OBJECT 105
182 # define OBJ_F_OBJ_CREATE 100
183 # define OBJ_F_OBJ_DUP 101
184 # define OBJ_F_OBJ_NAME_NEW_INDEX 106
185 # define OBJ_F_OBJ_NID2LN 102
186 # define OBJ_F_OBJ_NID2OBJ 103
187 # define OBJ_F_OBJ_NID2SN 104
188
189 /* Reason codes. */
190 # define OBJ_R_OID_EXISTS 102
191 # define OBJ_R_UNKNOWN_NID 101
192
193 # ifdef __cplusplus
194 }
195 # endif
196 #endif