• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
59 #include <limits.h>
60 #include <string.h>
61 
62 #include <openssl/asn1t.h>
63 #include <openssl/mem.h>
64 
65 #include "../internal.h"
66 #include "internal.h"
67 
68 
69 static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
70                                  const ASN1_ITEM *it, int tag, int aclass);
71 static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
72                        const ASN1_ITEM *it);
73 static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
74                             int skcontlen, const ASN1_ITEM *item,
75                             int do_sort, int iclass);
76 static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
77                                 const ASN1_TEMPLATE *tt, int tag, int aclass);
78 static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
79                                const ASN1_ITEM *it, int flags);
80 
81 /*
82  * Top level i2d equivalents
83  */
84 
ASN1_item_i2d(ASN1_VALUE * val,unsigned char ** out,const ASN1_ITEM * it)85 int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
86 {
87     return asn1_item_flags_i2d(val, out, it, 0);
88 }
89 
90 /*
91  * Encode an ASN1 item, this is use by the standard 'i2d' function. 'out'
92  * points to a buffer to output the data to. The new i2d has one additional
93  * feature. If the output buffer is NULL (i.e. *out == NULL) then a buffer is
94  * allocated and populated with the encoding.
95  */
96 
asn1_item_flags_i2d(ASN1_VALUE * val,unsigned char ** out,const ASN1_ITEM * it,int flags)97 static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
98                                const ASN1_ITEM *it, int flags)
99 {
100     if (out && !*out) {
101         unsigned char *p, *buf;
102         int len;
103         len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);
104         if (len <= 0)
105             return len;
106         buf = OPENSSL_malloc(len);
107         if (!buf)
108             return -1;
109         p = buf;
110         ASN1_item_ex_i2d(&val, &p, it, -1, flags);
111         *out = buf;
112         return len;
113     }
114 
115     return ASN1_item_ex_i2d(&val, out, it, -1, flags);
116 }
117 
118 /*
119  * Encode an item, taking care of IMPLICIT tagging (if any). This function
120  * performs the normal item handling: it can be used in external types.
121  */
122 
ASN1_item_ex_i2d(ASN1_VALUE ** pval,unsigned char ** out,const ASN1_ITEM * it,int tag,int aclass)123 int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
124                      const ASN1_ITEM *it, int tag, int aclass)
125 {
126     const ASN1_TEMPLATE *tt = NULL;
127     int i, seqcontlen, seqlen;
128     const ASN1_EXTERN_FUNCS *ef;
129     const ASN1_AUX *aux = it->funcs;
130     ASN1_aux_cb *asn1_cb = 0;
131 
132     if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
133         return 0;
134 
135     if (aux && aux->asn1_cb)
136         asn1_cb = aux->asn1_cb;
137 
138     switch (it->itype) {
139 
140     case ASN1_ITYPE_PRIMITIVE:
141         if (it->templates)
142             return asn1_template_ex_i2d(pval, out, it->templates,
143                                         tag, aclass);
144         return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
145         break;
146 
147     case ASN1_ITYPE_MSTRING:
148         /*
149          * It never makes sense for multi-strings to have implicit tagging, so
150          * if tag != -1, then this looks like an error in the template.
151          */
152         if (tag != -1) {
153             OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
154             return -1;
155         }
156         return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
157 
158     case ASN1_ITYPE_CHOICE:
159         /*
160          * It never makes sense for CHOICE types to have implicit tagging, so if
161          * tag != -1, then this looks like an error in the template.
162          */
163         if (tag != -1) {
164             OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
165             return -1;
166         }
167         if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
168             return 0;
169         i = asn1_get_choice_selector(pval, it);
170         if ((i >= 0) && (i < it->tcount)) {
171             ASN1_VALUE **pchval;
172             const ASN1_TEMPLATE *chtt;
173             chtt = it->templates + i;
174             pchval = asn1_get_field_ptr(pval, chtt);
175             return asn1_template_ex_i2d(pchval, out, chtt, -1, aclass);
176         }
177         /* Fixme: error condition if selector out of range */
178         if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
179             return 0;
180         break;
181 
182     case ASN1_ITYPE_EXTERN:
183         /* If new style i2d it does all the work */
184         ef = it->funcs;
185         return ef->asn1_ex_i2d(pval, out, it, tag, aclass);
186 
187     case ASN1_ITYPE_SEQUENCE:
188         i = asn1_enc_restore(&seqcontlen, out, pval, it);
189         /* An error occurred */
190         if (i < 0)
191             return 0;
192         /* We have a valid cached encoding... */
193         if (i > 0)
194             return seqcontlen;
195         /* Otherwise carry on */
196         seqcontlen = 0;
197         /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
198         if (tag == -1) {
199             tag = V_ASN1_SEQUENCE;
200             /* Retain any other flags in aclass */
201             aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)
202                 | V_ASN1_UNIVERSAL;
203         }
204         if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
205             return 0;
206         /* First work out sequence content length */
207         for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
208             const ASN1_TEMPLATE *seqtt;
209             ASN1_VALUE **pseqval;
210             int tmplen;
211             seqtt = asn1_do_adb(pval, tt, 1);
212             if (!seqtt)
213                 return 0;
214             pseqval = asn1_get_field_ptr(pval, seqtt);
215             tmplen = asn1_template_ex_i2d(pseqval, NULL, seqtt, -1, aclass);
216             if (tmplen == -1 || (tmplen > INT_MAX - seqcontlen))
217                 return -1;
218             seqcontlen += tmplen;
219         }
220 
221         seqlen = ASN1_object_size(/*constructed=*/1, seqcontlen, tag);
222         if (!out || seqlen == -1)
223             return seqlen;
224         /* Output SEQUENCE header */
225         ASN1_put_object(out, /*constructed=*/1, seqcontlen, tag, aclass);
226         for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
227             const ASN1_TEMPLATE *seqtt;
228             ASN1_VALUE **pseqval;
229             seqtt = asn1_do_adb(pval, tt, 1);
230             if (!seqtt)
231                 return 0;
232             pseqval = asn1_get_field_ptr(pval, seqtt);
233             /* FIXME: check for errors in enhanced version */
234             asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass);
235         }
236         if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))
237             return 0;
238         return seqlen;
239 
240     default:
241         return 0;
242 
243     }
244     return 0;
245 }
246 
asn1_template_ex_i2d(ASN1_VALUE ** pval,unsigned char ** out,const ASN1_TEMPLATE * tt,int tag,int iclass)247 static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
248                                 const ASN1_TEMPLATE *tt, int tag, int iclass)
249 {
250     int i, ret, flags, ttag, tclass;
251     size_t j;
252     flags = tt->flags;
253     /*
254      * Work out tag and class to use: tagging may come either from the
255      * template or the arguments, not both because this would create
256      * ambiguity. Additionally the iclass argument may contain some
257      * additional flags which should be noted and passed down to other
258      * levels.
259      */
260     if (flags & ASN1_TFLG_TAG_MASK) {
261         /* Error if argument and template tagging */
262         if (tag != -1)
263             /* FIXME: error code here */
264             return -1;
265         /* Get tagging from template */
266         ttag = tt->tag;
267         tclass = flags & ASN1_TFLG_TAG_CLASS;
268     } else if (tag != -1) {
269         /* No template tagging, get from arguments */
270         ttag = tag;
271         tclass = iclass & ASN1_TFLG_TAG_CLASS;
272     } else {
273         ttag = -1;
274         tclass = 0;
275     }
276     /*
277      * Remove any class mask from iflag.
278      */
279     iclass &= ~ASN1_TFLG_TAG_CLASS;
280 
281     /*
282      * At this point 'ttag' contains the outer tag to use, 'tclass' is the
283      * class and iclass is any flags passed to this function.
284      */
285 
286     if (flags & ASN1_TFLG_SK_MASK) {
287         /* SET OF, SEQUENCE OF */
288         STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
289         int isset, sktag, skaclass;
290         int skcontlen, sklen;
291         ASN1_VALUE *skitem;
292 
293         if (!*pval)
294             return 0;
295 
296         if (flags & ASN1_TFLG_SET_OF) {
297             isset = 1;
298             /* Historically, types with both bits set were mutated when
299              * serialized to apply the sort. We no longer support this. */
300             assert((flags & ASN1_TFLG_SEQUENCE_OF) == 0);
301         } else {
302             isset = 0;
303         }
304 
305         /*
306          * Work out inner tag value: if EXPLICIT or no tagging use underlying
307          * type.
308          */
309         if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) {
310             sktag = ttag;
311             skaclass = tclass;
312         } else {
313             skaclass = V_ASN1_UNIVERSAL;
314             if (isset)
315                 sktag = V_ASN1_SET;
316             else
317                 sktag = V_ASN1_SEQUENCE;
318         }
319 
320         /* Determine total length of items */
321         skcontlen = 0;
322         for (j = 0; j < sk_ASN1_VALUE_num(sk); j++) {
323             int tmplen;
324             skitem = sk_ASN1_VALUE_value(sk, j);
325             tmplen = ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item),
326                                       -1, iclass);
327             if (tmplen == -1 || (skcontlen > INT_MAX - tmplen))
328                 return -1;
329             skcontlen += tmplen;
330         }
331         sklen = ASN1_object_size(/*constructed=*/1, skcontlen, sktag);
332         if (sklen == -1)
333             return -1;
334         /* If EXPLICIT need length of surrounding tag */
335         if (flags & ASN1_TFLG_EXPTAG)
336             ret = ASN1_object_size(/*constructed=*/1, sklen, ttag);
337         else
338             ret = sklen;
339 
340         if (!out || ret == -1)
341             return ret;
342 
343         /* Now encode this lot... */
344         /* EXPLICIT tag */
345         if (flags & ASN1_TFLG_EXPTAG)
346             ASN1_put_object(out, /*constructed=*/1, sklen, ttag, tclass);
347         /* SET or SEQUENCE and IMPLICIT tag */
348         ASN1_put_object(out, /*constructed=*/1, skcontlen, sktag, skaclass);
349         /* And the stuff itself */
350         asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),
351                          isset, iclass);
352         return ret;
353     }
354 
355     if (flags & ASN1_TFLG_EXPTAG) {
356         /* EXPLICIT tagging */
357         /* Find length of tagged item */
358         i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, iclass);
359         if (!i)
360             return 0;
361         /* Find length of EXPLICIT tag */
362         ret = ASN1_object_size(/*constructed=*/1, i, ttag);
363         if (out && ret != -1) {
364             /* Output tag and item */
365             ASN1_put_object(out, /*constructed=*/1, i, ttag, tclass);
366             ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, iclass);
367         }
368         return ret;
369     }
370 
371     /* Either normal or IMPLICIT tagging: combine class and flags */
372     return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
373                             ttag, tclass | iclass);
374 
375 }
376 
377 /* Temporary structure used to hold DER encoding of items for SET OF */
378 
379 typedef struct {
380     unsigned char *data;
381     int length;
382 } DER_ENC;
383 
der_cmp(const void * a,const void * b)384 static int der_cmp(const void *a, const void *b)
385 {
386     const DER_ENC *d1 = a, *d2 = b;
387     int cmplen, i;
388     cmplen = (d1->length < d2->length) ? d1->length : d2->length;
389     i = OPENSSL_memcmp(d1->data, d2->data, cmplen);
390     if (i)
391         return i;
392     return d1->length - d2->length;
393 }
394 
395 /* Output the content octets of SET OF or SEQUENCE OF */
396 
asn1_set_seq_out(STACK_OF (ASN1_VALUE)* sk,unsigned char ** out,int skcontlen,const ASN1_ITEM * item,int do_sort,int iclass)397 static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
398                             int skcontlen, const ASN1_ITEM *item,
399                             int do_sort, int iclass)
400 {
401     size_t i;
402     ASN1_VALUE *skitem;
403     unsigned char *tmpdat = NULL, *p = NULL;
404     DER_ENC *derlst = NULL, *tder;
405     if (do_sort) {
406         /* Don't need to sort less than 2 items */
407         if (sk_ASN1_VALUE_num(sk) < 2)
408             do_sort = 0;
409         else {
410             derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk)
411                                     * sizeof(*derlst));
412             if (!derlst)
413                 return 0;
414             tmpdat = OPENSSL_malloc(skcontlen);
415             if (!tmpdat) {
416                 OPENSSL_free(derlst);
417                 return 0;
418             }
419         }
420     }
421     /* If not sorting just output each item */
422     if (!do_sort) {
423         for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
424             skitem = sk_ASN1_VALUE_value(sk, i);
425             ASN1_item_ex_i2d(&skitem, out, item, -1, iclass);
426         }
427         return 1;
428     }
429     p = tmpdat;
430 
431     /* Doing sort: build up a list of each member's DER encoding */
432     for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
433         skitem = sk_ASN1_VALUE_value(sk, i);
434         tder->data = p;
435         tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass);
436     }
437 
438     /* Now sort them */
439     qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
440     /* Output sorted DER encoding */
441     p = *out;
442     for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
443         OPENSSL_memcpy(p, tder->data, tder->length);
444         p += tder->length;
445     }
446     *out = p;
447     OPENSSL_free(derlst);
448     OPENSSL_free(tmpdat);
449     return 1;
450 }
451 
asn1_i2d_ex_primitive(ASN1_VALUE ** pval,unsigned char ** out,const ASN1_ITEM * it,int tag,int aclass)452 static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
453                                  const ASN1_ITEM *it, int tag, int aclass)
454 {
455     int len;
456     int utype;
457     int usetag;
458 
459     utype = it->utype;
460 
461     /*
462      * Get length of content octets and maybe find out the underlying type.
463      */
464 
465     len = asn1_ex_i2c(pval, NULL, &utype, it);
466 
467     /*
468      * If SEQUENCE, SET or OTHER then header is included in pseudo content
469      * octets so don't include tag+length. We need to check here because the
470      * call to asn1_ex_i2c() could change utype.
471      */
472     if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
473         (utype == V_ASN1_OTHER))
474         usetag = 0;
475     else
476         usetag = 1;
477 
478     /* -1 means omit type */
479 
480     if (len == -1)
481         return 0;
482 
483     /* If not implicitly tagged get tag from underlying type */
484     if (tag == -1)
485         tag = utype;
486 
487     /* Output tag+length followed by content octets */
488     if (out) {
489         if (usetag)
490             ASN1_put_object(out, /*constructed=*/0, len, tag, aclass);
491         asn1_ex_i2c(pval, *out, &utype, it);
492         *out += len;
493     }
494 
495     if (usetag)
496         return ASN1_object_size(/*constructed=*/0, len, tag);
497     return len;
498 }
499 
500 /* Produce content octets from a structure */
501 
asn1_ex_i2c(ASN1_VALUE ** pval,unsigned char * cout,int * putype,const ASN1_ITEM * it)502 static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
503                        const ASN1_ITEM *it)
504 {
505     ASN1_BOOLEAN *tbool = NULL;
506     ASN1_STRING *strtmp;
507     ASN1_OBJECT *otmp;
508     int utype;
509     const unsigned char *cont;
510     unsigned char c;
511     int len;
512 
513     /* Historically, |it->funcs| for primitive types contained an
514      * |ASN1_PRIMITIVE_FUNCS| table of callbacks. */
515     assert(it->funcs == NULL);
516 
517     /* Should type be omitted? */
518     if ((it->itype != ASN1_ITYPE_PRIMITIVE)
519         || (it->utype != V_ASN1_BOOLEAN)) {
520         if (!*pval)
521             return -1;
522     }
523 
524     if (it->itype == ASN1_ITYPE_MSTRING) {
525         /* If MSTRING type set the underlying type */
526         strtmp = (ASN1_STRING *)*pval;
527         utype = strtmp->type;
528         /* Negative INTEGER and ENUMERATED values use |ASN1_STRING| type values
529          * that do not match their corresponding utype values. INTEGERs cannot
530          * participate in MSTRING types, but ENUMERATEDs can.
531          *
532          * TODO(davidben): Is this a bug? Although arguably one of the MSTRING
533          * types should contain more values, rather than less. See
534          * https://crbug.com/boringssl/412. But it is not possible to fit all
535          * possible ANY values into an |ASN1_STRING|, so matching the spec here
536          * is somewhat hopeless. */
537         if (utype == V_ASN1_NEG_INTEGER) {
538             utype = V_ASN1_INTEGER;
539         } else if (utype == V_ASN1_NEG_ENUMERATED) {
540             utype = V_ASN1_ENUMERATED;
541         }
542         *putype = utype;
543     } else if (it->utype == V_ASN1_ANY) {
544         /* If ANY set type and pointer to value */
545         ASN1_TYPE *typ;
546         typ = (ASN1_TYPE *)*pval;
547         utype = typ->type;
548         *putype = utype;
549         pval = &typ->value.asn1_value;
550     } else
551         utype = *putype;
552 
553     switch (utype) {
554     case V_ASN1_OBJECT:
555         otmp = (ASN1_OBJECT *)*pval;
556         cont = otmp->data;
557         len = otmp->length;
558         if (cont == NULL || len == 0)
559             return -1;
560         break;
561 
562     case V_ASN1_NULL:
563         cont = NULL;
564         len = 0;
565         break;
566 
567     case V_ASN1_BOOLEAN:
568         tbool = (ASN1_BOOLEAN *)pval;
569         if (*tbool == -1)
570             return -1;
571         if (it->utype != V_ASN1_ANY) {
572             /*
573              * Default handling if value == size field then omit
574              */
575             if (*tbool && (it->size > 0))
576                 return -1;
577             if (!*tbool && !it->size)
578                 return -1;
579         }
580         c = *tbool ? 0xff : 0x00;
581         cont = &c;
582         len = 1;
583         break;
584 
585     case V_ASN1_BIT_STRING:
586         return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval,
587                                    cout ? &cout : NULL);
588         break;
589 
590     case V_ASN1_INTEGER:
591     case V_ASN1_ENUMERATED:
592         /*
593          * These are all have the same content format as ASN1_INTEGER
594          */
595         return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
596         break;
597 
598     case V_ASN1_OCTET_STRING:
599     case V_ASN1_NUMERICSTRING:
600     case V_ASN1_PRINTABLESTRING:
601     case V_ASN1_T61STRING:
602     case V_ASN1_VIDEOTEXSTRING:
603     case V_ASN1_IA5STRING:
604     case V_ASN1_UTCTIME:
605     case V_ASN1_GENERALIZEDTIME:
606     case V_ASN1_GRAPHICSTRING:
607     case V_ASN1_VISIBLESTRING:
608     case V_ASN1_GENERALSTRING:
609     case V_ASN1_UNIVERSALSTRING:
610     case V_ASN1_BMPSTRING:
611     case V_ASN1_UTF8STRING:
612     case V_ASN1_SEQUENCE:
613     case V_ASN1_SET:
614     default:
615         /* All based on ASN1_STRING and handled the same */
616         strtmp = (ASN1_STRING *)*pval;
617         cont = strtmp->data;
618         len = strtmp->length;
619 
620         break;
621 
622     }
623     if (cout && len)
624         OPENSSL_memcpy(cout, cont, len);
625     return len;
626 }
627