Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/include/openssl/obj.h

raw
1 // Copyright (C) 1995-1998 Eric Young ([email protected]) All rights reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 #ifndef OPENSSL_HEADER_OBJ_H
5 #define OPENSSL_HEADER_OBJ_H
6
7 #include <openssl/base.h>
8
9 #include <openssl/bytestring.h>
10 #include <openssl/nid.h> // IWYU pragma: export
11
12 #if defined(__cplusplus)
13 extern "C" {
14 #endif
15
16
17 // The objects library deals with the registration and indexing of ASN.1 object
18 // identifiers. These values are often written as a dotted sequence of numbers,
19 // e.g. 1.2.840.113549.1.9.16.3.9.
20 //
21 // Internally, OpenSSL likes to deal with these values by numbering them with
22 // numbers called "nids". OpenSSL has a large, built-in database of common
23 // object identifiers and also has both short and long names for them.
24 //
25 // This library provides functions for translating between object identifiers,
26 // nids, short names and long names.
27 //
28 // The nid values should not be used outside of a single process: they are not
29 // stable identifiers.
30
31
32 // Basic operations.
33
34 // OBJ_dup returns a duplicate copy of |obj| or NULL on allocation failure. The
35 // caller must call |ASN1_OBJECT_free| on the result to release it.
36 OPENSSL_EXPORT ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *obj);
37
38 // OBJ_cmp returns a value less than, equal to or greater than zero if |a| is
39 // less than, equal to or greater than |b|, respectively.
40 OPENSSL_EXPORT int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
41
42 // OBJ_get0_data returns a pointer to the DER representation of |obj|. This is
43 // the contents of the DER-encoded identifier, not including the tag and length.
44 // If |obj| does not have an associated object identifier (i.e. it is a nid-only
45 // value), this value is the empty string.
46 OPENSSL_EXPORT const uint8_t *OBJ_get0_data(const ASN1_OBJECT *obj);
47
48 // OBJ_length returns the length of the DER representation of |obj|. This is the
49 // contents of the DER-encoded identifier, not including the tag and length. If
50 // |obj| does not have an associated object identifier (i.e. it is a nid-only
51 // value), this value is the empty string.
52 OPENSSL_EXPORT size_t OBJ_length(const ASN1_OBJECT *obj);
53
54
55 // Looking up nids.
56
57 // OBJ_obj2nid returns the nid corresponding to |obj|, or |NID_undef| if no
58 // such object is known.
59 OPENSSL_EXPORT int OBJ_obj2nid(const ASN1_OBJECT *obj);
60
61 // OBJ_cbs2nid returns the nid corresponding to the DER data in |cbs|, or
62 // |NID_undef| if no such object is known.
63 OPENSSL_EXPORT int OBJ_cbs2nid(const CBS *cbs);
64
65 // OBJ_sn2nid returns the nid corresponding to |short_name|, or |NID_undef| if
66 // no such short name is known.
67 OPENSSL_EXPORT int OBJ_sn2nid(const char *short_name);
68
69 // OBJ_ln2nid returns the nid corresponding to |long_name|, or |NID_undef| if
70 // no such long name is known.
71 OPENSSL_EXPORT int OBJ_ln2nid(const char *long_name);
72
73 // OBJ_txt2nid returns the nid corresponding to |s|, which may be a short name,
74 // long name, or an ASCII string containing a dotted sequence of numbers. It
75 // returns the nid or NID_undef if unknown.
76 OPENSSL_EXPORT int OBJ_txt2nid(const char *s);
77
78
79 // Getting information about nids.
80
81 // OBJ_nid2obj returns the |ASN1_OBJECT| corresponding to |nid|, or NULL if
82 // |nid| is unknown.
83 //
84 // Although the output is not const, this function returns a static, immutable
85 // |ASN1_OBJECT|. It is not necessary to release the object with
86 // |ASN1_OBJECT_free|.
87 //
88 // However, functions like |X509_ALGOR_set0| expect to take ownership of a
89 // possibly dynamically-allocated |ASN1_OBJECT|. |ASN1_OBJECT_free| is a no-op
90 // for static |ASN1_OBJECT|s, so |OBJ_nid2obj| is compatible with such
91 // functions.
92 //
93 // Callers are encouraged to store the result of this function in a const
94 // pointer. However, if using functions like |X509_ALGOR_set0|, callers may use
95 // a non-const pointer and manage ownership.
96 OPENSSL_EXPORT ASN1_OBJECT *OBJ_nid2obj(int nid);
97
98 // OBJ_get_undef returns the object for |NID_undef|. Prefer this function over
99 // |OBJ_nid2obj| to avoid pulling in the full OID table.
100 OPENSSL_EXPORT const ASN1_OBJECT *OBJ_get_undef(void);
101
102 // OBJ_nid2sn returns the short name for |nid|, or NULL if |nid| is unknown.
103 OPENSSL_EXPORT const char *OBJ_nid2sn(int nid);
104
105 // OBJ_nid2ln returns the long name for |nid|, or NULL if |nid| is unknown.
106 OPENSSL_EXPORT const char *OBJ_nid2ln(int nid);
107
108 // OBJ_nid2cbb writes |nid| as an ASN.1 OBJECT IDENTIFIER to |out|. It returns
109 // one on success or zero otherwise.
110 OPENSSL_EXPORT int OBJ_nid2cbb(CBB *out, int nid);
111
112
113 // Dealing with textual representations of object identifiers.
114
115 // OBJ_txt2obj returns an ASN1_OBJECT for the textual representation in |s|.
116 // If |dont_search_names| is zero, then |s| will be matched against the long
117 // and short names of a known objects to find a match. Otherwise |s| must
118 // contain an ASCII string with a dotted sequence of numbers. The resulting
119 // object need not be previously known. It returns a freshly allocated
120 // |ASN1_OBJECT| or NULL on error.
121 OPENSSL_EXPORT ASN1_OBJECT *OBJ_txt2obj(const char *s, int dont_search_names);
122
123 // OBJ_obj2txt converts |obj| to a textual representation. If
124 // |always_return_oid| is zero then |obj| will be matched against known objects
125 // and the long (preferably) or short name will be used if found. Otherwise
126 // |obj| will be converted into a dotted sequence of integers. If |out| is not
127 // NULL, then at most |out_len| bytes of the textual form will be written
128 // there. If |out_len| is at least one, then string written to |out| will
129 // always be NUL terminated. It returns the number of characters that could
130 // have been written, not including the final NUL, or -1 on error.
131 OPENSSL_EXPORT int OBJ_obj2txt(char *out, int out_len, const ASN1_OBJECT *obj,
132 int always_return_oid);
133
134
135 // Adding objects at runtime.
136
137 // OBJ_create adds a known object and returns the NID of the new object, or
138 // NID_undef on error.
139 //
140 // WARNING: This function modifies global state. The table cannot contain
141 // duplicate OIDs, short names, or long names. If two callers in the same
142 // address space add conflicting values, only one registration will take effect.
143 // Avoid this function if possible. Instead, callers can process OIDs unknown to
144 // BoringSSL by acting on the byte representation directly. See
145 // |ASN1_OBJECT_create|, |OBJ_get0_data|, and |OBJ_length|.
146 OPENSSL_EXPORT int OBJ_create(const char *oid, const char *short_name,
147 const char *long_name);
148
149
150 // Handling signature algorithm identifiers.
151 //
152 // Some NIDs (e.g. sha256WithRSAEncryption) specify both a digest algorithm and
153 // a public key algorithm. The following functions map between pairs of digest
154 // and public-key algorithms and the NIDs that specify their combination.
155 //
156 // Sometimes the combination NID leaves the digest unspecified (e.g.
157 // rsassaPss). In these cases, the digest NID is |NID_undef|.
158
159 // OBJ_find_sigid_algs finds the digest and public-key NIDs that correspond to
160 // the signing algorithm |sign_nid|. If successful, it sets |*out_digest_nid|
161 // and |*out_pkey_nid| and returns one. Otherwise it returns zero. Any of
162 // |out_digest_nid| or |out_pkey_nid| can be NULL if the caller doesn't need
163 // that output value.
164 OPENSSL_EXPORT int OBJ_find_sigid_algs(int sign_nid, int *out_digest_nid,
165 int *out_pkey_nid);
166
167 // OBJ_find_sigid_by_algs finds the signature NID that corresponds to the
168 // combination of |digest_nid| and |pkey_nid|. If success, it sets
169 // |*out_sign_nid| and returns one. Otherwise it returns zero. The
170 // |out_sign_nid| argument can be NULL if the caller only wishes to learn
171 // whether the combination is valid.
172 OPENSSL_EXPORT int OBJ_find_sigid_by_algs(int *out_sign_nid, int digest_nid,
173 int pkey_nid);
174
175
176 // Deprecated functions.
177
178 typedef struct obj_name_st {
179 int type;
180 int alias;
181 const char *name;
182 const char *data;
183 } OBJ_NAME;
184
185 #define OBJ_NAME_TYPE_MD_METH 1
186 #define OBJ_NAME_TYPE_CIPHER_METH 2
187
188 // OBJ_NAME_do_all_sorted calls |callback| zero or more times, each time with
189 // the name of a different primitive. If |type| is |OBJ_NAME_TYPE_MD_METH| then
190 // the primitives will be hash functions, alternatively if |type| is
191 // |OBJ_NAME_TYPE_CIPHER_METH| then the primitives will be ciphers or cipher
192 // modes.
193 //
194 // This function is ill-specified and should never be used.
195 OPENSSL_EXPORT void OBJ_NAME_do_all_sorted(
196 int type, void (*callback)(const OBJ_NAME *, void *arg), void *arg);
197
198
199 // OBJ_cleanup does nothing.
200 OPENSSL_EXPORT void OBJ_cleanup(void);
201
202
203 #if defined(__cplusplus)
204 } // extern C
205 #endif
206
207 #define OBJ_R_UNKNOWN_NID 100
208 #define OBJ_R_INVALID_OID_STRING 101
209
210 #endif // OPENSSL_HEADER_OBJ_H