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