Coverage Report

Created: 2026-01-09 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/include/openssl/objects.h
Line
Count
Source
1
/*
2
 * Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (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 OPENSSL_OBJECTS_H
11
#define OPENSSL_OBJECTS_H
12
#pragma once
13
14
#include <openssl/macros.h>
15
#ifndef OPENSSL_NO_DEPRECATED_3_0
16
#define HEADER_OBJECTS_H
17
#endif
18
19
#include <openssl/obj_mac.h>
20
#include <openssl/bio.h>
21
#include <openssl/asn1.h>
22
#include <openssl/objectserr.h>
23
24
#define OBJ_NAME_TYPE_UNDEF 0x00
25
564
#define OBJ_NAME_TYPE_MD_METH 0x01
26
1.27k
#define OBJ_NAME_TYPE_CIPHER_METH 0x02
27
#define OBJ_NAME_TYPE_PKEY_METH 0x03
28
#define OBJ_NAME_TYPE_COMP_METH 0x04
29
#define OBJ_NAME_TYPE_MAC_METH 0x05
30
0
#define OBJ_NAME_TYPE_KDF_METH 0x06
31
#define OBJ_NAME_TYPE_NUM 0x07
32
33
5.80k
#define OBJ_NAME_ALIAS 0x8000
34
35
#define OBJ_BSEARCH_VALUE_ON_NOMATCH 0x01
36
#define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH 0x02
37
38
#ifdef __cplusplus
39
extern "C" {
40
#endif
41
42
typedef struct obj_name_st {
43
    int type;
44
    int alias;
45
    const char *name;
46
    const char *data;
47
} OBJ_NAME;
48
49
#define OBJ_create_and_add_object(a, b, c) OBJ_create(a, b, c)
50
51
int OBJ_NAME_init(void);
52
int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
53
    int (*cmp_func)(const char *, const char *),
54
    void (*free_func)(const char *, int, const char *));
55
const char *OBJ_NAME_get(const char *name, int type);
56
int OBJ_NAME_add(const char *name, int type, const char *data);
57
int OBJ_NAME_remove(const char *name, int type);
58
void OBJ_NAME_cleanup(int type); /* -1 for everything */
59
void OBJ_NAME_do_all(int type, void (*fn)(const OBJ_NAME *, void *arg),
60
    void *arg);
61
void OBJ_NAME_do_all_sorted(int type,
62
    void (*fn)(const OBJ_NAME *, void *arg),
63
    void *arg);
64
65
DECLARE_ASN1_DUP_FUNCTION_name(ASN1_OBJECT, OBJ)
66
ASN1_OBJECT *OBJ_nid2obj(int n);
67
const char *OBJ_nid2ln(int n);
68
const char *OBJ_nid2sn(int n);
69
int OBJ_obj2nid(const ASN1_OBJECT *o);
70
ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name);
71
int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
72
int OBJ_txt2nid(const char *s);
73
int OBJ_ln2nid(const char *s);
74
int OBJ_sn2nid(const char *s);
75
int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
76
const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,
77
    int (*cmp)(const void *, const void *));
78
const void *OBJ_bsearch_ex_(const void *key, const void *base, int num,
79
    int size,
80
    int (*cmp)(const void *, const void *),
81
    int flags);
82
83
#define _DECLARE_OBJ_BSEARCH_CMP_FN(scope, type1, type2, nm)        \
84
    static int nm##_cmp_BSEARCH_CMP_FN(const void *, const void *); \
85
    static int nm##_cmp(type1 const *, type2 const *);              \
86
    scope type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
87
88
#define DECLARE_OBJ_BSEARCH_CMP_FN(type1, type2, cmp) \
89
    _DECLARE_OBJ_BSEARCH_CMP_FN(static, type1, type2, cmp)
90
#define DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm) \
91
    type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)
92
93
/*-
94
 * Unsolved problem: if a type is actually a pointer type, like
95
 * nid_triple is, then its impossible to get a const where you need
96
 * it. Consider:
97
 *
98
 * typedef int nid_triple[3];
99
 * const void *a_;
100
 * const nid_triple const *a = a_;
101
 *
102
 * The assignment discards a const because what you really want is:
103
 *
104
 * const int const * const *a = a_;
105
 *
106
 * But if you do that, you lose the fact that a is an array of 3 ints,
107
 * which breaks comparison functions.
108
 *
109
 * Thus we end up having to cast, sadly, or unpack the
110
 * declarations. Or, as I finally did in this case, declare nid_triple
111
 * to be a struct, which it should have been in the first place.
112
 *
113
 * Ben, August 2008.
114
 *
115
 * Also, strictly speaking not all types need be const, but handling
116
 * the non-constness means a lot of complication, and in practice
117
 * comparison routines do always not touch their arguments.
118
 */
