| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/asn1/tasn_enc.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* $OpenBSD: tasn_enc.c,v 1.21 2016/12/30 16:04:34 jsing Exp $ */ | - | ||||||||||||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | - | ||||||||||||
| 3 | * project 2000. | - | ||||||||||||
| 4 | */ | - | ||||||||||||
| 5 | /* ==================================================================== | - | ||||||||||||
| 6 | * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved. | - | ||||||||||||
| 7 | * | - | ||||||||||||
| 8 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||
| 9 | * modification, are permitted provided that the following conditions | - | ||||||||||||
| 10 | * are met: | - | ||||||||||||
| 11 | * | - | ||||||||||||
| 12 | * 1. Redistributions of source code must retain the above copyright | - | ||||||||||||
| 13 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||
| 14 | * | - | ||||||||||||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||
| 16 | * notice, this list of conditions and the following disclaimer in | - | ||||||||||||
| 17 | * the documentation and/or other materials provided with the | - | ||||||||||||
| 18 | * distribution. | - | ||||||||||||
| 19 | * | - | ||||||||||||
| 20 | * 3. All advertising materials mentioning features or use of this | - | ||||||||||||
| 21 | * software must display the following acknowledgment: | - | ||||||||||||
| 22 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | - | ||||||||||||
| 24 | * | - | ||||||||||||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | - | ||||||||||||
| 26 | * endorse or promote products derived from this software without | - | ||||||||||||
| 27 | * prior written permission. For written permission, please contact | - | ||||||||||||
| 28 | * licensing@OpenSSL.org. | - | ||||||||||||
| 29 | * | - | ||||||||||||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | - | ||||||||||||
| 31 | * nor may "OpenSSL" appear in their names without prior written | - | ||||||||||||
| 32 | * permission of the OpenSSL Project. | - | ||||||||||||
| 33 | * | - | ||||||||||||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | - | ||||||||||||
| 35 | * acknowledgment: | - | ||||||||||||
| 36 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | - | ||||||||||||
| 38 | * | - | ||||||||||||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | - | ||||||||||||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | - | ||||||||||||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | - | ||||||||||||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | - | ||||||||||||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | - | ||||||||||||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | - | ||||||||||||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||||||||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | - | ||||||||||||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | - | ||||||||||||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | - | ||||||||||||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||
| 51 | * ==================================================================== | - | ||||||||||||
| 52 | * | - | ||||||||||||
| 53 | * This product includes cryptographic software written by Eric Young | - | ||||||||||||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | - | ||||||||||||
| 55 | * Hudson (tjh@cryptsoft.com). | - | ||||||||||||
| 56 | * | - | ||||||||||||
| 57 | */ | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | #include <stddef.h> | - | ||||||||||||
| 60 | #include <string.h> | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | #include <openssl/asn1.h> | - | ||||||||||||
| 63 | #include <openssl/asn1t.h> | - | ||||||||||||
| 64 | #include <openssl/objects.h> | - | ||||||||||||
| 65 | - | |||||||||||||
| 66 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | - | ||||||||||||
| 67 | const ASN1_ITEM *it, int tag, int aclass); | - | ||||||||||||
| 68 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, | - | ||||||||||||
| 69 | int skcontlen, const ASN1_ITEM *item, int do_sort, int iclass); | - | ||||||||||||
| 70 | static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | - | ||||||||||||
| 71 | const ASN1_TEMPLATE *tt, int tag, int aclass); | - | ||||||||||||
| 72 | static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, | - | ||||||||||||
| 73 | const ASN1_ITEM *it, int flags); | - | ||||||||||||
| 74 | static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | - | ||||||||||||
| 75 | const ASN1_ITEM *it); | - | ||||||||||||
| 76 | - | |||||||||||||
| 77 | /* Top level i2d equivalents: the 'ndef' variant instructs the encoder | - | ||||||||||||
| 78 | * to use indefinite length constructed encoding, where appropriate | - | ||||||||||||
| 79 | */ | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | int | - | ||||||||||||
| 82 | ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | - | ||||||||||||
| 83 | { | - | ||||||||||||
| 84 | return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF); never executed: return asn1_item_flags_i2d(val, out, it, (0x1<<11)); | 0 | ||||||||||||
| 85 | } | - | ||||||||||||
| 86 | - | |||||||||||||
| 87 | int | - | ||||||||||||
| 88 | ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | - | ||||||||||||
| 89 | { | - | ||||||||||||
| 90 | return asn1_item_flags_i2d(val, out, it, 0); executed 1585 times by 12 tests: return asn1_item_flags_i2d(val, out, it, 0);Executed by:
| 1585 | ||||||||||||
| 91 | } | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | /* Encode an ASN1 item, this is use by the | - | ||||||||||||
| 94 | * standard 'i2d' function. 'out' points to | - | ||||||||||||
| 95 | * a buffer to output the data to. | - | ||||||||||||
| 96 | * | - | ||||||||||||
| 97 | * The new i2d has one additional feature. If the output | - | ||||||||||||
| 98 | * buffer is NULL (i.e. *out == NULL) then a buffer is | - | ||||||||||||
| 99 | * allocated and populated with the encoding. | - | ||||||||||||
| 100 | */ | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | static int | - | ||||||||||||
| 103 | asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it, | - | ||||||||||||
| 104 | int flags) | - | ||||||||||||
| 105 | { | - | ||||||||||||
| 106 | if (out && !*out) {
| 193-1392 | ||||||||||||
| 107 | unsigned char *p, *buf; | - | ||||||||||||
| 108 | int len; | - | ||||||||||||
| 109 | len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); | - | ||||||||||||
| 110 | if (len <= 0)
| 0-1047 | ||||||||||||
| 111 | return len; never executed: return len; | 0 | ||||||||||||
| 112 | buf = malloc(len); | - | ||||||||||||
| 113 | if (!buf)
| 0-1047 | ||||||||||||
| 114 | return -1; never executed: return -1; | 0 | ||||||||||||
| 115 | p = buf; | - | ||||||||||||
| 116 | ASN1_item_ex_i2d(&val, &p, it, -1, flags); | - | ||||||||||||
| 117 | *out = buf; | - | ||||||||||||
| 118 | return len; executed 1047 times by 11 tests: return len;Executed by:
| 1047 | ||||||||||||
| 119 | } | - | ||||||||||||
| 120 | - | |||||||||||||
| 121 | return ASN1_item_ex_i2d(&val, out, it, -1, flags); executed 538 times by 8 tests: return ASN1_item_ex_i2d(&val, out, it, -1, flags);Executed by:
| 538 | ||||||||||||
| 122 | } | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | /* Encode an item, taking care of IMPLICIT tagging (if any). | - | ||||||||||||
| 125 | * This function performs the normal item handling: it can be | - | ||||||||||||
| 126 | * used in external types. | - | ||||||||||||
| 127 | */ | - | ||||||||||||
| 128 | - | |||||||||||||
| 129 | int | - | ||||||||||||
| 130 | ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, | - | ||||||||||||
| 131 | int tag, int aclass) | - | ||||||||||||
| 132 | { | - | ||||||||||||
| 133 | const ASN1_TEMPLATE *tt = NULL; | - | ||||||||||||
| 134 | int i, seqcontlen, seqlen, ndef = 1; | - | ||||||||||||
| 135 | const ASN1_EXTERN_FUNCS *ef; | - | ||||||||||||
| 136 | const ASN1_AUX *aux = it->funcs; | - | ||||||||||||
| 137 | ASN1_aux_cb *asn1_cb = NULL; | - | ||||||||||||
| 138 | - | |||||||||||||
| 139 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
| 0-22209 | ||||||||||||
| 140 | return 0; never executed: return 0; | 0 | ||||||||||||
| 141 | - | |||||||||||||
| 142 | if (aux && aux->asn1_cb)
| 1230-34226 | ||||||||||||
| 143 | asn1_cb = aux->asn1_cb; executed 5545 times by 8 tests: asn1_cb = aux->asn1_cb;Executed by:
| 5545 | ||||||||||||
| 144 | - | |||||||||||||
| 145 | switch (it->itype) { | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | case ASN1_ITYPE_PRIMITIVE: executed 22209 times by 13 tests: case 0x0:Executed by:
| 22209 | ||||||||||||
| 148 | if (it->templates)
| 3877-18332 | ||||||||||||
| 149 | return asn1_template_ex_i2d(pval, out, it->templates, executed 3877 times by 9 tests: return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass);Executed by:
| 3877 | ||||||||||||
| 150 | tag, aclass); executed 3877 times by 9 tests: return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass);Executed by:
| 3877 | ||||||||||||
| 151 | return asn1_i2d_ex_primitive(pval, out, it, tag, aclass); executed 18332 times by 12 tests: return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);Executed by:
| 18332 | ||||||||||||
| 152 | break; dead code: break; | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | case ASN1_ITYPE_MSTRING: executed 7652 times by 8 tests: case 0x5:Executed by:
| 7652 | ||||||||||||
| 155 | return asn1_i2d_ex_primitive(pval, out, it, -1, aclass); executed 7652 times by 8 tests: return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);Executed by:
| 7652 | ||||||||||||
| 156 | - | |||||||||||||
| 157 | case ASN1_ITYPE_CHOICE: executed 212 times by 3 tests: case 0x2:Executed by:
| 212 | ||||||||||||
| 158 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
| 0-208 | ||||||||||||
| 159 | return 0; never executed: return 0; | 0 | ||||||||||||
| 160 | i = asn1_get_choice_selector(pval, it); | - | ||||||||||||
| 161 | if ((i >= 0) && (i < it->tcount)) {
| 0-212 | ||||||||||||
| 162 | ASN1_VALUE **pchval; | - | ||||||||||||
| 163 | const ASN1_TEMPLATE *chtt; | - | ||||||||||||
| 164 | chtt = it->templates + i; | - | ||||||||||||
| 165 | pchval = asn1_get_field_ptr(pval, chtt); | - | ||||||||||||
| 166 | return asn1_template_ex_i2d(pchval, out, chtt, executed 212 times by 3 tests: return asn1_template_ex_i2d(pchval, out, chtt, -1, aclass);Executed by:
| 212 | ||||||||||||
| 167 | -1, aclass); executed 212 times by 3 tests: return asn1_template_ex_i2d(pchval, out, chtt, -1, aclass);Executed by:
| 212 | ||||||||||||
| 168 | } | - | ||||||||||||
| 169 | /* Fixme: error condition if selector out of range */ | - | ||||||||||||
| 170 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
| 0 | ||||||||||||
| 171 | return 0; never executed: return 0; | 0 | ||||||||||||
| 172 | break; never executed: break; | 0 | ||||||||||||
| 173 | - | |||||||||||||
| 174 | case ASN1_ITYPE_EXTERN: executed 116 times by 3 tests: case 0x4:Executed by:
| 116 | ||||||||||||
| 175 | /* If new style i2d it does all the work */ | - | ||||||||||||
| 176 | ef = it->funcs; | - | ||||||||||||
| 177 | return ef->asn1_ex_i2d(pval, out, it, tag, aclass); executed 116 times by 3 tests: return ef->asn1_ex_i2d(pval, out, it, tag, aclass);Executed by:
| 116 | ||||||||||||
| 178 | - | |||||||||||||
| 179 | case ASN1_ITYPE_NDEF_SEQUENCE: executed 33 times by 1 test: case 0x6:Executed by:
| 33 | ||||||||||||
| 180 | /* Use indefinite length constructed if requested */ | - | ||||||||||||
| 181 | if (aclass & ASN1_TFLG_NDEF)
| 0-33 | ||||||||||||
| 182 | ndef = 2; never executed: ndef = 2; | 0 | ||||||||||||
| 183 | /* fall through */ | - | ||||||||||||
| 184 | - | |||||||||||||
| 185 | case ASN1_ITYPE_SEQUENCE: code before this statement executed 33 times by 1 test: case 0x1:Executed by:
executed 10779 times by 11 tests: case 0x1:Executed by:
| 33-10779 | ||||||||||||
| 186 | i = asn1_enc_restore(&seqcontlen, out, pval, it); | - | ||||||||||||
| 187 | /* An error occurred */ | - | ||||||||||||
| 188 | if (i < 0)
| 0-10812 | ||||||||||||
| 189 | return 0; never executed: return 0; | 0 | ||||||||||||
| 190 | /* We have a valid cached encoding... */ | - | ||||||||||||
| 191 | if (i > 0)
| 1104-9708 | ||||||||||||
| 192 | return seqcontlen; executed 1104 times by 6 tests: return seqcontlen;Executed by:
| 1104 | ||||||||||||
| 193 | /* Otherwise carry on */ | - | ||||||||||||
| 194 | seqcontlen = 0; | - | ||||||||||||
| 195 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | - | ||||||||||||
| 196 | if (tag == -1) {
| 0-9708 | ||||||||||||
| 197 | tag = V_ASN1_SEQUENCE; | - | ||||||||||||
| 198 | /* Retain any other flags in aclass */ | - | ||||||||||||
| 199 | aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) | | - | ||||||||||||
| 200 | V_ASN1_UNIVERSAL; | - | ||||||||||||
| 201 | } executed 9708 times by 11 tests: end of blockExecuted by:
| 9708 | ||||||||||||
| 202 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
| 0-8712 | ||||||||||||
| 203 | return 0; never executed: return 0; | 0 | ||||||||||||
| 204 | /* First work out sequence content length */ | - | ||||||||||||
| 205 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
| 9708-20563 | ||||||||||||
| 206 | const ASN1_TEMPLATE *seqtt; | - | ||||||||||||
| 207 | ASN1_VALUE **pseqval; | - | ||||||||||||
| 208 | seqtt = asn1_do_adb(pval, tt, 1); | - | ||||||||||||
| 209 | if (!seqtt)
| 0-20563 | ||||||||||||
| 210 | return 0; never executed: return 0; | 0 | ||||||||||||
| 211 | pseqval = asn1_get_field_ptr(pval, seqtt); | - | ||||||||||||
| 212 | /* FIXME: check for errors in enhanced version */ | - | ||||||||||||
| 213 | seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt, | - | ||||||||||||
| 214 | -1, aclass); | - | ||||||||||||
| 215 | } executed 20563 times by 11 tests: end of blockExecuted by:
| 20563 | ||||||||||||
| 216 | - | |||||||||||||
| 217 | seqlen = ASN1_object_size(ndef, seqcontlen, tag); | - | ||||||||||||
| 218 | if (!out)
| 3676-6032 | ||||||||||||
| 219 | return seqlen; executed 6032 times by 11 tests: return seqlen;Executed by:
| 6032 | ||||||||||||
| 220 | /* Output SEQUENCE header */ | - | ||||||||||||
| 221 | ASN1_put_object(out, ndef, seqcontlen, tag, aclass); | - | ||||||||||||
| 222 | for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
| 3676-7877 | ||||||||||||
| 223 | const ASN1_TEMPLATE *seqtt; | - | ||||||||||||
| 224 | ASN1_VALUE **pseqval; | - | ||||||||||||
| 225 | seqtt = asn1_do_adb(pval, tt, 1); | - | ||||||||||||
| 226 | if (!seqtt)
| 0-7877 | ||||||||||||
| 227 | return 0; never executed: return 0; | 0 | ||||||||||||
| 228 | pseqval = asn1_get_field_ptr(pval, seqtt); | - | ||||||||||||
| 229 | /* FIXME: check for errors in enhanced version */ | - | ||||||||||||
| 230 | asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); | - | ||||||||||||
| 231 | } executed 7877 times by 11 tests: end of blockExecuted by:
| 7877 | ||||||||||||
| 232 | if (ndef == 2)
| 0-3676 | ||||||||||||
| 233 | ASN1_put_eoc(out); never executed: ASN1_put_eoc(out); | 0 | ||||||||||||
| 234 | if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
| 0-3195 | ||||||||||||
| 235 | return 0; never executed: return 0; | 0 | ||||||||||||
| 236 | return seqlen; executed 3676 times by 11 tests: return seqlen;Executed by:
| 3676 | ||||||||||||
| 237 | - | |||||||||||||
| 238 | default: never executed: default: | 0 | ||||||||||||
| 239 | return 0; never executed: return 0; | 0 | ||||||||||||
| 240 | - | |||||||||||||
| 241 | } | - | ||||||||||||
| 242 | return 0; never executed: return 0; | 0 | ||||||||||||
| 243 | } | - | ||||||||||||
| 244 | - | |||||||||||||
| 245 | int | - | ||||||||||||
| 246 | ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, | - | ||||||||||||
| 247 | const ASN1_TEMPLATE *tt) | - | ||||||||||||
| 248 | { | - | ||||||||||||
| 249 | return asn1_template_ex_i2d(pval, out, tt, -1, 0); never executed: return asn1_template_ex_i2d(pval, out, tt, -1, 0); | 0 | ||||||||||||
| 250 | } | - | ||||||||||||
| 251 | - | |||||||||||||
| 252 | static int | - | ||||||||||||
| 253 | asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, | - | ||||||||||||
| 254 | const ASN1_TEMPLATE *tt, int tag, int iclass) | - | ||||||||||||
| 255 | { | - | ||||||||||||
| 256 | int i, ret, flags, ttag, tclass, ndef; | - | ||||||||||||
| 257 | flags = tt->flags; | - | ||||||||||||
| 258 | /* Work out tag and class to use: tagging may come | - | ||||||||||||
| 259 | * either from the template or the arguments, not both | - | ||||||||||||
| 260 | * because this would create ambiguity. Additionally | - | ||||||||||||
| 261 | * the iclass argument may contain some additional flags | - | ||||||||||||
| 262 | * which should be noted and passed down to other levels. | - | ||||||||||||
| 263 | */ | - | ||||||||||||
| 264 | if (flags & ASN1_TFLG_TAG_MASK) {
| 210-32319 | ||||||||||||
| 265 | /* Error if argument and template tagging */ | - | ||||||||||||
| 266 | if (tag != -1)
| 0-210 | ||||||||||||
| 267 | /* FIXME: error code here */ | - | ||||||||||||
| 268 | return -1; never executed: return -1; | 0 | ||||||||||||
| 269 | /* Get tagging from template */ | - | ||||||||||||
| 270 | ttag = tt->tag; | - | ||||||||||||
| 271 | tclass = flags & ASN1_TFLG_TAG_CLASS; | - | ||||||||||||
| 272 | } else if (tag != -1) { executed 210 times by 3 tests: end of blockExecuted by:
| 0-32319 | ||||||||||||
| 273 | /* No template tagging, get from arguments */ | - | ||||||||||||
| 274 | ttag = tag; | - | ||||||||||||
| 275 | tclass = iclass & ASN1_TFLG_TAG_CLASS; | - | ||||||||||||
| 276 | } else { never executed: end of block | 0 | ||||||||||||
| 277 | ttag = -1; | - | ||||||||||||
| 278 | tclass = 0; | - | ||||||||||||
| 279 | } executed 32319 times by 12 tests: end of blockExecuted by:
| 32319 | ||||||||||||
| 280 | /* | - | ||||||||||||
| 281 | * Remove any class mask from iflag. | - | ||||||||||||
| 282 | */ | - | ||||||||||||
| 283 | iclass &= ~ASN1_TFLG_TAG_CLASS; | - | ||||||||||||
| 284 | - | |||||||||||||
| 285 | /* At this point 'ttag' contains the outer tag to use, | - | ||||||||||||
| 286 | * 'tclass' is the class and iclass is any flags passed | - | ||||||||||||
| 287 | * to this function. | - | ||||||||||||
| 288 | */ | - | ||||||||||||
| 289 | - | |||||||||||||
| 290 | /* if template and arguments require ndef, use it */ | - | ||||||||||||
| 291 | if ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF))
| 0-32508 | ||||||||||||
| 292 | ndef = 2; never executed: ndef = 2; | 0 | ||||||||||||
| 293 | else | - | ||||||||||||
| 294 | ndef = 1; executed 32529 times by 12 tests: ndef = 1;Executed by:
| 32529 | ||||||||||||
| 295 | - | |||||||||||||
| 296 | if (flags & ASN1_TFLG_SK_MASK) {
| 4103-28426 | ||||||||||||
| 297 | /* SET OF, SEQUENCE OF */ | - | ||||||||||||
| 298 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | - | ||||||||||||
| 299 | int isset, sktag, skaclass; | - | ||||||||||||
| 300 | int skcontlen, sklen; | - | ||||||||||||
| 301 | ASN1_VALUE *skitem; | - | ||||||||||||
| 302 | - | |||||||||||||
| 303 | if (!*pval)
| 51-4052 | ||||||||||||
| 304 | return 0; executed 51 times by 4 tests: return 0;Executed by:
| 51 | ||||||||||||
| 305 | - | |||||||||||||
| 306 | if (flags & ASN1_TFLG_SET_OF) {
| 112-3940 | ||||||||||||
| 307 | isset = 1; | - | ||||||||||||
| 308 | /* 2 means we reorder */ | - | ||||||||||||
| 309 | if (flags & ASN1_TFLG_SEQUENCE_OF)
| 4-3936 | ||||||||||||
| 310 | isset = 2; executed 4 times by 1 test: isset = 2;Executed by:
| 4 | ||||||||||||
| 311 | } else executed 3940 times by 8 tests: end of blockExecuted by:
| 3940 | ||||||||||||
| 312 | isset = 0; executed 112 times by 3 tests: isset = 0;Executed by:
| 112 | ||||||||||||
| 313 | - | |||||||||||||
| 314 | /* Work out inner tag value: if EXPLICIT | - | ||||||||||||
| 315 | * or no tagging use underlying type. | - | ||||||||||||
| 316 | */ | - | ||||||||||||
| 317 | if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) {
| 0-4024 | ||||||||||||
| 318 | sktag = ttag; | - | ||||||||||||
| 319 | skaclass = tclass; | - | ||||||||||||
| 320 | } else { executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||
| 321 | skaclass = V_ASN1_UNIVERSAL; | - | ||||||||||||
| 322 | if (isset)
| 84-3940 | ||||||||||||
| 323 | sktag = V_ASN1_SET; executed 3940 times by 8 tests: sktag = 17;Executed by:
| 3940 | ||||||||||||
| 324 | else | - | ||||||||||||
| 325 | sktag = V_ASN1_SEQUENCE; executed 84 times by 3 tests: sktag = 16;Executed by:
| 84 | ||||||||||||
| 326 | } | - | ||||||||||||
| 327 | - | |||||||||||||
| 328 | /* Determine total length of items */ | - | ||||||||||||
| 329 | skcontlen = 0; | - | ||||||||||||
| 330 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
| 4052-4201 | ||||||||||||
| 331 | skitem = sk_ASN1_VALUE_value(sk, i); | - | ||||||||||||
| 332 | skcontlen += ASN1_item_ex_i2d(&skitem, NULL, | - | ||||||||||||
| 333 | tt->item, -1, iclass); | - | ||||||||||||
| 334 | } executed 4201 times by 8 tests: end of blockExecuted by:
| 4201 | ||||||||||||
| 335 | sklen = ASN1_object_size(ndef, skcontlen, sktag); | - | ||||||||||||
| 336 | /* If EXPLICIT need length of surrounding tag */ | - | ||||||||||||
| 337 | if (flags & ASN1_TFLG_EXPTAG)
| 0-4052 | ||||||||||||
| 338 | ret = ASN1_object_size(ndef, sklen, ttag); never executed: ret = ASN1_object_size(ndef, sklen, ttag); | 0 | ||||||||||||
| 339 | else | - | ||||||||||||
| 340 | ret = sklen; executed 4052 times by 8 tests: ret = sklen;Executed by:
| 4052 | ||||||||||||
| 341 | - | |||||||||||||
| 342 | if (!out)
| 1950-2102 | ||||||||||||
| 343 | return ret; executed 2102 times by 8 tests: return ret;Executed by:
| 2102 | ||||||||||||
| 344 | - | |||||||||||||
| 345 | /* Now encode this lot... */ | - | ||||||||||||
| 346 | /* EXPLICIT tag */ | - | ||||||||||||
| 347 | if (flags & ASN1_TFLG_EXPTAG)
| 0-1950 | ||||||||||||
| 348 | ASN1_put_object(out, ndef, sklen, ttag, tclass); never executed: ASN1_put_object(out, ndef, sklen, ttag, tclass); | 0 | ||||||||||||
| 349 | /* SET or SEQUENCE and IMPLICIT tag */ | - | ||||||||||||
| 350 | ASN1_put_object(out, ndef, skcontlen, sktag, skaclass); | - | ||||||||||||
| 351 | /* And the stuff itself */ | - | ||||||||||||
| 352 | asn1_set_seq_out(sk, out, skcontlen, tt->item, | - | ||||||||||||
| 353 | isset, iclass); | - | ||||||||||||
| 354 | if (ndef == 2) {
| 0-1950 | ||||||||||||
| 355 | ASN1_put_eoc(out); | - | ||||||||||||
| 356 | if (flags & ASN1_TFLG_EXPTAG)
| 0 | ||||||||||||
| 357 | ASN1_put_eoc(out); never executed: ASN1_put_eoc(out); | 0 | ||||||||||||
| 358 | } never executed: end of block | 0 | ||||||||||||
| 359 | - | |||||||||||||
| 360 | return ret; executed 1950 times by 8 tests: return ret;Executed by:
| 1950 | ||||||||||||
| 361 | } | - | ||||||||||||
| 362 | - | |||||||||||||
| 363 | if (flags & ASN1_TFLG_EXPTAG) {
| 35-28391 | ||||||||||||
| 364 | /* EXPLICIT tagging */ | - | ||||||||||||
| 365 | /* Find length of tagged item */ | - | ||||||||||||
| 366 | i = ASN1_item_ex_i2d(pval, NULL, tt->item, | - | ||||||||||||
| 367 | -1, iclass); | - | ||||||||||||
| 368 | if (!i)
| 15-20 | ||||||||||||
| 369 | return 0; executed 20 times by 2 tests: return 0;Executed by:
| 20 | ||||||||||||
| 370 | /* Find length of EXPLICIT tag */ | - | ||||||||||||
| 371 | ret = ASN1_object_size(ndef, i, ttag); | - | ||||||||||||
| 372 | if (out) {
| 4-11 | ||||||||||||
| 373 | /* Output tag and item */ | - | ||||||||||||
| 374 | ASN1_put_object(out, ndef, i, ttag, tclass); | - | ||||||||||||
| 375 | ASN1_item_ex_i2d(pval, out, tt->item, | - | ||||||||||||
| 376 | -1, iclass); | - | ||||||||||||
| 377 | if (ndef == 2)
| 0-4 | ||||||||||||
| 378 | ASN1_put_eoc(out); never executed: ASN1_put_eoc(out); | 0 | ||||||||||||
| 379 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 380 | return ret; executed 15 times by 1 test: return ret;Executed by:
| 15 | ||||||||||||
| 381 | } | - | ||||||||||||
| 382 | - | |||||||||||||
| 383 | /* Either normal or IMPLICIT tagging: combine class and flags */ | - | ||||||||||||
| 384 | return ASN1_item_ex_i2d(pval, out, tt->item, executed 28391 times by 11 tests: return ASN1_item_ex_i2d(pval, out, tt->item, ttag, tclass | iclass);Executed by:
| 28391 | ||||||||||||
| 385 | ttag, tclass | iclass); executed 28391 times by 11 tests: return ASN1_item_ex_i2d(pval, out, tt->item, ttag, tclass | iclass);Executed by:
| 28391 | ||||||||||||
| 386 | } | - | ||||||||||||
| 387 | - | |||||||||||||
| 388 | /* Temporary structure used to hold DER encoding of items for SET OF */ | - | ||||||||||||
| 389 | - | |||||||||||||
| 390 | typedef struct { | - | ||||||||||||
| 391 | unsigned char *data; | - | ||||||||||||
| 392 | int length; | - | ||||||||||||
| 393 | ASN1_VALUE *field; | - | ||||||||||||
| 394 | } DER_ENC; | - | ||||||||||||
| 395 | - | |||||||||||||
| 396 | static int | - | ||||||||||||
| 397 | der_cmp(const void *a, const void *b) | - | ||||||||||||
| 398 | { | - | ||||||||||||
| 399 | const DER_ENC *d1 = a, *d2 = b; | - | ||||||||||||
| 400 | int cmplen, i; | - | ||||||||||||
| 401 | - | |||||||||||||
| 402 | cmplen = (d1->length < d2->length) ? d1->length : d2->length;
| 4-6 | ||||||||||||
| 403 | i = memcmp(d1->data, d2->data, cmplen); | - | ||||||||||||
| 404 | if (i)
| 0-10 | ||||||||||||
| 405 | return i; executed 10 times by 1 test: return i;Executed by:
| 10 | ||||||||||||
| 406 | return d1->length - d2->length; never executed: return d1->length - d2->length; | 0 | ||||||||||||
| 407 | } | - | ||||||||||||
| 408 | - | |||||||||||||
| 409 | /* Output the content octets of SET OF or SEQUENCE OF */ | - | ||||||||||||
| 410 | - | |||||||||||||
| 411 | static int | - | ||||||||||||
| 412 | asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen, | - | ||||||||||||
| 413 | const ASN1_ITEM *item, int do_sort, int iclass) | - | ||||||||||||
| 414 | { | - | ||||||||||||
| 415 | int i; | - | ||||||||||||
| 416 | ASN1_VALUE *skitem; | - | ||||||||||||
| 417 | unsigned char *tmpdat = NULL, *p = NULL; | - | ||||||||||||
| 418 | DER_ENC *derlst = NULL, *tder; | - | ||||||||||||
| 419 | - | |||||||||||||
| 420 | if (do_sort) {
| 48-1902 | ||||||||||||
| 421 | /* Don't need to sort less than 2 items */ | - | ||||||||||||
| 422 | if (sk_ASN1_VALUE_num(sk) < 2)
| 2-1900 | ||||||||||||
| 423 | do_sort = 0; executed 1900 times by 8 tests: do_sort = 0;Executed by:
| 1900 | ||||||||||||
| 424 | else { | - | ||||||||||||
| 425 | derlst = reallocarray(NULL, sk_ASN1_VALUE_num(sk), | - | ||||||||||||
| 426 | sizeof(*derlst)); | - | ||||||||||||
| 427 | tmpdat = malloc(skcontlen); | - | ||||||||||||
| 428 | if (!derlst || !tmpdat) {
| 0-2 | ||||||||||||
| 429 | free(derlst); | - | ||||||||||||
| 430 | free(tmpdat); | - | ||||||||||||
| 431 | return 0; never executed: return 0; | 0 | ||||||||||||
| 432 | } | - | ||||||||||||
| 433 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 434 | } | - | ||||||||||||
| 435 | /* If not sorting just output each item */ | - | ||||||||||||
| 436 | if (!do_sort) {
| 2-1948 | ||||||||||||
| 437 | for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
| 1948-2000 | ||||||||||||
| 438 | skitem = sk_ASN1_VALUE_value(sk, i); | - | ||||||||||||
| 439 | ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); | - | ||||||||||||
| 440 | } executed 2000 times by 8 tests: end of blockExecuted by:
| 2000 | ||||||||||||
| 441 | return 1; executed 1948 times by 8 tests: return 1;Executed by:
| 1948 | ||||||||||||
| 442 | } | - | ||||||||||||
| 443 | p = tmpdat; | - | ||||||||||||
| 444 | - | |||||||||||||
| 445 | /* Doing sort: build up a list of each member's DER encoding */ | - | ||||||||||||
| 446 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
| 2-8 | ||||||||||||
| 447 | skitem = sk_ASN1_VALUE_value(sk, i); | - | ||||||||||||
| 448 | tder->data = p; | - | ||||||||||||
| 449 | tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); | - | ||||||||||||
| 450 | tder->field = skitem; | - | ||||||||||||
| 451 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 452 | - | |||||||||||||
| 453 | /* Now sort them */ | - | ||||||||||||
| 454 | qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); | - | ||||||||||||
| 455 | /* Output sorted DER encoding */ | - | ||||||||||||
| 456 | p = *out; | - | ||||||||||||
| 457 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
| 2-8 | ||||||||||||
| 458 | memcpy(p, tder->data, tder->length); | - | ||||||||||||
| 459 | p += tder->length; | - | ||||||||||||
| 460 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||
| 461 | *out = p; | - | ||||||||||||
| 462 | /* If do_sort is 2 then reorder the STACK */ | - | ||||||||||||
| 463 | if (do_sort == 2) {
| 0-2 | ||||||||||||
| 464 | for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
| 2-8 | ||||||||||||
| 465 | (void)sk_ASN1_VALUE_set(sk, i, tder->field); executed 8 times by 1 test: (void)sk_set(((_STACK*) (1 ? (sk) : (struct stack_st_ASN1_VALUE*)0)), (i), ((void*) (1 ? (tder->field) : (ASN1_VALUE*)0)));Executed by:
| 8 | ||||||||||||
| 466 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 467 | free(derlst); | - | ||||||||||||
| 468 | free(tmpdat); | - | ||||||||||||
| 469 | return 1; executed 2 times by 1 test: return 1;Executed by:
| 2 | ||||||||||||
| 470 | } | - | ||||||||||||
| 471 | - | |||||||||||||
| 472 | static int | - | ||||||||||||
| 473 | asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, | - | ||||||||||||
| 474 | const ASN1_ITEM *it, int tag, int aclass) | - | ||||||||||||
| 475 | { | - | ||||||||||||
| 476 | int len; | - | ||||||||||||
| 477 | int utype; | - | ||||||||||||
| 478 | int usetag; | - | ||||||||||||
| 479 | int ndef = 0; | - | ||||||||||||
| 480 | - | |||||||||||||
| 481 | utype = it->utype; | - | ||||||||||||
| 482 | - | |||||||||||||
| 483 | /* Get length of content octets and maybe find | - | ||||||||||||
| 484 | * out the underlying type. | - | ||||||||||||
| 485 | */ | - | ||||||||||||
| 486 | - | |||||||||||||
| 487 | len = asn1_ex_i2c(pval, NULL, &utype, it); | - | ||||||||||||
| 488 | - | |||||||||||||
| 489 | /* If SEQUENCE, SET or OTHER then header is | - | ||||||||||||
| 490 | * included in pseudo content octets so don't | - | ||||||||||||
| 491 | * include tag+length. We need to check here | - | ||||||||||||
| 492 | * because the call to asn1_ex_i2c() could change | - | ||||||||||||
| 493 | * utype. | - | ||||||||||||
| 494 | */ | - | ||||||||||||
| 495 | if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
| 0-25929 | ||||||||||||
| 496 | (utype == V_ASN1_OTHER))
| 0-25929 | ||||||||||||
| 497 | usetag = 0; executed 55 times by 2 tests: usetag = 0;Executed by:
| 55 | ||||||||||||
| 498 | else | - | ||||||||||||
| 499 | usetag = 1; executed 25929 times by 12 tests: usetag = 1;Executed by:
| 25929 | ||||||||||||
| 500 | - | |||||||||||||
| 501 | /* -1 means omit type */ | - | ||||||||||||
| 502 | if (len == -1)
| 515-25469 | ||||||||||||
| 503 | return 0; executed 515 times by 3 tests: return 0;Executed by:
| 515 | ||||||||||||
| 504 | - | |||||||||||||
| 505 | /* -2 return is special meaning use ndef */ | - | ||||||||||||
| 506 | if (len == -2) {
| 0-25469 | ||||||||||||
| 507 | ndef = 2; | - | ||||||||||||
| 508 | len = 0; | - | ||||||||||||
| 509 | } never executed: end of block | 0 | ||||||||||||
| 510 | - | |||||||||||||
| 511 | /* If not implicitly tagged get tag from underlying type */ | - | ||||||||||||
| 512 | if (tag == -1)
| 78-25391 | ||||||||||||
| 513 | tag = utype; executed 25391 times by 12 tests: tag = utype;Executed by:
| 25391 | ||||||||||||
| 514 | - | |||||||||||||
| 515 | /* Output tag+length followed by content octets */ | - | ||||||||||||
| 516 | if (out) {
| 6910-18559 | ||||||||||||
| 517 | if (usetag)
| 9-6901 | ||||||||||||
| 518 | ASN1_put_object(out, ndef, len, tag, aclass); executed 6901 times by 12 tests: ASN1_put_object(out, ndef, len, tag, aclass);Executed by:
| 6901 | ||||||||||||
| 519 | asn1_ex_i2c(pval, *out, &utype, it); | - | ||||||||||||
| 520 | if (ndef)
| 0-6910 | ||||||||||||
| 521 | ASN1_put_eoc(out); never executed: ASN1_put_eoc(out); | 0 | ||||||||||||
| 522 | else | - | ||||||||||||
| 523 | *out += len; executed 6910 times by 12 tests: *out += len;Executed by:
| 6910 | ||||||||||||
| 524 | } | - | ||||||||||||
| 525 | - | |||||||||||||
| 526 | if (usetag)
| 55-25414 | ||||||||||||
| 527 | return ASN1_object_size(ndef, len, tag); executed 25414 times by 12 tests: return ASN1_object_size(ndef, len, tag);Executed by:
| 25414 | ||||||||||||
| 528 | return len; executed 55 times by 2 tests: return len;Executed by:
| 55 | ||||||||||||
| 529 | } | - | ||||||||||||
| 530 | - | |||||||||||||
| 531 | /* Produce content octets from a structure */ | - | ||||||||||||
| 532 | - | |||||||||||||
| 533 | static int | - | ||||||||||||
| 534 | asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, | - | ||||||||||||
| 535 | const ASN1_ITEM *it) | - | ||||||||||||
| 536 | { | - | ||||||||||||
| 537 | ASN1_BOOLEAN *tbool = NULL; | - | ||||||||||||
| 538 | ASN1_STRING *strtmp; | - | ||||||||||||
| 539 | ASN1_OBJECT *otmp; | - | ||||||||||||
| 540 | int utype; | - | ||||||||||||
| 541 | const unsigned char *cont; | - | ||||||||||||
| 542 | unsigned char c; | - | ||||||||||||
| 543 | int len; | - | ||||||||||||
| 544 | const ASN1_PRIMITIVE_FUNCS *pf; | - | ||||||||||||
| 545 | - | |||||||||||||
| 546 | pf = it->funcs; | - | ||||||||||||
| 547 | if (pf && pf->prim_i2c)
| 0-26806 | ||||||||||||
| 548 | return pf->prim_i2c(pval, cout, putype, it); executed 6088 times by 4 tests: return pf->prim_i2c(pval, cout, putype, it);Executed by:
| 6088 | ||||||||||||
| 549 | - | |||||||||||||
| 550 | /* Should type be omitted? */ | - | ||||||||||||
| 551 | if ((it->itype != ASN1_ITYPE_PRIMITIVE) ||
| 9564-17242 | ||||||||||||
| 552 | (it->utype != V_ASN1_BOOLEAN)) {
| 0-17242 | ||||||||||||
| 553 | if (!*pval)
| 137-26669 | ||||||||||||
| 554 | return -1; executed 137 times by 2 tests: return -1;Executed by:
| 137 | ||||||||||||
| 555 | } executed 26669 times by 11 tests: end of blockExecuted by:
| 26669 | ||||||||||||
| 556 | - | |||||||||||||
| 557 | if (it->itype == ASN1_ITYPE_MSTRING) {
| 9564-17105 | ||||||||||||
| 558 | /* If MSTRING type set the underlying type */ | - | ||||||||||||
| 559 | strtmp = (ASN1_STRING *)*pval; | - | ||||||||||||
| 560 | utype = strtmp->type; | - | ||||||||||||
| 561 | *putype = utype; | - | ||||||||||||
| 562 | } else if (it->utype == V_ASN1_ANY) { executed 9564 times by 8 tests: end of blockExecuted by:
| 2627-14478 | ||||||||||||
| 563 | /* If ANY set type and pointer to value */ | - | ||||||||||||
| 564 | ASN1_TYPE *typ; | - | ||||||||||||
| 565 | typ = (ASN1_TYPE *)*pval; | - | ||||||||||||
| 566 | utype = typ->type; | - | ||||||||||||
| 567 | *putype = utype; | - | ||||||||||||
| 568 | pval = &typ->value.asn1_value; | - | ||||||||||||
| 569 | } else executed 2627 times by 6 tests: end of blockExecuted by:
| 2627 | ||||||||||||
| 570 | utype = *putype; executed 14478 times by 11 tests: utype = *putype;Executed by:
| 14478 | ||||||||||||
| 571 | - | |||||||||||||
| 572 | switch (utype) { | - | ||||||||||||
| 573 | case V_ASN1_OBJECT: executed 12313 times by 8 tests: case 6:Executed by:
| 12313 | ||||||||||||
| 574 | otmp = (ASN1_OBJECT *)*pval; | - | ||||||||||||
| 575 | cont = otmp->data; | - | ||||||||||||
| 576 | len = otmp->length; | - | ||||||||||||
| 577 | break; executed 12313 times by 8 tests: break;Executed by:
| 12313 | ||||||||||||
| 578 | - | |||||||||||||
| 579 | case V_ASN1_NULL: executed 2387 times by 6 tests: case 5:Executed by:
| 2387 | ||||||||||||
| 580 | cont = NULL; | - | ||||||||||||
| 581 | len = 0; | - | ||||||||||||
| 582 | break; executed 2387 times by 6 tests: break;Executed by:
| 2387 | ||||||||||||
| 583 | - | |||||||||||||
| 584 | case V_ASN1_BOOLEAN: never executed: case 1: | 0 | ||||||||||||
| 585 | tbool = (ASN1_BOOLEAN *)pval; | - | ||||||||||||
| 586 | if (*tbool == -1)
| 0 | ||||||||||||
| 587 | return -1; never executed: return -1; | 0 | ||||||||||||
| 588 | if (it->utype != V_ASN1_ANY) {
| 0 | ||||||||||||
| 589 | /* Default handling if value == size field then omit */ | - | ||||||||||||
| 590 | if (*tbool && (it->size > 0))
| 0 | ||||||||||||
| 591 | return -1; never executed: return -1; | 0 | ||||||||||||
| 592 | if (!*tbool && !it->size)
| 0 | ||||||||||||
| 593 | return -1; never executed: return -1; | 0 | ||||||||||||
| 594 | } never executed: end of block | 0 | ||||||||||||
| 595 | c = (unsigned char)*tbool; | - | ||||||||||||
| 596 | cont = &c; | - | ||||||||||||
| 597 | len = 1; | - | ||||||||||||
| 598 | break; never executed: break; | 0 | ||||||||||||
| 599 | - | |||||||||||||
| 600 | case V_ASN1_BIT_STRING: executed 1306 times by 6 tests: case 3:Executed by:
| 1306 | ||||||||||||
| 601 | return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, executed 1306 times by 6 tests: return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : ((void *)0) );Executed by:
| 1306 | ||||||||||||
| 602 | cout ? &cout : NULL); executed 1306 times by 6 tests: return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : ((void *)0) );Executed by:
| 1306 | ||||||||||||
| 603 | break; dead code: break; | - | ||||||||||||
| 604 | - | |||||||||||||
| 605 | case V_ASN1_INTEGER: executed 206 times by 4 tests: case 2:Executed by:
| 206 | ||||||||||||
| 606 | case V_ASN1_ENUMERATED: never executed: case 10: | 0 | ||||||||||||
| 607 | /* These are all have the same content format | - | ||||||||||||
| 608 | * as ASN1_INTEGER | - | ||||||||||||
| 609 | */ | - | ||||||||||||
| 610 | return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, executed 206 times by 4 tests: return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : ((void *)0) );Executed by:
| 206 | ||||||||||||
| 611 | cout ? &cout : NULL); executed 206 times by 4 tests: return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : ((void *)0) );Executed by:
| 206 | ||||||||||||
| 612 | break; dead code: break; | - | ||||||||||||
| 613 | - | |||||||||||||
| 614 | case V_ASN1_OCTET_STRING: executed 677 times by 7 tests: case 4:Executed by:
| 677 | ||||||||||||
| 615 | case V_ASN1_NUMERICSTRING: never executed: case 18: | 0 | ||||||||||||
| 616 | case V_ASN1_PRINTABLESTRING: executed 20 times by 1 test: case 19:Executed by:
| 20 | ||||||||||||
| 617 | case V_ASN1_T61STRING: never executed: case 20: | 0 | ||||||||||||
| 618 | case V_ASN1_VIDEOTEXSTRING: never executed: case 21: | 0 | ||||||||||||
| 619 | case V_ASN1_IA5STRING: executed 88 times by 1 test: case 22:Executed by:
| 88 | ||||||||||||
| 620 | case V_ASN1_UTCTIME: executed 102 times by 3 tests: case 23:Executed by:
| 102 | ||||||||||||
| 621 | case V_ASN1_GENERALIZEDTIME: executed 6 times by 1 test: case 24:Executed by:
| 6 | ||||||||||||
| 622 | case V_ASN1_GRAPHICSTRING: never executed: case 25: | 0 | ||||||||||||
| 623 | case V_ASN1_VISIBLESTRING: never executed: case 26: | 0 | ||||||||||||
| 624 | case V_ASN1_GENERALSTRING: never executed: case 27: | 0 | ||||||||||||
| 625 | case V_ASN1_UNIVERSALSTRING: never executed: case 28: | 0 | ||||||||||||
| 626 | case V_ASN1_BMPSTRING: never executed: case 30: | 0 | ||||||||||||
| 627 | case V_ASN1_UTF8STRING: executed 9500 times by 8 tests: case 12:Executed by:
| 9500 | ||||||||||||
| 628 | case V_ASN1_SEQUENCE: executed 64 times by 2 tests: case 16:Executed by:
| 64 | ||||||||||||
| 629 | case V_ASN1_SET: never executed: case 17: | 0 | ||||||||||||
| 630 | default: never executed: default: | 0 | ||||||||||||
| 631 | /* All based on ASN1_STRING and handled the same */ | - | ||||||||||||
| 632 | strtmp = (ASN1_STRING *)*pval; | - | ||||||||||||
| 633 | /* Special handling for NDEF */ | - | ||||||||||||
| 634 | if ((it->size == ASN1_TFLG_NDEF) &&
| 15-10442 | ||||||||||||
| 635 | (strtmp->flags & ASN1_STRING_FLAG_NDEF)) {
| 0-15 | ||||||||||||
| 636 | if (cout) {
| 0 | ||||||||||||
| 637 | strtmp->data = cout; | - | ||||||||||||
| 638 | strtmp->length = 0; | - | ||||||||||||
| 639 | } never executed: end of block | 0 | ||||||||||||
| 640 | /* Special return code */ | - | ||||||||||||
| 641 | return -2; never executed: return -2; | 0 | ||||||||||||
| 642 | } | - | ||||||||||||
| 643 | cont = strtmp->data; | - | ||||||||||||
| 644 | len = strtmp->length; | - | ||||||||||||
| 645 | - | |||||||||||||
| 646 | break; executed 10457 times by 10 tests: break;Executed by:
| 10457 | ||||||||||||
| 647 | - | |||||||||||||
| 648 | } | - | ||||||||||||
| 649 | if (cout && len)
| 469-20134 | ||||||||||||
| 650 | memcpy(cout, cont, len); executed 4554 times by 10 tests: memcpy(cout, cont, len);Executed by:
| 4554 | ||||||||||||
| 651 | return len; executed 25157 times by 10 tests: return len;Executed by:
| 25157 | ||||||||||||
| 652 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |