/src/boringssl/crypto/asn1/internal.h
Line | Count | Source |
1 | | // Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef OPENSSL_HEADER_CRYPTO_ASN1_INTERNAL_H |
16 | | #define OPENSSL_HEADER_CRYPTO_ASN1_INTERNAL_H |
17 | | |
18 | | #include <time.h> |
19 | | |
20 | | #include <openssl/asn1.h> |
21 | | #include <openssl/asn1t.h> |
22 | | #include <openssl/span.h> |
23 | | |
24 | | #include "../internal.h" |
25 | | |
26 | | |
27 | | BSSL_NAMESPACE_BEGIN |
28 | | |
29 | | // Wrapper functions for time functions. |
30 | | |
31 | | // OPENSSL_gmtime converts a time_t value in `time` which must be in the range |
32 | | // of year 0000 to 9999 to a broken out time value in `tm`. On success `tm` is |
33 | | // returned. On failure NULL is returned. |
34 | | OPENSSL_EXPORT struct tm *OPENSSL_gmtime(const time_t *time, struct tm *result); |
35 | | |
36 | | // OPENSSL_gmtime_adj returns one on success, and updates `tm` by adding |
37 | | // `offset_day` days and `offset_sec` seconds. It returns zero on failure. `tm` |
38 | | // must be in the range of year 0000 to 9999 both before and after the update or |
39 | | // a failure will be returned. |
40 | | OPENSSL_EXPORT int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, |
41 | | int64_t offset_sec); |
42 | | |
43 | | // OPENSSL_gmtime_diff calculates the difference between `from` and `to`. It |
44 | | // returns one, and outputs the difference as a number of days and seconds in |
45 | | // `*out_days` and `*out_secs` on success. It returns zero on failure. Both |
46 | | // `from` and `to` must be in the range of year 0000 to 9999 or a failure will |
47 | | // be returned. |
48 | | OPENSSL_EXPORT int OPENSSL_gmtime_diff(int *out_days, int *out_secs, |
49 | | const struct tm *from, |
50 | | const struct tm *to); |
51 | | |
52 | | |
53 | | // Object identifiers. |
54 | | |
55 | | // These are used internally in the ASN1_OBJECT to keep track of |
56 | | // whether the names and data need to be free()ed |
57 | 12.8M | #define ASN1_OBJECT_FLAG_DYNAMIC 0x01 // internal use |
58 | 8.65M | #define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 // internal use |
59 | 8.65M | #define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 // internal use |
60 | | |
61 | | BSSL_NAMESPACE_END |
62 | | |
63 | | // An asn1_object_st (aka `ASN1_OBJECT`) represents an ASN.1 OBJECT IDENTIFIER. |
64 | | // Note: Mutating an `ASN1_OBJECT` is only permitted when initializing it. The |
65 | | // library maintains a table of static `ASN1_OBJECT`s, which may be referenced |
66 | | // by non-const `ASN1_OBJECT` pointers. Code which receives an `ASN1_OBJECT` |
67 | | // pointer externally must assume it is immutable, even if the pointer is not |
68 | | // const. |
69 | | struct asn1_object_st { |
70 | | const char *sn, *ln; |
71 | | int nid; |
72 | | int length; |
73 | | const unsigned char *data; // data remains const after init |
74 | | int flags; // Should we free this one |
75 | | }; |
76 | | |
77 | | BSSL_NAMESPACE_BEGIN |
78 | | |
79 | | ASN1_OBJECT *ASN1_OBJECT_new(); |
80 | | |
81 | | // asn1_parse_object parses a DER-encoded ASN.1 OBJECT IDENTIFIER from `cbs` and |
82 | | // write the result to `out`. If `tag` is non-zero, the value is implicitly |
83 | | // tagged with `tag`. On success, it returns a newly-allocated `ASN1_OBJECT` |
84 | | // with the result and advances `cbs` past the parsed element. |
85 | | // |
86 | | // TODO(crbug.com/boringssl/414361735): This should return a bssl::UniquePtr, |
87 | | // but cannot until it is made C++ linkage. |
88 | | ASN1_OBJECT *asn1_parse_object(CBS *cbs, CBS_ASN1_TAG tag); |
89 | | |
90 | | // asn1_marshal_object marshals `in` as a DER-encoded, ASN.1 OBJECT IDENTIFIER |
91 | | // and writes the result to `out`. It returns one on success and zero on error. |
92 | | // If `tag` is non-zero, the tag is replaced with `tag`. |
93 | | int asn1_marshal_object(CBB *out, const ASN1_OBJECT *in, CBS_ASN1_TAG tag); |
94 | | |
95 | | |
96 | | // Strings. |
97 | | |
98 | | // asn1_is_printable returns one if `value` is a valid Unicode codepoint for an |
99 | | // ASN.1 PrintableString, and zero otherwise. |
100 | | int asn1_is_printable(uint32_t value); |
101 | | |
102 | | // asn1_string_init initializes `str`, which may be uninitialized, with type |
103 | | // `type`. |
104 | | void asn1_string_init(ASN1_STRING *str, int type); |
105 | | |
106 | | // asn1_string_cleanup releases memory associated with `str`'s value, without |
107 | | // freeing `str` itself. |
108 | | void asn1_string_cleanup(ASN1_STRING *str); |
109 | | |
110 | | // A ScopedASN1String is a stack-allocatable `ASN1_STRING` with managed |
111 | | // lifetime. |
112 | | // TODO(crbug.com/443769299): Once `ASN1_STRING` is no longer public, this can |
113 | | // instead use `DECLARE_OPAQUE_STRUCT`. |
114 | | class ScopedASN1String { |
115 | | public: |
116 | 2.02M | explicit ScopedASN1String(int type) { asn1_string_init(&str_, type); } |
117 | | ScopedASN1String(const ScopedASN1String &) = delete; |
118 | | ScopedASN1String &operator=(const ScopedASN1String &) = delete; |
119 | 2.02M | ~ScopedASN1String() { asn1_string_cleanup(&str_); } |
120 | | |
121 | 1.85M | ASN1_STRING *get() { return &str_; } |
122 | 2.11M | const ASN1_STRING *get() const { return &str_; } |
123 | 0 | ASN1_STRING *operator->() { return &str_; } |
124 | 0 | const ASN1_STRING *operator->() const { return &str_; } |
125 | | |
126 | | private: |
127 | | ASN1_STRING str_; |
128 | | }; |
129 | | |
130 | | // asn1_parse_string_unchecked parses a DER-encoded string of type `str_type`, |
131 | | // tagged with `tag`. It does not check the contents. |
132 | | int asn1_parse_string_unchecked(CBS *cbs, ASN1_STRING *out, int str_type, |
133 | | CBS_ASN1_TAG tag); |
134 | | |
135 | | // The following functions parse a DER-encoded ASN.1 value of the specified |
136 | | // type from `cbs` and write the result to `*out`. If `tag` is non-zero, the |
137 | | // value is implicitly tagged with `tag`. On success, they return one and |
138 | | // advance `cbs` past the parsed element. On entry, `*out` must contain an |
139 | | // `ASN1_STRING` in some valid state. |
140 | | int asn1_parse_bit_string(CBS *cbs, ASN1_BIT_STRING *out, CBS_ASN1_TAG tag); |
141 | | int asn1_parse_integer(CBS *cbs, ASN1_INTEGER *out, CBS_ASN1_TAG tag); |
142 | | int asn1_parse_enumerated(CBS *cbs, ASN1_ENUMERATED *out, CBS_ASN1_TAG tag); |
143 | | int asn1_parse_octet_string(CBS *cbs, ASN1_STRING *out, CBS_ASN1_TAG tag); |
144 | | int asn1_parse_t61_string(CBS *cbs, ASN1_STRING *out, CBS_ASN1_TAG tag); |
145 | | int asn1_parse_bmp_string(CBS *cbs, ASN1_BMPSTRING *out, CBS_ASN1_TAG tag); |
146 | | int asn1_parse_universal_string(CBS *cbs, ASN1_UNIVERSALSTRING *out, |
147 | | CBS_ASN1_TAG tag); |
148 | | int asn1_parse_utf8_string(CBS *cbs, ASN1_UNIVERSALSTRING *out, |
149 | | CBS_ASN1_TAG tag); |
150 | | int asn1_parse_generalized_time(CBS *cbs, ASN1_GENERALIZEDTIME *out, |
151 | | CBS_ASN1_TAG tag); |
152 | | int asn1_parse_utc_time(CBS *cbs, ASN1_UTCTIME *out, CBS_ASN1_TAG tag, |
153 | | int allow_timezone_offset); |
154 | | |
155 | | // asn1_parse_bit_string_with_bad_length behaves like `asn1_parse_bit_string` |
156 | | // but tolerates BER non-minimal, definite lengths. |
157 | | int asn1_parse_bit_string_with_bad_length(CBS *cbs, ASN1_BIT_STRING *out); |
158 | | |
159 | | // asn1_marshal_bit_string marshals `in` as a DER-encoded, ASN.1 BIT STRING and |
160 | | // writes the result to `out`. It returns one on success and zero on error. If |
161 | | // `tag` is non-zero, the tag is replaced with `tag`. |
162 | | int asn1_marshal_bit_string(CBB *out, const ASN1_BIT_STRING *in, |
163 | | CBS_ASN1_TAG tag); |
164 | | |
165 | | // asn1_marshal_integer marshals `in` as a DER-encoded, ASN.1 INTEGER and writes |
166 | | // the result to `out`. It returns one on success and zero on error. If `tag` is |
167 | | // non-zero, the tag is replaced with `tag`. This can also be used to marshal an |
168 | | // ASN.1 ENUMERATED value by overriding the tag. |
169 | | int asn1_marshal_integer(CBB *out, const ASN1_INTEGER *in, CBS_ASN1_TAG tag); |
170 | | |
171 | | // asn1_marshal_octet_string marshals `in` as a DER-encoded, ASN.1 OCTET STRING |
172 | | // and writes the result to `out`. It returns one on success and zero on error. |
173 | | // If `tag` is non-zero, the tag is replaced with `tag`. |
174 | | // |
175 | | // This function may be used to marshal other string-based universal types whose |
176 | | // encoding is that of an implicitly-tagged OCTET STRING, e.g. UTF8String. |
177 | | int asn1_marshal_octet_string(CBB *out, const ASN1_STRING *in, |
178 | | CBS_ASN1_TAG tag); |
179 | | |
180 | | OPENSSL_EXPORT int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d, |
181 | | int allow_timezone_offset); |
182 | | OPENSSL_EXPORT int asn1_generalizedtime_to_tm(struct tm *tm, |
183 | | const ASN1_GENERALIZEDTIME *d); |
184 | | |
185 | | int asn1_parse_time(CBS *cbs, ASN1_TIME *out, int allow_utc_timezone_offset); |
186 | | int asn1_marshal_time(CBB *cbb, const ASN1_TIME *in); |
187 | | |
188 | | |
189 | | // The ASN.1 ANY type. |
190 | | |
191 | | // asn1_type_value_as_pointer returns `a`'s value in pointer form. This is |
192 | | // usually the value object but, for BOOLEAN values, is 0 or 0xff cast to |
193 | | // a pointer. |
194 | | const void *asn1_type_value_as_pointer(const ASN1_TYPE *a); |
195 | | |
196 | | // asn1_type_set0_string sets `a`'s value to the object represented by `str` and |
197 | | // takes ownership of `str`. |
198 | | void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str); |
199 | | |
200 | | // asn1_parse_any parses a DER-encoded ASN.1 value of any type from `cbs` and |
201 | | // writes the result to `*out`. On success, it advances `cbs` past the parsed |
202 | | // element and returns one. On entry, `*out` must contain an `ASN1_TYPE` in some |
203 | | // valid state. |
204 | | int asn1_parse_any(CBS *cbs, ASN1_TYPE *out); |
205 | | |
206 | | // asn1_parse_any_as_string behaves like `asn1_parse_any` but represents the |
207 | | // value as an `ASN1_STRING`. Types which are not represented with |
208 | | // `ASN1_STRING`, such as `ASN1_OBJECT`, are represented with type |
209 | | // `V_ASN1_OTHER`. |
210 | | int asn1_parse_any_as_string(CBS *cbs, ASN1_STRING *out); |
211 | | |
212 | | // asn1_marshal_any marshals `in` as a DER-encoded ASN.1 value and writes the |
213 | | // result to `out`. It returns one on success and zero on error. |
214 | | int asn1_marshal_any(CBB *out, const ASN1_TYPE *in); |
215 | | |
216 | | // asn1_marshal_any_string marshals `in` as a DER-encoded ASN.1 value and writes |
217 | | // the result to `out`. It returns one on success and zero on error. |
218 | | int asn1_marshal_any_string(CBB *out, const ASN1_STRING *in); |
219 | | |
220 | | |
221 | | // Support structures for the template-based encoder. |
222 | | |
223 | | // ASN1_ENCODING is used to save the received encoding of an ASN.1 type. This |
224 | | // avoids problems with invalid encodings that break signatures. |
225 | | typedef struct ASN1_ENCODING_st { |
226 | | // enc is the saved DER encoding. Its ownership is determined by `buf`. |
227 | | uint8_t *enc; |
228 | | // len is the length of `enc`. If zero, there is no saved encoding. |
229 | | size_t len; |
230 | | } ASN1_ENCODING; |
231 | | |
232 | | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); |
233 | | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); |
234 | | |
235 | | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); |
236 | | |
237 | | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it); |
238 | | |
239 | | // asn1_load_ptr returns `*pval`, but without asserting `*pval`'s underlying |
240 | | // type for strict aliasing. This helper must be used when the field's |
241 | | // underlying type is not known statically. It must not be used for |
242 | | // `ASN1_BOOLEAN` fields, which are not a pointers. |
243 | 23.9M | inline ASN1_VALUE *asn1_load_ptr(ASN1_VALUE **pval) { |
244 | 23.9M | ASN1_VALUE *ret; |
245 | 23.9M | OPENSSL_memcpy(&ret, pval, sizeof(ASN1_VALUE *)); |
246 | 23.9M | return ret; |
247 | 23.9M | } |
248 | | |
249 | | // asn1_load_ptr_as behaves like `asn1_load_ptr`, but casts the result to `T*`. |
250 | | template <typename T> |
251 | 4.74M | inline T *asn1_load_ptr_as(ASN1_VALUE **pval) { |
252 | 4.74M | return reinterpret_cast<T *>(asn1_load_ptr(pval)); |
253 | 4.74M | } Unexecuted instantiation: X509_algor_st* bssl::asn1_load_ptr_as<X509_algor_st>(ASN1_VALUE_st**) Unexecuted instantiation: bssl::X509_CRL_INFO* bssl::asn1_load_ptr_as<bssl::X509_CRL_INFO>(ASN1_VALUE_st**) Unexecuted instantiation: X509_crl_st* bssl::asn1_load_ptr_as<X509_crl_st>(ASN1_VALUE_st**) X509_name_entry_st* bssl::asn1_load_ptr_as<X509_name_entry_st>(ASN1_VALUE_st**) Line | Count | Source | 251 | 11.4k | inline T *asn1_load_ptr_as(ASN1_VALUE **pval) { | 252 | 11.4k | return reinterpret_cast<T *>(asn1_load_ptr(pval)); | 253 | 11.4k | } |
X509_name_st* bssl::asn1_load_ptr_as<X509_name_st>(ASN1_VALUE_st**) Line | Count | Source | 251 | 15.6k | inline T *asn1_load_ptr_as(ASN1_VALUE **pval) { | 252 | 15.6k | return reinterpret_cast<T *>(asn1_load_ptr(pval)); | 253 | 15.6k | } |
Unexecuted instantiation: X509_pubkey_st* bssl::asn1_load_ptr_as<X509_pubkey_st>(ASN1_VALUE_st**) Unexecuted instantiation: bssl::X509_REQ_INFO* bssl::asn1_load_ptr_as<bssl::X509_REQ_INFO>(ASN1_VALUE_st**) Unexecuted instantiation: x509_st* bssl::asn1_load_ptr_as<x509_st>(ASN1_VALUE_st**) stack_st_ASN1_VALUE* bssl::asn1_load_ptr_as<stack_st_ASN1_VALUE>(ASN1_VALUE_st**) Line | Count | Source | 251 | 450k | inline T *asn1_load_ptr_as(ASN1_VALUE **pval) { | 252 | 450k | return reinterpret_cast<T *>(asn1_load_ptr(pval)); | 253 | 450k | } |
asn1_type_st* bssl::asn1_load_ptr_as<asn1_type_st>(ASN1_VALUE_st**) Line | Count | Source | 251 | 168k | inline T *asn1_load_ptr_as(ASN1_VALUE **pval) { | 252 | 168k | return reinterpret_cast<T *>(asn1_load_ptr(pval)); | 253 | 168k | } |
asn1_object_st* bssl::asn1_load_ptr_as<asn1_object_st>(ASN1_VALUE_st**) Line | Count | Source | 251 | 1.36M | inline T *asn1_load_ptr_as(ASN1_VALUE **pval) { | 252 | 1.36M | return reinterpret_cast<T *>(asn1_load_ptr(pval)); | 253 | 1.36M | } |
asn1_string_st* bssl::asn1_load_ptr_as<asn1_string_st>(ASN1_VALUE_st**) Line | Count | Source | 251 | 2.73M | inline T *asn1_load_ptr_as(ASN1_VALUE **pval) { | 252 | 2.73M | return reinterpret_cast<T *>(asn1_load_ptr(pval)); | 253 | 2.73M | } |
Unexecuted instantiation: rsa_pss_params_st* bssl::asn1_load_ptr_as<rsa_pss_params_st>(ASN1_VALUE_st**) |
254 | | |
255 | | // asn1_store_ptr sets `*pval` to `v`, but without asserting `*pval`'s |
256 | | // underlying type for strict aliasing. This helper must be used when the |
257 | | // field's underlying type is not known statically. It must not be used for |
258 | | // `ASN1_BOOLEAN` fields, which are not a pointers. |
259 | 7.62M | inline void asn1_store_ptr(ASN1_VALUE **pval, const void *v) { |
260 | 7.62M | OPENSSL_memcpy(pval, &v, sizeof(v)); |
261 | 7.62M | } |
262 | | |
263 | | // asn1_get_choice_selector returns the CHOICE selector value for `*pval`, which |
264 | | // must of type `it`. |
265 | | int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it); |
266 | | |
267 | | int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it); |
268 | | |
269 | | // asn1_get_field_ptr returns a pointer to the field in `*pval` corresponding to |
270 | | // `tt`. |
271 | | ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); |
272 | | |
273 | | // asn1_do_adb returns the `ASN1_TEMPLATE` for the ANY DEFINED BY field `tt`, |
274 | | // based on the selector INTEGER or OID in `*pval`. If `tt` is not an ADB field, |
275 | | // it returns `tt`. If the selector does not match any value, it returns NULL. |
276 | | // If `nullerr` is non-zero, it will additionally push an error to the error |
277 | | // queue when there is no match. |
278 | | const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, |
279 | | int nullerr); |
280 | | |
281 | | void asn1_refcount_set_one(ASN1_VALUE **pval, const ASN1_ITEM *it); |
282 | | int asn1_refcount_dec_and_test_zero(ASN1_VALUE **pval, const ASN1_ITEM *it); |
283 | | |
284 | | void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); |
285 | | void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); |
286 | | |
287 | | // asn1_enc_restore, if `*pval` has a saved encoding, sets `*out` to it, and |
288 | | // returns one. If it has no saved encoding, it returns zero. |
289 | | int asn1_enc_restore(Span<const uint8_t> *out, ASN1_VALUE **pval, |
290 | | const ASN1_ITEM *it); |
291 | | |
292 | | // asn1_enc_save saves `inlen` bytes from `in` as `*pval`'s saved encoding. It |
293 | | // returns one on success and zero on error. If `buf` is non-NULL, `in` must |
294 | | // point into `buf`. |
295 | | int asn1_enc_save(ASN1_VALUE **pval, const uint8_t *in, size_t inlen, |
296 | | const ASN1_ITEM *it); |
297 | | |
298 | | // asn1_encoding_clear clears the cached encoding in `enc`. |
299 | | void asn1_encoding_clear(ASN1_ENCODING *enc); |
300 | | |
301 | | // asn1_tag_to_cbs converts a tag from this library's representation (the |
302 | | // `V_ASN1_*` constants) to that of `CBS` and `CBB`. It returns the tag on |
303 | | // success and zero if the input could not be represented. (Zero would be |
304 | | // [UNIVERSAL 0], which is a reserved tag value.) |
305 | | // |
306 | | // The resulting tag will not have the constructed bit set. The caller must OR |
307 | | // the result with `CBS_ASN1_CONSTRUCTED` if necessary, before passing to |
308 | | // `CBS` and `CBB` functions. |
309 | | CBS_ASN1_TAG asn1_tag_to_cbs(int aclass, int tag); |
310 | | |
311 | | typedef struct { |
312 | | int nid; |
313 | | long minsize; |
314 | | long maxsize; |
315 | | unsigned long mask; |
316 | | unsigned long flags; |
317 | | } ASN1_STRING_TABLE; |
318 | | |
319 | | // asn1_get_string_table_for_testing sets `*out_ptr` and `*out_len` to the table |
320 | | // of built-in `ASN1_STRING_TABLE` values. It is exported for testing. |
321 | | OPENSSL_EXPORT void asn1_get_string_table_for_testing( |
322 | | const ASN1_STRING_TABLE **out_ptr, size_t *out_len); |
323 | | |
324 | | typedef ASN1_VALUE *ASN1_new_func(); |
325 | | typedef void ASN1_free_func(ASN1_VALUE *a); |
326 | | typedef ASN1_VALUE *ASN1_d2i_func(ASN1_VALUE **a, const unsigned char **in, |
327 | | long length); |
328 | | typedef int ASN1_i2d_func(ASN1_VALUE *a, unsigned char **in); |
329 | | |
330 | | // An ASN1_ex_parse function should parse a value from `cbs` and set `*pval` to |
331 | | // the result. It should return one on success and zero on failure. If `opt` is |
332 | | // non-zero, the field may be optional. If an optional element is missing, the |
333 | | // function should return one and consume zero bytes from `cbs`. |
334 | | // |
335 | | // If `opt` is non-zero, the function can assume that `*pval` is nullptr on |
336 | | // entry. Otherwise, `*pval` may either be nullptr, or the result of |
337 | | // `ASN1_ex_new_func`. The function may either write into the existing object, |
338 | | // if any, or unconditionally make a new one. (The existing object comes from |
339 | | // tasn_new.cc recursively filling in objects before parsing into them.) |
340 | | typedef int ASN1_ex_parse(ASN1_VALUE **pval, CBS *cbs, const ASN1_ITEM *it, |
341 | | int opt); |
342 | | |
343 | | // An ASN1_ex_marshal function should marshal `*pval`, a value of type `it`, to |
344 | | // `cbb` and return one on success or zero on error. |
345 | | typedef int ASN1_ex_marshal(CBB *cbb, ASN1_VALUE **pval, const ASN1_ITEM *it); |
346 | | |
347 | | typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); |
348 | | typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); |
349 | | |
350 | | typedef struct ASN1_EXTERN_FUNCS_st { |
351 | | ASN1_ex_new_func *asn1_ex_new; |
352 | | ASN1_ex_free_func *asn1_ex_free; |
353 | | ASN1_ex_parse *asn1_ex_parse; |
354 | | ASN1_ex_marshal *asn1_ex_marshal; |
355 | | } ASN1_EXTERN_FUNCS; |
356 | | |
357 | | // IMPLEMENT_EXTERN_ASN1_PARSE_NEW implements an `ASN1_ITEM` for a type whose |
358 | | // parse function returns a new object. |
359 | | #define IMPLEMENT_EXTERN_ASN1_PARSE_NEW(name, new_func, free_func, tag, \ |
360 | | parse_func, marshal_func) \ |
361 | | namespace { \ |
362 | 0 | int name##_new_cb(ASN1_VALUE **pval, const ASN1_ITEM *it) { \ |
363 | 0 | name *obj = new_func(); \ |
364 | 0 | if (obj == nullptr) { \ |
365 | 0 | return 0; \ |
366 | 0 | } \ |
367 | 0 | asn1_store_ptr(pval, obj); \ |
368 | 0 | return 1; \ |
369 | 0 | } \ Unexecuted instantiation: x_algor.cc:(anonymous namespace)::X509_ALGOR_new_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) Unexecuted instantiation: x_name.cc:bssl::(anonymous namespace)::X509_NAME_ENTRY_new_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) Unexecuted instantiation: x_name.cc:(anonymous namespace)::X509_NAME_new_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) Unexecuted instantiation: x_pubkey.cc:bssl::(anonymous namespace)::X509_PUBKEY_new_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) Unexecuted instantiation: x_x509.cc:(anonymous namespace)::X509_new_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) |
370 | | \ |
371 | 17.9k | void name##_free_cb(ASN1_VALUE **pval, const ASN1_ITEM *it) { \ |
372 | 17.9k | free_func(asn1_load_ptr_as<name>(pval)); \ |
373 | 17.9k | asn1_store_ptr(pval, nullptr); \ |
374 | 17.9k | } \ Unexecuted instantiation: x_algor.cc:(anonymous namespace)::X509_ALGOR_free_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) x_name.cc:bssl::(anonymous namespace)::X509_NAME_ENTRY_free_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) Line | Count | Source | 371 | 5.95k | void name##_free_cb(ASN1_VALUE **pval, const ASN1_ITEM *it) { \ | 372 | 5.95k | free_func(asn1_load_ptr_as<name>(pval)); \ | 373 | 5.95k | asn1_store_ptr(pval, nullptr); \ | 374 | 5.95k | } \ |
x_name.cc:(anonymous namespace)::X509_NAME_free_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) Line | Count | Source | 371 | 11.9k | void name##_free_cb(ASN1_VALUE **pval, const ASN1_ITEM *it) { \ | 372 | 11.9k | free_func(asn1_load_ptr_as<name>(pval)); \ | 373 | 11.9k | asn1_store_ptr(pval, nullptr); \ | 374 | 11.9k | } \ |
Unexecuted instantiation: x_pubkey.cc:bssl::(anonymous namespace)::X509_PUBKEY_free_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) Unexecuted instantiation: x_x509.cc:(anonymous namespace)::X509_free_cb(ASN1_VALUE_st**, ASN1_ITEM_st const*) |
375 | | \ |
376 | | int name##_parse_cb(ASN1_VALUE **pval, CBS *cbs, const ASN1_ITEM *it, \ |
377 | 4.00k | int opt) { \ |
378 | 4.00k | if (opt && !CBS_peek_asn1_tag(cbs, (tag))) { \ |
379 | 0 | return 1; \ |
380 | 0 | } \ |
381 | 4.00k | \ |
382 | 4.00k | bssl::UniquePtr<name> ret = parse_func(cbs); \ |
383 | 4.00k | if (ret == nullptr) { \ |
384 | 497 | return 0; \ |
385 | 497 | } \ |
386 | 4.00k | name##_free_cb(pval, it); \ |
387 | 3.51k | asn1_store_ptr(pval, ret.release()); \ |
388 | 3.51k | return 1; \ |
389 | 4.00k | } \ Unexecuted instantiation: x_algor.cc:(anonymous namespace)::X509_ALGOR_parse_cb(ASN1_VALUE_st**, cbs_st*, ASN1_ITEM_st const*, int) x_name.cc:bssl::(anonymous namespace)::X509_NAME_ENTRY_parse_cb(ASN1_VALUE_st**, cbs_st*, ASN1_ITEM_st const*, int) Line | Count | Source | 377 | 214 | int opt) { \ | 378 | 214 | if (opt && !CBS_peek_asn1_tag(cbs, (tag))) { \ | 379 | 0 | return 1; \ | 380 | 0 | } \ | 381 | 214 | \ | 382 | 214 | bssl::UniquePtr<name> ret = parse_func(cbs); \ | 383 | 214 | if (ret == nullptr) { \ | 384 | 38 | return 0; \ | 385 | 38 | } \ | 386 | 214 | name##_free_cb(pval, it); \ | 387 | 176 | asn1_store_ptr(pval, ret.release()); \ | 388 | 176 | return 1; \ | 389 | 214 | } \ |
x_name.cc:(anonymous namespace)::X509_NAME_parse_cb(ASN1_VALUE_st**, cbs_st*, ASN1_ITEM_st const*, int) Line | Count | Source | 377 | 3.79k | int opt) { \ | 378 | 3.79k | if (opt && !CBS_peek_asn1_tag(cbs, (tag))) { \ | 379 | 0 | return 1; \ | 380 | 0 | } \ | 381 | 3.79k | \ | 382 | 3.79k | bssl::UniquePtr<name> ret = parse_func(cbs); \ | 383 | 3.79k | if (ret == nullptr) { \ | 384 | 459 | return 0; \ | 385 | 459 | } \ | 386 | 3.79k | name##_free_cb(pval, it); \ | 387 | 3.33k | asn1_store_ptr(pval, ret.release()); \ | 388 | 3.33k | return 1; \ | 389 | 3.79k | } \ |
Unexecuted instantiation: x_pubkey.cc:bssl::(anonymous namespace)::X509_PUBKEY_parse_cb(ASN1_VALUE_st**, cbs_st*, ASN1_ITEM_st const*, int) Unexecuted instantiation: x_x509.cc:(anonymous namespace)::X509_parse_cb(ASN1_VALUE_st**, cbs_st*, ASN1_ITEM_st const*, int) |
390 | | \ |
391 | 9.20k | int name##_marshal_cb(CBB *cbb, ASN1_VALUE **pval, const ASN1_ITEM *it) { \ |
392 | 9.20k | return marshal_func(cbb, asn1_load_ptr_as<name>(pval)); \ |
393 | 9.20k | } \ Unexecuted instantiation: x_algor.cc:(anonymous namespace)::X509_ALGOR_marshal_cb(cbb_st*, ASN1_VALUE_st**, ASN1_ITEM_st const*) x_name.cc:bssl::(anonymous namespace)::X509_NAME_ENTRY_marshal_cb(cbb_st*, ASN1_VALUE_st**, ASN1_ITEM_st const*) Line | Count | Source | 391 | 5.50k | int name##_marshal_cb(CBB *cbb, ASN1_VALUE **pval, const ASN1_ITEM *it) { \ | 392 | 5.50k | return marshal_func(cbb, asn1_load_ptr_as<name>(pval)); \ | 393 | 5.50k | } \ |
x_name.cc:(anonymous namespace)::X509_NAME_marshal_cb(cbb_st*, ASN1_VALUE_st**, ASN1_ITEM_st const*) Line | Count | Source | 391 | 3.70k | int name##_marshal_cb(CBB *cbb, ASN1_VALUE **pval, const ASN1_ITEM *it) { \ | 392 | 3.70k | return marshal_func(cbb, asn1_load_ptr_as<name>(pval)); \ | 393 | 3.70k | } \ |
Unexecuted instantiation: x_pubkey.cc:bssl::(anonymous namespace)::X509_PUBKEY_marshal_cb(cbb_st*, ASN1_VALUE_st**, ASN1_ITEM_st const*) Unexecuted instantiation: x_x509.cc:(anonymous namespace)::X509_marshal_cb(cbb_st*, ASN1_VALUE_st**, ASN1_ITEM_st const*) |
394 | | \ |
395 | | const ASN1_EXTERN_FUNCS name##_extern_funcs = { \ |
396 | | name##_new_cb, name##_free_cb, name##_parse_cb, name##_marshal_cb}; \ |
397 | | } \ |
398 | | IMPLEMENT_EXTERN_ASN1(name, name##_extern_funcs) |
399 | | |
400 | | // IMPLEMENT_EXTERN_ASN1_PARSE_INTO implements an `ASN1_ITEM` for a type whose |
401 | | // parse function writes into an existing object. |
402 | | #define IMPLEMENT_EXTERN_ASN1_PARSE_INTO(name, new_func, free_func, tag, \ |
403 | | parse_func, marshal_func) \ |
404 | | \ |
405 | | namespace { \ |
406 | 4.00k | bssl::UniquePtr<name> name##_parse_new(CBS *cbs) { \ |
407 | 4.00k | bssl::UniquePtr<name> ret(new_func()); \ |
408 | 4.00k | if (ret == nullptr || !parse_func(cbs, ret.get())) { \ |
409 | 497 | return 0; \ |
410 | 497 | } \ |
411 | 4.00k | return ret; \ |
412 | 4.00k | } \ Unexecuted instantiation: x_algor.cc:(anonymous namespace)::X509_ALGOR_parse_new(cbs_st*) x_name.cc:bssl::(anonymous namespace)::X509_NAME_ENTRY_parse_new(cbs_st*) Line | Count | Source | 406 | 214 | bssl::UniquePtr<name> name##_parse_new(CBS *cbs) { \ | 407 | 214 | bssl::UniquePtr<name> ret(new_func()); \ | 408 | 214 | if (ret == nullptr || !parse_func(cbs, ret.get())) { \ | 409 | 38 | return 0; \ | 410 | 38 | } \ | 411 | 214 | return ret; \ | 412 | 214 | } \ |
x_name.cc:(anonymous namespace)::X509_NAME_parse_new(cbs_st*) Line | Count | Source | 406 | 3.79k | bssl::UniquePtr<name> name##_parse_new(CBS *cbs) { \ | 407 | 3.79k | bssl::UniquePtr<name> ret(new_func()); \ | 408 | 3.79k | if (ret == nullptr || !parse_func(cbs, ret.get())) { \ | 409 | 459 | return 0; \ | 410 | 459 | } \ | 411 | 3.79k | return ret; \ | 412 | 3.79k | } \ |
Unexecuted instantiation: x_pubkey.cc:bssl::(anonymous namespace)::X509_PUBKEY_parse_new(cbs_st*) |
413 | | } \ |
414 | | IMPLEMENT_EXTERN_ASN1_PARSE_NEW(name, new_func, free_func, tag, \ |
415 | | name##_parse_new, marshal_func) |
416 | | |
417 | | // ASN1_TIME is an `ASN1_ITEM` whose ASN.1 type is X.509 Time (RFC 5280) and C |
418 | | // type is `ASN1_TIME*`. |
419 | | DECLARE_ASN1_ITEM(ASN1_TIME) |
420 | | |
421 | | // DIRECTORYSTRING is an `ASN1_ITEM` whose ASN.1 type is X.509 DirectoryString |
422 | | // (RFC 5280) and C type is `ASN1_STRING*`. |
423 | | DECLARE_ASN1_ITEM(DIRECTORYSTRING) |
424 | | |
425 | | // DISPLAYTEXT is an `ASN1_ITEM` whose ASN.1 type is X.509 DisplayText (RFC |
426 | | // 5280) and C type is `ASN1_STRING*`. |
427 | | DECLARE_ASN1_ITEM(DISPLAYTEXT) |
428 | | |
429 | | BSSL_NAMESPACE_END |
430 | | |
431 | | #endif // OPENSSL_HEADER_CRYPTO_ASN1_INTERNAL_H |