119
120
#define IMPLEMENT_OBJ_BSEARCH_CMP_FN(type1, type2, nm)                     \
121
    static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_)     \
122
0
    {                                                                      \
123
0
        type1 const *a = a_;                                               \
124
0
        type2 const *b = b_;                                               \
125
0
        return nm##_cmp(a, b);                                             \
126
0
    }                                                                      \
Unexecuted instantiation: obj_dat.c:ln_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: obj_dat.c:sn_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: obj_dat.c:obj_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: obj_xref.c:sig_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: obj_xref.c:sigx_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: a_strnid.c:table_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: ameth_lib.c:ameth_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: evp_pbe.c:pbe2_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: v3_purp.c:nid_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: x509_vpm.c:table_cmp_BSEARCH_CMP_FN
Unexecuted instantiation: v3_lib.c:ext_cmp_BSEARCH_CMP_FN
127
    static type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num) \
128
0
    {                                                                      \
129
0
        return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2),        \
130
0
            nm##_cmp_BSEARCH_CMP_FN);                                      \
131
0
    }                                                                      \
Unexecuted instantiation: obj_dat.c:OBJ_bsearch_ln
Unexecuted instantiation: obj_dat.c:OBJ_bsearch_sn
Unexecuted instantiation: obj_dat.c:OBJ_bsearch_obj
Unexecuted instantiation: obj_xref.c:OBJ_bsearch_sig
Unexecuted instantiation: obj_xref.c:OBJ_bsearch_sigx
Unexecuted instantiation: a_strnid.c:OBJ_bsearch_table
Unexecuted instantiation: ameth_lib.c:OBJ_bsearch_ameth
Unexecuted instantiation: evp_pbe.c:OBJ_bsearch_pbe2
Unexecuted instantiation: v3_purp.c:OBJ_bsearch_nid
Unexecuted instantiation: x509_vpm.c:OBJ_bsearch_table
Unexecuted instantiation: v3_lib.c:OBJ_bsearch_ext
132
    extern void dummy_prototype(void)
133
134
#define IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(type1, type2, nm)          \
135
    static int nm##_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) \
136
    {                                                                  \
137
        type1 const *a = a_;                                           \
138
        type2 const *b = b_;                                           \
139
        return nm##_cmp(a, b);                                         \
140
    }                                                                  \
141
    type2 *OBJ_bsearch_##nm(type1 *key, type2 const *base, int num)    \
142
    {                                                                  \
143
        return (type2 *)OBJ_bsearch_(key, base, num, sizeof(type2),    \
144
            nm##_cmp_BSEARCH_CMP_FN);                                  \
145
    }                                                                  \
146
    extern void dummy_prototype(void)
147
148
#define OBJ_bsearch(type1, key, type2, base, num, cmp)                              \
149
    ((type2 *)OBJ_bsearch_(CHECKED_PTR_OF(type1, key), CHECKED_PTR_OF(type2, base), \
150
        num, sizeof(type2),                                                         \
151
        ((void)CHECKED_PTR_OF(type1, cmp##_type_1),                                 \
152
            (void)CHECKED_PTR_OF(type2, cmp##_type_2),                              \
153
            cmp##_BSEARCH_CMP_FN)))
154
155
#define OBJ_bsearch_ex(type1, key, type2, base, num, cmp, flags)                       \
156
    ((type2 *)OBJ_bsearch_ex_(CHECKED_PTR_OF(type1, key), CHECKED_PTR_OF(type2, base), \
157
         num, sizeof(type2),                                                           \
158
         ((void)CHECKED_PTR_OF(type1, cmp##_type_1),                                   \
159
             (void)type_2 = CHECKED_PTR_OF(type2, cmp##_type_2),                       \
160
             cmp##_BSEARCH_CMP_FN)),                                                   \
161
        flags)
162
163
int OBJ_new_nid(int num);
164
int OBJ_add_object(const ASN1_OBJECT *obj);
165
int OBJ_create(const char *oid, const char *sn, const char *ln);
166
#ifndef OPENSSL_NO_DEPRECATED_1_1_0
167
#define OBJ_cleanup() \
168
    while (0)         \
169
    continue
170
#endif
171
int OBJ_create_objects(BIO *in);
172
173
size_t OBJ_length(const ASN1_OBJECT *obj);
174
const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
175
176
int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid);
177
int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid);
178
int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
179
void OBJ_sigid_free(void);
180
181
#define SN_ac_auditEntity SN_ac_auditIdentity
182
183
#ifdef __cplusplus
184
}
185
#endif
186
#endif