2 * Copyright (C) 2002, 2004, 2006, 2008, 2009, 2010 Free Software
5 * This file is part of LIBTASN1.
7 * The LIBTASN1 library is free software; you can redistribute it
8 * and/or modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 /*****************************************************/
26 /* Description: Functions to create a DER coding of */
28 /*****************************************************/
31 #include "parser_aux.h"
34 #include <structure.h>
36 #define MAX_TAG_LEN 16
38 /******************************************************/
39 /* Function : _asn1_error_description_value_not_found */
40 /* Description: creates the ErrorDescription string */
41 /* for the ASN1_VALUE_NOT_FOUND error. */
43 /* node: node of the tree where the value is NULL. */
44 /* ErrorDescription: string returned. */
46 /******************************************************/
48 _asn1_error_description_value_not_found (ASN1_TYPE node,
49 char *ErrorDescription)
52 if (ErrorDescription == NULL)
55 Estrcpy (ErrorDescription, ":: value of element '");
56 _asn1_hierarchical_name (node, ErrorDescription + strlen (ErrorDescription),
57 ASN1_MAX_ERROR_DESCRIPTION_SIZE - 40);
58 Estrcat (ErrorDescription, "' not found");
64 * @len: value to convert.
65 * @ans: string returned.
66 * @ans_len: number of meaningful bytes of ANS (ans[0]..ans[ans_len-1]).
68 * Creates the DER coding for the LEN parameter (only the length).
69 * The @ans buffer is pre-allocated and must have room for the output.
72 asn1_length_der (unsigned long int len, unsigned char *ans, int *ans_len)
75 unsigned char temp[SIZEOF_UNSIGNED_LONG_INT];
81 ans[0] = (unsigned char) len;
90 temp[k++] = len & 0xFF;
96 ans[0] = ((unsigned char) k & 0x7F) + 128;
98 ans[*ans_len - 1 - k] = temp[k];
103 /******************************************************/
104 /* Function : _asn1_tag_der */
105 /* Description: creates the DER coding for the CLASS */
106 /* and TAG parameters. */
108 /* class: value to convert. */
109 /* tag_value: value to convert. */
110 /* ans: string returned. */
111 /* ans_len: number of meaningful bytes of ANS */
112 /* (ans[0]..ans[ans_len-1]). */
114 /******************************************************/
116 _asn1_tag_der (unsigned char class, unsigned int tag_value,
117 unsigned char *ans, int *ans_len)
120 unsigned char temp[SIZEOF_UNSIGNED_INT];
125 ans[0] = (class & 0xE0) + ((unsigned char) (tag_value & 0x1F));
131 ans[0] = (class & 0xE0) + 31;
135 temp[k++] = tag_value & 0x7F;
136 tag_value = tag_value >> 7;
140 ans[*ans_len - 1 - k] = temp[k] + 128;
141 ans[*ans_len - 1] -= 128;
147 * @str: OCTET string.
148 * @str_len: STR length (str[0]..str[str_len-1]).
149 * @der: string returned.
150 * @der_len: number of meaningful bytes of DER (der[0]..der[ans_len-1]).
152 * Creates the DER coding for an OCTET type (length included).
155 asn1_octet_der (const unsigned char *str, int str_len,
156 unsigned char *der, int *der_len)
160 if (der == NULL || str_len < 0)
162 asn1_length_der (str_len, der, &len_len);
163 memcpy (der + len_len, str, str_len);
164 *der_len = str_len + len_len;
167 /******************************************************/
168 /* Function : _asn1_time_der */
169 /* Description: creates the DER coding for a TIME */
170 /* type (length included). */
172 /* str: TIME null-terminated string. */
173 /* der: string returned. */
174 /* der_len: number of meaningful bytes of DER */
175 /* (der[0]..der[ans_len-1]). Initially it */
176 /* if must store the lenght of DER. */
178 /* ASN1_MEM_ERROR when DER isn't big enough */
179 /* ASN1_SUCCESS otherwise */
180 /******************************************************/
182 _asn1_time_der (unsigned char *str, unsigned char *der, int *der_len)
189 asn1_length_der (strlen (str), (max_len > 0) ? der : NULL, &len_len);
191 if ((len_len + (int) strlen (str)) <= max_len)
192 memcpy (der + len_len, str, strlen (str));
193 *der_len = len_len + strlen (str);
195 if ((*der_len) > max_len)
196 return ASN1_MEM_ERROR;
204 _asn1_get_utctime_der(unsigned char *der,int *der_len,unsigned char *str)
209 if(str==NULL) return;
210 str_len=asn1_get_length_der(der,*der_len,&len_len);
211 if (str_len<0) return;
212 memcpy(temp,der+len_len,str_len);
213 *der_len=str_len+len_len;
217 strcat(temp,"00+0000");
221 strcat(temp,"+0000");
225 memmove(temp+12,temp+10,6);
226 temp[10]=temp[11]='0';
238 /******************************************************/
239 /* Function : _asn1_objectid_der */
240 /* Description: creates the DER coding for an */
241 /* OBJECT IDENTIFIER type (length included). */
243 /* str: OBJECT IDENTIFIER null-terminated string. */
244 /* der: string returned. */
245 /* der_len: number of meaningful bytes of DER */
246 /* (der[0]..der[ans_len-1]). Initially it */
247 /* must store the length of DER. */
249 /* ASN1_MEM_ERROR when DER isn't big enough */
250 /* ASN1_SUCCESS otherwise */
251 /******************************************************/
253 _asn1_objectid_der (unsigned char *str, unsigned char *der, int *der_len)
255 int len_len, counter, k, first, max_len;
256 char *temp, *n_end, *n_start;
258 unsigned long val, val1 = 0;
262 temp = (char *) _asn1_malloc (strlen (str) + 2);
264 return ASN1_MEM_ALLOC_ERROR;
271 while ((n_end = strchr (n_start, '.')))
274 val = strtoul (n_start, NULL, 10);
279 else if (counter == 2)
282 der[0] = 40 * val1 + val;
288 for (k = 4; k >= 0; k--)
290 bit7 = (val >> (k * 7)) & 0x7F;
291 if (bit7 || first || !k)
295 if (max_len > (*der_len))
296 der[*der_len] = bit7;
306 asn1_length_der (*der_len, NULL, &len_len);
307 if (max_len >= (*der_len + len_len))
309 memmove (der + len_len, der, *der_len);
310 asn1_length_der (*der_len, der, &len_len);
316 if (max_len < (*der_len))
317 return ASN1_MEM_ERROR;
323 const char bit_mask[] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80 };
328 * @bit_len: number of meaningful bits in STR.
329 * @der: string returned.
330 * @der_len: number of meaningful bytes of DER
331 * (der[0]..der[ans_len-1]).
333 * Creates the DER coding for a BIT STRING type (length and pad
337 asn1_bit_der (const unsigned char *str, int bit_len,
338 unsigned char *der, int *der_len)
340 int len_len, len_byte, len_pad;
344 len_byte = bit_len >> 3;
345 len_pad = 8 - (bit_len & 7);
350 asn1_length_der (len_byte + 1, der, &len_len);
351 der[len_len] = len_pad;
352 memcpy (der + len_len + 1, str, len_byte);
353 der[len_len + len_byte] &= bit_mask[len_pad];
354 *der_len = len_byte + len_len + 1;
358 /******************************************************/
359 /* Function : _asn1_complete_explicit_tag */
360 /* Description: add the length coding to the EXPLICIT */
363 /* node: pointer to the tree element. */
364 /* der: string with the DER coding of the whole tree*/
365 /* counter: number of meaningful bytes of DER */
366 /* (der[0]..der[*counter-1]). */
367 /* max_len: size of der vector */
369 /* ASN1_MEM_ERROR if der vector isn't big enough, */
370 /* otherwise ASN1_SUCCESS. */
371 /******************************************************/
373 _asn1_complete_explicit_tag (ASN1_TYPE node, unsigned char *der,
374 int *counter, int *max_len)
377 int is_tag_implicit, len2, len3;
378 unsigned char temp[SIZEOF_UNSIGNED_INT];
382 if (node->type & CONST_TAG)
385 /* When there are nested tags we must complete them reverse to
386 the order they were created. This is because completing a tag
387 modifies all data within it, including the incomplete tags
388 which store buffer positions -- simon@josefsson.org 2002-09-06
392 while (p && p != node->down->left)
394 if (type_field (p->type) == TYPE_TAG)
396 if (p->type & CONST_EXPLICIT)
398 len2 = strtol (p->name, NULL, 10);
399 _asn1_set_name (p, NULL);
400 asn1_length_der (*counter - len2, temp, &len3);
401 if (len3 <= (*max_len))
403 memmove (der + len2 + len3, der + len2,
405 memcpy (der + len2, temp, len3);
412 { /* CONST_IMPLICIT */
413 if (!is_tag_implicit)
424 return ASN1_MEM_ERROR;
430 /******************************************************/
431 /* Function : _asn1_insert_tag_der */
432 /* Description: creates the DER coding of tags of one */
435 /* node: pointer to the tree element. */
436 /* der: string returned */
437 /* counter: number of meaningful bytes of DER */
438 /* (counter[0]..der[*counter-1]). */
439 /* max_len: size of der vector */
441 /* ASN1_GENERIC_ERROR if the type is unknown, */
442 /* ASN1_MEM_ERROR if der vector isn't big enough, */
443 /* otherwise ASN1_SUCCESS. */
444 /******************************************************/
446 _asn1_insert_tag_der (ASN1_TYPE node, unsigned char *der, int *counter,
450 int tag_len, is_tag_implicit;
451 unsigned char class, class_implicit = 0, temp[SIZEOF_UNSIGNED_INT * 3 + 1];
452 unsigned long tag_implicit = 0;
453 char tag_der[MAX_TAG_LEN];
457 if (node->type & CONST_TAG)
462 if (type_field (p->type) == TYPE_TAG)
464 if (p->type & CONST_APPLICATION)
465 class = ASN1_CLASS_APPLICATION;
466 else if (p->type & CONST_UNIVERSAL)
467 class = ASN1_CLASS_UNIVERSAL;
468 else if (p->type & CONST_PRIVATE)
469 class = ASN1_CLASS_PRIVATE;
471 class = ASN1_CLASS_CONTEXT_SPECIFIC;
473 if (p->type & CONST_EXPLICIT)
476 _asn1_tag_der (class_implicit, tag_implicit, tag_der,
479 _asn1_tag_der (class | ASN1_CLASS_STRUCTURED,
480 strtoul (p->value, NULL, 10), tag_der,
485 memcpy (der + *counter, tag_der, tag_len);
488 _asn1_ltostr (*counter, temp);
489 _asn1_set_name (p, temp);
494 { /* CONST_IMPLICIT */
495 if (!is_tag_implicit)
497 if ((type_field (node->type) == TYPE_SEQUENCE) ||
498 (type_field (node->type) == TYPE_SEQUENCE_OF) ||
499 (type_field (node->type) == TYPE_SET) ||
500 (type_field (node->type) == TYPE_SET_OF))
501 class |= ASN1_CLASS_STRUCTURED;
502 class_implicit = class;
503 tag_implicit = strtoul (p->value, NULL, 10);
514 _asn1_tag_der (class_implicit, tag_implicit, tag_der, &tag_len);
518 switch (type_field (node->type))
521 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_NULL, tag_der,
525 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_BOOLEAN, tag_der,
529 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_INTEGER, tag_der,
532 case TYPE_ENUMERATED:
533 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_ENUMERATED, tag_der,
537 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_OBJECT_ID, tag_der,
541 if (node->type & CONST_UTC)
543 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_UTCTime, tag_der,
547 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_GENERALIZEDTime,
550 case TYPE_OCTET_STRING:
551 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_OCTET_STRING, tag_der,
554 case TYPE_GENERALSTRING:
555 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_GENERALSTRING,
558 case TYPE_BIT_STRING:
559 _asn1_tag_der (ASN1_CLASS_UNIVERSAL, ASN1_TAG_BIT_STRING, tag_der,
563 case TYPE_SEQUENCE_OF:
564 _asn1_tag_der (ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED,
565 ASN1_TAG_SEQUENCE, tag_der, &tag_len);
569 _asn1_tag_der (ASN1_CLASS_UNIVERSAL | ASN1_CLASS_STRUCTURED,
570 ASN1_TAG_SET, tag_der, &tag_len);
582 return ASN1_GENERIC_ERROR;
588 memcpy (der + *counter, tag_der, tag_len);
592 return ASN1_MEM_ERROR;
597 /******************************************************/
598 /* Function : _asn1_ordering_set */
599 /* Description: puts the elements of a SET type in */
600 /* the correct order according to DER rules. */
602 /* der: string with the DER coding. */
603 /* node: pointer to the SET element. */
605 /******************************************************/
607 _asn1_ordering_set (unsigned char *der, int der_len, ASN1_TYPE node)
613 struct vet *next, *prev;
616 int counter, len, len2;
617 struct vet *first, *last, *p_vet, *p2_vet;
619 unsigned char class, *temp;
624 if (type_field (node->type) != TYPE_SET)
628 while ((type_field (p->type) == TYPE_TAG)
629 || (type_field (p->type) == TYPE_SIZE))
632 if ((p == NULL) || (p->right == NULL))
638 p_vet = (struct vet *) _asn1_malloc (sizeof (struct vet));
650 /* tag value calculation */
652 (der + counter, der_len - counter, &class, &len2,
653 &tag) != ASN1_SUCCESS)
655 p_vet->value = (class << 24) | tag;
658 /* extraction and length */
659 len2 = asn1_get_length_der (der + counter, der_len - counter, &len);
662 counter += len + len2;
664 p_vet->end = counter;
672 p2_vet = p_vet->next;
676 if (p_vet->value > p2_vet->value)
678 /* change position */
679 temp = (unsigned char *) _asn1_malloc (p_vet->end - counter);
683 memcpy (temp, der + counter, p_vet->end - counter);
684 memcpy (der + counter, der + p_vet->end,
685 p2_vet->end - p_vet->end);
686 memcpy (der + counter + p2_vet->end - p_vet->end, temp,
687 p_vet->end - counter);
691 p_vet->value = p2_vet->value;
694 p_vet->end = counter + (p2_vet->end - p_vet->end);
696 counter = p_vet->end;
698 p2_vet = p2_vet->next;
703 p_vet->prev->next = NULL;
711 /******************************************************/
712 /* Function : _asn1_ordering_set_of */
713 /* Description: puts the elements of a SET OF type in */
714 /* the correct order according to DER rules. */
716 /* der: string with the DER coding. */
717 /* node: pointer to the SET OF element. */
719 /******************************************************/
721 _asn1_ordering_set_of (unsigned char *der, int der_len, ASN1_TYPE node)
726 struct vet *next, *prev;
729 int counter, len, len2, change;
730 struct vet *first, *last, *p_vet, *p2_vet;
732 unsigned char *temp, class;
733 unsigned long k, max;
737 if (type_field (node->type) != TYPE_SET_OF)
741 while ((type_field (p->type) == TYPE_TAG)
742 || (type_field (p->type) == TYPE_SIZE))
746 if ((p == NULL) || (p->right == NULL))
752 p_vet = (struct vet *) _asn1_malloc (sizeof (struct vet));
764 /* extraction of tag and length */
765 if (der_len - counter > 0)
769 (der + counter, der_len - counter, &class, &len,
770 NULL) != ASN1_SUCCESS)
774 len2 = asn1_get_length_der (der + counter, der_len - counter, &len);
777 counter += len + len2;
780 p_vet->end = counter;
788 p2_vet = p_vet->next;
792 if ((p_vet->end - counter) > (p2_vet->end - p_vet->end))
793 max = p_vet->end - counter;
795 max = p2_vet->end - p_vet->end;
798 for (k = 0; k < max; k++)
799 if (der[counter + k] > der[p_vet->end + k])
804 else if (der[counter + k] < der[p_vet->end + k])
811 && ((p_vet->end - counter) > (p2_vet->end - p_vet->end)))
816 /* change position */
817 temp = (unsigned char *) _asn1_malloc (p_vet->end - counter);
821 memcpy (temp, der + counter, (p_vet->end) - counter);
822 memcpy (der + counter, der + (p_vet->end),
823 (p2_vet->end) - (p_vet->end));
824 memcpy (der + counter + (p2_vet->end) - (p_vet->end), temp,
825 (p_vet->end) - counter);
828 p_vet->end = counter + (p2_vet->end - p_vet->end);
830 counter = p_vet->end;
832 p2_vet = p2_vet->next;
837 p_vet->prev->next = NULL;
847 * @element: pointer to an ASN1 element
848 * @name: the name of the structure you want to encode (it must be
850 * @ider: vector that will contain the DER encoding. DER must be a
851 * pointer to memory cells already allocated.
852 * @len: number of bytes of *@ider: @ider[0]..@ider[len-1], Initialy
853 * holds the sizeof of der vector.
854 * @errorDescription : return the error description or an empty
857 * Creates the DER encoding for the NAME structure (inside *POINTER
862 * %ASN1_SUCCESS: DER encoding OK.
864 * %ASN1_ELEMENT_NOT_FOUND: NAME is not a valid element.
866 * %ASN1_VALUE_NOT_FOUND: There is an element without a value.
868 * %ASN1_MEM_ERROR: @ider vector isn't big enough. Also in this case
869 * LEN will contain the length needed.
872 asn1_der_coding (ASN1_TYPE element, const char *name, void *ider, int *len,
873 char *ErrorDescription)
875 ASN1_TYPE node, p, p2;
876 char temp[SIZEOF_UNSIGNED_LONG_INT * 3 + 1];
877 int counter, counter_old, len2, len3, tlen, move, max_len, max_len_old;
879 unsigned char *der = ider;
881 node = asn1_find_node (element, name);
883 return ASN1_ELEMENT_NOT_FOUND;
885 /* Node is now a locally allocated variable.
886 * That is because in some point we modify the
887 * structure, and I don't know why! --nmav
889 node = _asn1_copy_structure3 (node);
891 return ASN1_ELEMENT_NOT_FOUND;
901 counter_old = counter;
902 max_len_old = max_len;
905 err = _asn1_insert_tag_der (p, der, &counter, &max_len);
906 if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR)
909 switch (type_field (p->type))
919 if ((p->type & CONST_DEFAULT) && (p->value == NULL))
921 counter = counter_old;
922 max_len = max_len_old;
926 if (p->value == NULL)
928 _asn1_error_description_value_not_found (p,
930 err = ASN1_VALUE_NOT_FOUND;
937 if (p->value[0] == 'F')
940 der[counter++] = 0xFF;
948 case TYPE_ENUMERATED:
949 if ((p->type & CONST_DEFAULT) && (p->value == NULL))
951 counter = counter_old;
952 max_len = max_len_old;
956 if (p->value == NULL)
958 _asn1_error_description_value_not_found (p,
960 err = ASN1_VALUE_NOT_FOUND;
963 len2 = asn1_get_length_der (p->value, p->value_len, &len3);
966 err = ASN1_DER_ERROR;
969 max_len -= len2 + len3;
971 memcpy (der + counter, p->value, len3 + len2);
972 counter += len3 + len2;
977 if ((p->type & CONST_DEFAULT) && (p->value == NULL))
979 counter = counter_old;
980 max_len = max_len_old;
984 if (p->value == NULL)
986 _asn1_error_description_value_not_found (p,
988 err = ASN1_VALUE_NOT_FOUND;
992 err = _asn1_objectid_der (p->value, der + counter, &len2);
993 if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR)
1002 if (p->value == NULL)
1004 _asn1_error_description_value_not_found (p, ErrorDescription);
1005 err = ASN1_VALUE_NOT_FOUND;
1009 err = _asn1_time_der (p->value, der + counter, &len2);
1010 if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR)
1017 case TYPE_OCTET_STRING:
1018 if (p->value == NULL)
1020 _asn1_error_description_value_not_found (p, ErrorDescription);
1021 err = ASN1_VALUE_NOT_FOUND;
1024 len2 = asn1_get_length_der (p->value, p->value_len, &len3);
1027 err = ASN1_DER_ERROR;
1030 max_len -= len2 + len3;
1032 memcpy (der + counter, p->value, len3 + len2);
1033 counter += len3 + len2;
1036 case TYPE_GENERALSTRING:
1037 if (p->value == NULL)
1039 _asn1_error_description_value_not_found (p, ErrorDescription);
1040 err = ASN1_VALUE_NOT_FOUND;
1043 len2 = asn1_get_length_der (p->value, p->value_len, &len3);
1046 err = ASN1_DER_ERROR;
1049 max_len -= len2 + len3;
1051 memcpy (der + counter, p->value, len3 + len2);
1052 counter += len3 + len2;
1055 case TYPE_BIT_STRING:
1056 if (p->value == NULL)
1058 _asn1_error_description_value_not_found (p, ErrorDescription);
1059 err = ASN1_VALUE_NOT_FOUND;
1062 len2 = asn1_get_length_der (p->value, p->value_len, &len3);
1065 err = ASN1_DER_ERROR;
1068 max_len -= len2 + len3;
1070 memcpy (der + counter, p->value, len3 + len2);
1071 counter += len3 + len2;
1078 _asn1_ltostr (counter, temp);
1079 tlen = strlen (temp);
1081 _asn1_set_value (p, temp, tlen + 1);
1082 if (p->down == NULL)
1090 while (p2 && (type_field (p2->type) == TYPE_TAG))
1104 len2 = strtol (p->value, NULL, 10);
1105 _asn1_set_value (p, NULL, 0);
1106 if ((type_field (p->type) == TYPE_SET) && (max_len >= 0))
1107 _asn1_ordering_set (der + len2, max_len - len2, p);
1108 asn1_length_der (counter - len2, temp, &len3);
1112 memmove (der + len2 + len3, der + len2, counter - len2);
1113 memcpy (der + len2, temp, len3);
1119 case TYPE_SEQUENCE_OF:
1123 _asn1_ltostr (counter, temp);
1124 tlen = strlen (temp);
1127 _asn1_set_value (p, temp, tlen + 1);
1129 while ((type_field (p->type) == TYPE_TAG)
1130 || (type_field (p->type) == TYPE_SIZE))
1139 p = _asn1_find_up (p);
1144 len2 = strtol (p->value, NULL, 10);
1145 _asn1_set_value (p, NULL, 0);
1146 if ((type_field (p->type) == TYPE_SET_OF)
1147 && (max_len - len2 > 0))
1149 _asn1_ordering_set_of (der + len2, max_len - len2, p);
1151 asn1_length_der (counter - len2, temp, &len3);
1155 memmove (der + len2 + len3, der + len2, counter - len2);
1156 memcpy (der + len2, temp, len3);
1163 if (p->value == NULL)
1165 _asn1_error_description_value_not_found (p, ErrorDescription);
1166 err = ASN1_VALUE_NOT_FOUND;
1169 len2 = asn1_get_length_der (p->value, p->value_len, &len3);
1172 err = ASN1_DER_ERROR;
1177 memcpy (der + counter, p->value + len3, len2);
1182 move = (move == UP) ? RIGHT : DOWN;
1186 if ((move != DOWN) && (counter != counter_old))
1188 err = _asn1_complete_explicit_tag (p, der, &counter, &max_len);
1189 if (err != ASN1_SUCCESS && err != ASN1_MEM_ERROR)
1193 if (p == node && move != DOWN)
1211 p = _asn1_find_up (p);
1218 err = ASN1_MEM_ERROR;
1225 asn1_delete_structure (&node);