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