Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 2 | * All rights reserved. |
| 3 | * |
| 4 | * This package is an SSL implementation written |
| 5 | * by Eric Young (eay@cryptsoft.com). |
| 6 | * The implementation was written so as to conform with Netscapes SSL. |
| 7 | * |
| 8 | * This library is free for commercial and non-commercial use as long as |
| 9 | * the following conditions are aheared to. The following conditions |
| 10 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 12 | * included with this distribution is covered by the same copyright terms |
| 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 14 | * |
| 15 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 16 | * the code are not to be removed. |
| 17 | * If this package is used in a product, Eric Young should be given attribution |
| 18 | * as the author of the parts of the library used. |
| 19 | * This can be in the form of a textual message at program startup or |
| 20 | * in documentation (online or textual) provided with the package. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: |
| 25 | * 1. Redistributions of source code must retain the copyright |
| 26 | * notice, this list of conditions and the following disclaimer. |
| 27 | * 2. Redistributions in binary form must reproduce the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer in the |
| 29 | * documentation and/or other materials provided with the distribution. |
| 30 | * 3. All advertising materials mentioning features or use of this software |
| 31 | * must display the following acknowledgement: |
| 32 | * "This product includes cryptographic software written by |
| 33 | * Eric Young (eay@cryptsoft.com)" |
| 34 | * The word 'cryptographic' can be left out if the rouines from the library |
| 35 | * being used are not cryptographic related :-). |
| 36 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 37 | * the apps directory (application code) you must include an acknowledgement: |
| 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 39 | * |
| 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 50 | * SUCH DAMAGE. |
| 51 | * |
| 52 | * The licence and distribution terms for any publically available version or |
| 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 54 | * copied and put under another distribution licence |
| 55 | * [including the GNU Public Licence.] */ |
| 56 | |
| 57 | #include <openssl/asn1.h> |
| 58 | |
Adam Langley | 2b2d66d | 2015-01-30 17:08:37 -0800 | [diff] [blame] | 59 | #include <string.h> |
| 60 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 61 | #include <openssl/asn1t.h> |
| 62 | #include <openssl/err.h> |
| 63 | #include <openssl/mem.h> |
| 64 | #include <openssl/obj.h> |
| 65 | |
David Benjamin | e3a7bd0 | 2021-06-30 10:18:30 -0400 | [diff] [blame] | 66 | #include "internal.h" |
David Benjamin | 17cf2cb | 2016-12-13 01:07:13 -0500 | [diff] [blame] | 67 | #include "../internal.h" |
| 68 | |
| 69 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 70 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 71 | int combine); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 72 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); |
David Benjamin | e4da107 | 2020-06-20 10:55:13 -0400 | [diff] [blame] | 73 | static int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 74 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); |
David Benjamin | e4da107 | 2020-06-20 10:55:13 -0400 | [diff] [blame] | 75 | static int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 76 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); |
| 77 | |
| 78 | ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 79 | { |
| 80 | ASN1_VALUE *ret = NULL; |
| 81 | if (ASN1_item_ex_new(&ret, it) > 0) |
| 82 | return ret; |
| 83 | return NULL; |
| 84 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 85 | |
| 86 | /* Allocate an ASN1 structure */ |
| 87 | |
| 88 | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 89 | { |
| 90 | return asn1_item_ex_combine_new(pval, it, 0); |
| 91 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 92 | |
| 93 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 94 | int combine) |
| 95 | { |
| 96 | const ASN1_TEMPLATE *tt = NULL; |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 97 | const ASN1_EXTERN_FUNCS *ef; |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 98 | ASN1_VALUE **pseqval; |
| 99 | int i; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 100 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 101 | switch (it->itype) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 102 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 103 | case ASN1_ITYPE_EXTERN: |
| 104 | ef = it->funcs; |
| 105 | if (ef && ef->asn1_ex_new) { |
| 106 | if (!ef->asn1_ex_new(pval, it)) |
| 107 | goto memerr; |
| 108 | } |
| 109 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 110 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 111 | case ASN1_ITYPE_PRIMITIVE: |
| 112 | if (it->templates) { |
| 113 | if (!ASN1_template_new(pval, it->templates)) |
| 114 | goto memerr; |
| 115 | } else if (!ASN1_primitive_new(pval, it)) |
| 116 | goto memerr; |
| 117 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 118 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 119 | case ASN1_ITYPE_MSTRING: |
| 120 | if (!ASN1_primitive_new(pval, it)) |
| 121 | goto memerr; |
| 122 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 123 | |
David Benjamin | afed9f7 | 2021-08-22 14:26:34 -0400 | [diff] [blame] | 124 | case ASN1_ITYPE_CHOICE: { |
| 125 | const ASN1_AUX *aux = it->funcs; |
| 126 | ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL; |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 127 | if (asn1_cb) { |
| 128 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
| 129 | if (!i) |
| 130 | goto auxerr; |
| 131 | if (i == 2) { |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 132 | return 1; |
| 133 | } |
| 134 | } |
| 135 | if (!combine) { |
| 136 | *pval = OPENSSL_malloc(it->size); |
| 137 | if (!*pval) |
| 138 | goto memerr; |
David Benjamin | 17cf2cb | 2016-12-13 01:07:13 -0500 | [diff] [blame] | 139 | OPENSSL_memset(*pval, 0, it->size); |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 140 | } |
| 141 | asn1_set_choice_selector(pval, -1, it); |
| 142 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) |
David Benjamin | c4d5925 | 2017-02-09 19:41:18 -0500 | [diff] [blame] | 143 | goto auxerr2; |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 144 | break; |
David Benjamin | afed9f7 | 2021-08-22 14:26:34 -0400 | [diff] [blame] | 145 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 146 | |
David Benjamin | afed9f7 | 2021-08-22 14:26:34 -0400 | [diff] [blame] | 147 | case ASN1_ITYPE_SEQUENCE: { |
| 148 | const ASN1_AUX *aux = it->funcs; |
| 149 | ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL; |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 150 | if (asn1_cb) { |
| 151 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); |
| 152 | if (!i) |
| 153 | goto auxerr; |
| 154 | if (i == 2) { |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 155 | return 1; |
| 156 | } |
| 157 | } |
| 158 | if (!combine) { |
| 159 | *pval = OPENSSL_malloc(it->size); |
| 160 | if (!*pval) |
| 161 | goto memerr; |
David Benjamin | 17cf2cb | 2016-12-13 01:07:13 -0500 | [diff] [blame] | 162 | OPENSSL_memset(*pval, 0, it->size); |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 163 | asn1_refcount_set_one(pval, it); |
| 164 | asn1_enc_init(pval, it); |
| 165 | } |
| 166 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { |
| 167 | pseqval = asn1_get_field_ptr(pval, tt); |
| 168 | if (!ASN1_template_new(pseqval, tt)) |
David Benjamin | c4d5925 | 2017-02-09 19:41:18 -0500 | [diff] [blame] | 169 | goto memerr2; |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 170 | } |
| 171 | if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) |
David Benjamin | c4d5925 | 2017-02-09 19:41:18 -0500 | [diff] [blame] | 172 | goto auxerr2; |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 173 | break; |
| 174 | } |
David Benjamin | afed9f7 | 2021-08-22 14:26:34 -0400 | [diff] [blame] | 175 | } |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 176 | return 1; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 177 | |
David Benjamin | c4d5925 | 2017-02-09 19:41:18 -0500 | [diff] [blame] | 178 | memerr2: |
David Benjamin | 4f94a83 | 2017-10-30 11:00:42 -0400 | [diff] [blame] | 179 | asn1_item_combine_free(pval, it, combine); |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 180 | memerr: |
| 181 | OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 182 | return 0; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 183 | |
David Benjamin | c4d5925 | 2017-02-09 19:41:18 -0500 | [diff] [blame] | 184 | auxerr2: |
David Benjamin | 4f94a83 | 2017-10-30 11:00:42 -0400 | [diff] [blame] | 185 | asn1_item_combine_free(pval, it, combine); |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 186 | auxerr: |
| 187 | OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR); |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 188 | return 0; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 189 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 190 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 191 | |
| 192 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 193 | { |
| 194 | const ASN1_EXTERN_FUNCS *ef; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 195 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 196 | switch (it->itype) { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 197 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 198 | case ASN1_ITYPE_EXTERN: |
| 199 | ef = it->funcs; |
| 200 | if (ef && ef->asn1_ex_clear) |
| 201 | ef->asn1_ex_clear(pval, it); |
| 202 | else |
| 203 | *pval = NULL; |
| 204 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 205 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 206 | case ASN1_ITYPE_PRIMITIVE: |
| 207 | if (it->templates) |
| 208 | asn1_template_clear(pval, it->templates); |
| 209 | else |
| 210 | asn1_primitive_clear(pval, it); |
| 211 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 212 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 213 | case ASN1_ITYPE_MSTRING: |
| 214 | asn1_primitive_clear(pval, it); |
| 215 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 216 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 217 | case ASN1_ITYPE_CHOICE: |
| 218 | case ASN1_ITYPE_SEQUENCE: |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 219 | *pval = NULL; |
| 220 | break; |
| 221 | } |
| 222 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 223 | |
David Benjamin | e4da107 | 2020-06-20 10:55:13 -0400 | [diff] [blame] | 224 | static int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 225 | { |
| 226 | const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); |
| 227 | int ret; |
| 228 | if (tt->flags & ASN1_TFLG_OPTIONAL) { |
| 229 | asn1_template_clear(pval, tt); |
| 230 | return 1; |
| 231 | } |
| 232 | /* If ANY DEFINED BY nothing to do */ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 233 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 234 | if (tt->flags & ASN1_TFLG_ADB_MASK) { |
| 235 | *pval = NULL; |
| 236 | return 1; |
| 237 | } |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 238 | /* If SET OF or SEQUENCE OF, its a STACK */ |
| 239 | if (tt->flags & ASN1_TFLG_SK_MASK) { |
| 240 | STACK_OF(ASN1_VALUE) *skval; |
| 241 | skval = sk_ASN1_VALUE_new_null(); |
| 242 | if (!skval) { |
| 243 | OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); |
| 244 | ret = 0; |
| 245 | goto done; |
| 246 | } |
| 247 | *pval = (ASN1_VALUE *)skval; |
| 248 | ret = 1; |
| 249 | goto done; |
| 250 | } |
| 251 | /* Otherwise pass it back to the item routine */ |
| 252 | ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); |
| 253 | done: |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 254 | return ret; |
| 255 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 256 | |
| 257 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 258 | { |
| 259 | /* If ADB or STACK just NULL the field */ |
| 260 | if (tt->flags & (ASN1_TFLG_ADB_MASK | ASN1_TFLG_SK_MASK)) |
| 261 | *pval = NULL; |
| 262 | else |
| 263 | asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); |
| 264 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 265 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 266 | /* |
| 267 | * NB: could probably combine most of the real XXX_new() behaviour and junk |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 268 | * all the old functions. |
| 269 | */ |
| 270 | |
David Benjamin | e4da107 | 2020-06-20 10:55:13 -0400 | [diff] [blame] | 271 | static int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 272 | { |
| 273 | ASN1_TYPE *typ; |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 274 | int utype; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 275 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 276 | if (!it) |
| 277 | return 0; |
David Benjamin | e30f3fb | 2015-03-18 19:55:40 -0400 | [diff] [blame] | 278 | |
David Benjamin | 3de5949 | 2020-06-20 03:05:47 -0400 | [diff] [blame] | 279 | /* Historically, |it->funcs| for primitive types contained an |
| 280 | * |ASN1_PRIMITIVE_FUNCS| table of calbacks. */ |
| 281 | assert(it->funcs == NULL); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 282 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 283 | if (it->itype == ASN1_ITYPE_MSTRING) |
| 284 | utype = -1; |
| 285 | else |
| 286 | utype = it->utype; |
| 287 | switch (utype) { |
| 288 | case V_ASN1_OBJECT: |
| 289 | *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); |
| 290 | return 1; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 291 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 292 | case V_ASN1_BOOLEAN: |
| 293 | *(ASN1_BOOLEAN *)pval = it->size; |
| 294 | return 1; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 295 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 296 | case V_ASN1_NULL: |
| 297 | *pval = (ASN1_VALUE *)1; |
| 298 | return 1; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 299 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 300 | case V_ASN1_ANY: |
| 301 | typ = OPENSSL_malloc(sizeof(ASN1_TYPE)); |
| 302 | if (!typ) |
| 303 | return 0; |
| 304 | typ->value.ptr = NULL; |
| 305 | typ->type = -1; |
| 306 | *pval = (ASN1_VALUE *)typ; |
| 307 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 308 | |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 309 | default: |
David Benjamin | 046fc13 | 2021-08-01 15:20:53 -0400 | [diff] [blame] | 310 | *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype); |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 311 | break; |
| 312 | } |
| 313 | if (*pval) |
| 314 | return 1; |
| 315 | return 0; |
| 316 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 317 | |
| 318 | static void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 319 | { |
| 320 | int utype; |
David Benjamin | 3de5949 | 2020-06-20 03:05:47 -0400 | [diff] [blame] | 321 | /* Historically, |it->funcs| for primitive types contained an |
| 322 | * |ASN1_PRIMITIVE_FUNCS| table of calbacks. */ |
| 323 | assert(it == NULL || it->funcs == NULL); |
Adam Langley | 57707c7 | 2016-01-14 11:25:12 -0800 | [diff] [blame] | 324 | if (!it || (it->itype == ASN1_ITYPE_MSTRING)) |
| 325 | utype = -1; |
| 326 | else |
| 327 | utype = it->utype; |
| 328 | if (utype == V_ASN1_BOOLEAN) |
| 329 | *(ASN1_BOOLEAN *)pval = it->size; |
| 330 | else |
| 331 | *pval = NULL; |
| 332 | } |