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