Updated to minitasn1 3.0
[gnutls.git] / lib / minitasn1 / parser_aux.c
blobff701bc32fc5ab9ace20d63cb8ef2e1b37d7f363
1 /*
2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
4 * This file is part of LIBTASN1.
6 * The LIBTASN1 library is free software; you can redistribute it
7 * and/or modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301, USA
22 #include <int.h>
23 #include "parser_aux.h"
24 #include "gstr.h"
25 #include "structure.h"
26 #include "element.h"
28 char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not found */
30 /***********************************************/
31 /* Type: list_type */
32 /* Description: type used in the list during */
33 /* the structure creation. */
34 /***********************************************/
35 typedef struct list_struct
37 ASN1_TYPE node;
38 struct list_struct *next;
39 } list_type;
42 /* Pointer to the first element of the list */
43 list_type *firstElement = NULL;
45 /******************************************************/
46 /* Function : _asn1_add_static_node */
47 /* Description: creates a new NODE_ASN element and */
48 /* puts it in the list pointed by firstElement. */
49 /* Parameters: */
50 /* type: type of the new element (see TYPE_ */
51 /* and CONST_ constants). */
52 /* Return: pointer to the new element. */
53 /******************************************************/
54 ASN1_TYPE
55 _asn1_add_static_node (unsigned int type)
57 list_type *listElement;
58 ASN1_TYPE punt;
60 punt = calloc (1, sizeof (struct node_asn_struct));
61 if (punt == NULL)
62 return NULL;
64 listElement = malloc (sizeof (list_type));
65 if (listElement == NULL)
67 free (punt);
68 return NULL;
71 listElement->node = punt;
72 listElement->next = firstElement;
73 firstElement = listElement;
75 punt->type = type;
77 return punt;
80 /**
81 * asn1_find_node:
82 * @pointer: NODE_ASN element pointer.
83 * @name: null terminated string with the element's name to find.
85 * Searches for an element called @name starting from @pointer. The
86 * name is composed by differents identifiers separated by dots. When
87 * *@pointer has a name, the first identifier must be the name of
88 * *@pointer, otherwise it must be the name of one child of *@pointer.
90 * Returns: the search result, or %NULL if not found.
91 **/
92 ASN1_TYPE
93 asn1_find_node (ASN1_TYPE pointer, const char *name)
95 ASN1_TYPE p;
96 char *n_end, n[ASN1_MAX_NAME_SIZE + 1];
97 const char *n_start;
98 unsigned int nsize;
99 unsigned int nhash;
101 if (pointer == NULL)
102 return NULL;
104 if (name == NULL)
105 return NULL;
107 p = pointer;
108 n_start = name;
110 if (p->name[0] != 0)
111 { /* has *pointer got a name ? */
112 n_end = strchr (n_start, '.'); /* search the first dot */
113 if (n_end)
115 nsize = n_end - n_start;
116 memcpy (n, n_start, nsize);
117 n[nsize] = 0;
118 n_start = n_end;
119 n_start++;
121 nhash = _asn1_bhash(n, nsize);
123 else
125 nsize = _asn1_str_cpy (n, sizeof (n), n_start);
126 nhash = _asn1_bhash(n, nsize);
128 n_start = NULL;
131 while (p)
133 if ((p->name) && nhash == p->name_hash && (!strcmp (p->name, n)))
134 break;
135 else
136 p = p->right;
137 } /* while */
139 if (p == NULL)
140 return NULL;
142 else
143 { /* *pointer doesn't have a name */
144 if (n_start[0] == 0)
145 return p;
148 while (n_start)
149 { /* Has the end of NAME been reached? */
150 n_end = strchr (n_start, '.'); /* search the next dot */
151 if (n_end)
153 nsize = n_end - n_start;
154 memcpy (n, n_start, nsize);
155 n[nsize] = 0;
156 n_start = n_end;
157 n_start++;
159 nhash = _asn1_bhash(n, nsize);
161 else
163 nsize = _asn1_str_cpy (n, sizeof (n), n_start);
164 nhash = _asn1_bhash(n, nsize);
165 n_start = NULL;
168 if (p->down == NULL)
169 return NULL;
171 p = p->down;
173 /* The identifier "?LAST" indicates the last element
174 in the right chain. */
175 if (!strcmp (n, "?LAST"))
177 if (p == NULL)
178 return NULL;
179 while (p->right)
180 p = p->right;
182 else
183 { /* no "?LAST" */
184 while (p)
186 if (p->name_hash == nhash && !strcmp (p->name, n))
187 break;
188 else
189 p = p->right;
191 if (p == NULL)
192 return NULL;
194 } /* while */
196 return p;
200 /******************************************************************/
201 /* Function : _asn1_set_value */
202 /* Description: sets the field VALUE in a NODE_ASN element. The */
203 /* previous value (if exist) will be lost */
204 /* Parameters: */
205 /* node: element pointer. */
206 /* value: pointer to the value that you want to set. */
207 /* len: character number of value. */
208 /* Return: pointer to the NODE_ASN element. */
209 /******************************************************************/
210 ASN1_TYPE
211 _asn1_set_value (ASN1_TYPE node, const void *value, unsigned int len)
213 if (node == NULL)
214 return node;
215 if (node->value)
217 if (node->value != node->small_value)
218 free (node->value);
219 node->value = NULL;
220 node->value_len = 0;
223 if (!len)
224 return node;
226 if (len < sizeof (node->small_value))
228 node->value = node->small_value;
230 else
232 node->value = malloc (len);
233 if (node->value == NULL)
234 return NULL;
236 node->value_len = len;
238 memcpy (node->value, value, len);
239 return node;
242 /******************************************************************/
243 /* Function : _asn1_set_value_octet */
244 /* Description: sets the field VALUE in a NODE_ASN element. The */
245 /* previous value (if exist) will be lost. The value */
246 /* given is stored as an octet string. */
247 /* Parameters: */
248 /* node: element pointer. */
249 /* value: pointer to the value that you want to set. */
250 /* len: character number of value. */
251 /* Return: pointer to the NODE_ASN element. */
252 /******************************************************************/
253 ASN1_TYPE
254 _asn1_set_value_octet (ASN1_TYPE node, const void *value, unsigned int len)
256 int len2;
257 void *temp;
259 if (node == NULL)
260 return node;
262 asn1_length_der (len, NULL, &len2);
263 temp = malloc (len + len2);
264 if (temp == NULL)
265 return NULL;
267 asn1_octet_der (value, len, temp, &len2);
268 return _asn1_set_value_m (node, temp, len2);
271 /* the same as _asn1_set_value except that it sets an already malloc'ed
272 * value.
274 ASN1_TYPE
275 _asn1_set_value_m (ASN1_TYPE node, void *value, unsigned int len)
277 if (node == NULL)
278 return node;
280 if (node->value)
282 if (node->value != node->small_value)
283 free (node->value);
284 node->value = NULL;
285 node->value_len = 0;
288 if (!len)
289 return node;
291 node->value = value;
292 node->value_len = len;
294 return node;
297 /******************************************************************/
298 /* Function : _asn1_append_value */
299 /* Description: appends to the field VALUE in a NODE_ASN element. */
300 /* */
301 /* Parameters: */
302 /* node: element pointer. */
303 /* value: pointer to the value that you want to be appended. */
304 /* len: character number of value. */
305 /* Return: pointer to the NODE_ASN element. */
306 /******************************************************************/
307 ASN1_TYPE
308 _asn1_append_value (ASN1_TYPE node, const void *value, unsigned int len)
310 if (node == NULL)
311 return node;
312 if (node->value != NULL && node->value != node->small_value)
314 /* value is allocated */
315 int prev_len = node->value_len;
316 node->value_len += len;
317 node->value = realloc (node->value, node->value_len);
318 if (node->value == NULL)
320 node->value_len = 0;
321 return NULL;
323 memcpy (&node->value[prev_len], value, len);
325 return node;
327 else if (node->value == node->small_value)
329 /* value is in node */
330 int prev_len = node->value_len;
331 node->value_len += len;
332 node->value = malloc (node->value_len);
333 if (node->value == NULL)
335 node->value_len = 0;
336 return NULL;
338 memcpy (node->value, node->small_value, prev_len);
339 memcpy (&node->value[prev_len], value, len);
341 return node;
343 else /* node->value == NULL */
344 return _asn1_set_value (node, value, len);
347 /******************************************************************/
348 /* Function : _asn1_set_name */
349 /* Description: sets the field NAME in a NODE_ASN element. The */
350 /* previous value (if exist) will be lost */
351 /* Parameters: */
352 /* node: element pointer. */
353 /* name: a null terminated string with the name that you want */
354 /* to set. */
355 /* Return: pointer to the NODE_ASN element. */
356 /******************************************************************/
357 ASN1_TYPE
358 _asn1_set_name (ASN1_TYPE node, const char *name)
360 unsigned int nsize;
362 if (node == NULL)
363 return node;
365 if (name == NULL)
367 node->name[0] = 0;
368 node->name_hash = _asn1_bhash(node->name, 0);
369 return node;
372 nsize = _asn1_str_cpy (node->name, sizeof (node->name), name);
373 node->name_hash = _asn1_bhash(node->name, nsize);
375 return node;
378 /******************************************************************/
379 /* Function : _asn1_cpy_name */
380 /* Description: copies the field NAME in a NODE_ASN element. */
381 /* Parameters: */
382 /* dst: a dest element pointer. */
383 /* src: a source element pointer. */
384 /* Return: pointer to the NODE_ASN element. */
385 /******************************************************************/
386 ASN1_TYPE
387 _asn1_cpy_name (ASN1_TYPE dst, ASN1_TYPE src)
389 unsigned int nsize;
391 if (dst == NULL)
392 return dst;
394 if (src == NULL)
396 dst->name[0] = 0;
397 dst->name_hash = _asn1_bhash(dst->name, 0);
398 return dst;
401 nsize = _asn1_str_cpy (dst->name, sizeof (dst->name), src->name);
402 dst->name_hash = src->name_hash;
404 return dst;
407 /******************************************************************/
408 /* Function : _asn1_set_right */
409 /* Description: sets the field RIGHT in a NODE_ASN element. */
410 /* Parameters: */
411 /* node: element pointer. */
412 /* right: pointer to a NODE_ASN element that you want be pointed*/
413 /* by NODE. */
414 /* Return: pointer to *NODE. */
415 /******************************************************************/
416 ASN1_TYPE
417 _asn1_set_right (ASN1_TYPE node, ASN1_TYPE right)
419 if (node == NULL)
420 return node;
421 node->right = right;
422 if (right)
423 right->left = node;
424 return node;
428 /******************************************************************/
429 /* Function : _asn1_get_last_right */
430 /* Description: return the last element along the right chain. */
431 /* Parameters: */
432 /* node: starting element pointer. */
433 /* Return: pointer to the last element along the right chain. */
434 /******************************************************************/
435 ASN1_TYPE
436 _asn1_get_last_right (ASN1_TYPE node)
438 ASN1_TYPE p;
440 if (node == NULL)
441 return NULL;
442 p = node;
443 while (p->right)
444 p = p->right;
445 return p;
448 /******************************************************************/
449 /* Function : _asn1_remove_node */
450 /* Description: gets free the memory allocated for an NODE_ASN */
451 /* element (not the elements pointed by it). */
452 /* Parameters: */
453 /* node: NODE_ASN element pointer. */
454 /******************************************************************/
455 void
456 _asn1_remove_node (ASN1_TYPE node)
458 if (node == NULL)
459 return;
461 if (node->value != NULL && node->value != node->small_value)
462 free (node->value);
463 free (node);
466 /******************************************************************/
467 /* Function : _asn1_find_up */
468 /* Description: return the father of the NODE_ASN element. */
469 /* Parameters: */
470 /* node: NODE_ASN element pointer. */
471 /* Return: Null if not found. */
472 /******************************************************************/
473 ASN1_TYPE
474 _asn1_find_up (ASN1_TYPE node)
476 ASN1_TYPE p;
478 if (node == NULL)
479 return NULL;
481 p = node;
483 while ((p->left != NULL) && (p->left->right == p))
484 p = p->left;
486 return p->left;
489 /******************************************************************/
490 /* Function : _asn1_delete_list */
491 /* Description: deletes the list elements (not the elements */
492 /* pointed by them). */
493 /******************************************************************/
494 void
495 _asn1_delete_list (void)
497 list_type *listElement;
499 while (firstElement)
501 listElement = firstElement;
502 firstElement = firstElement->next;
503 free (listElement);
507 /******************************************************************/
508 /* Function : _asn1_delete_list_and nodes */
509 /* Description: deletes the list elements and the elements */
510 /* pointed by them. */
511 /******************************************************************/
512 void
513 _asn1_delete_list_and_nodes (void)
515 list_type *listElement;
517 while (firstElement)
519 listElement = firstElement;
520 firstElement = firstElement->next;
521 _asn1_remove_node (listElement->node);
522 free (listElement);
527 char *
528 _asn1_ltostr (long v, char *str)
530 long d, r;
531 char temp[20];
532 int count, k, start;
534 if (v < 0)
536 str[0] = '-';
537 start = 1;
538 v = -v;
540 else
541 start = 0;
543 count = 0;
546 d = v / 10;
547 r = v - d * 10;
548 temp[start + count] = '0' + (char) r;
549 count++;
550 v = d;
552 while (v);
554 for (k = 0; k < count; k++)
555 str[k + start] = temp[start + count - k - 1];
556 str[count + start] = 0;
557 return str;
561 /******************************************************************/
562 /* Function : _asn1_change_integer_value */
563 /* Description: converts into DER coding the value assign to an */
564 /* INTEGER constant. */
565 /* Parameters: */
566 /* node: root of an ASN1element. */
567 /* Return: */
568 /* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */
569 /* otherwise ASN1_SUCCESS */
570 /******************************************************************/
571 asn1_retCode
572 _asn1_change_integer_value (ASN1_TYPE node)
574 ASN1_TYPE p;
575 unsigned char val[SIZEOF_UNSIGNED_LONG_INT];
576 unsigned char val2[SIZEOF_UNSIGNED_LONG_INT + 1];
577 int len;
579 if (node == NULL)
580 return ASN1_ELEMENT_NOT_FOUND;
582 p = node;
583 while (p)
585 if ((type_field (p->type) == TYPE_INTEGER) && (p->type & CONST_ASSIGN))
587 if (p->value)
589 _asn1_convert_integer (p->value, val, sizeof (val), &len);
590 asn1_octet_der (val, len, val2, &len);
591 _asn1_set_value (p, val2, len);
595 if (p->down)
597 p = p->down;
599 else
601 if (p == node)
602 p = NULL;
603 else if (p->right)
604 p = p->right;
605 else
607 while (1)
609 p = _asn1_find_up (p);
610 if (p == node)
612 p = NULL;
613 break;
615 if (p->right)
617 p = p->right;
618 break;
625 return ASN1_SUCCESS;
629 /******************************************************************/
630 /* Function : _asn1_expand_object_id */
631 /* Description: expand the IDs of an OBJECT IDENTIFIER constant. */
632 /* Parameters: */
633 /* node: root of an ASN1 element. */
634 /* Return: */
635 /* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */
636 /* otherwise ASN1_SUCCESS */
637 /******************************************************************/
638 asn1_retCode
639 _asn1_expand_object_id (ASN1_TYPE node)
641 ASN1_TYPE p, p2, p3, p4, p5;
642 char name_root[ASN1_MAX_NAME_SIZE], name2[2 * ASN1_MAX_NAME_SIZE + 1];
643 int move, tlen;
645 if (node == NULL)
646 return ASN1_ELEMENT_NOT_FOUND;
648 _asn1_str_cpy (name_root, sizeof (name_root), node->name);
650 p = node;
651 move = DOWN;
653 while (!((p == node) && (move == UP)))
655 if (move != UP)
657 if ((type_field (p->type) == TYPE_OBJECT_ID)
658 && (p->type & CONST_ASSIGN))
660 p2 = p->down;
661 if (p2 && (type_field (p2->type) == TYPE_CONSTANT))
663 if (p2->value && !isdigit (p2->value[0]))
665 _asn1_str_cpy (name2, sizeof (name2), name_root);
666 _asn1_str_cat (name2, sizeof (name2), ".");
667 _asn1_str_cat (name2, sizeof (name2),
668 (char *) p2->value);
669 p3 = asn1_find_node (node, name2);
670 if (!p3 || (type_field (p3->type) != TYPE_OBJECT_ID) ||
671 !(p3->type & CONST_ASSIGN))
672 return ASN1_ELEMENT_NOT_FOUND;
673 _asn1_set_down (p, p2->right);
674 _asn1_remove_node (p2);
675 p2 = p;
676 p4 = p3->down;
677 while (p4)
679 if (type_field (p4->type) == TYPE_CONSTANT)
681 p5 = _asn1_add_single_node (TYPE_CONSTANT);
682 _asn1_set_name (p5, p4->name);
683 tlen = _asn1_strlen (p4->value);
684 if (tlen > 0)
685 _asn1_set_value (p5, p4->value, tlen + 1);
686 if (p2 == p)
688 _asn1_set_right (p5, p->down);
689 _asn1_set_down (p, p5);
691 else
693 _asn1_set_right (p5, p2->right);
694 _asn1_set_right (p2, p5);
696 p2 = p5;
698 p4 = p4->right;
700 move = DOWN;
701 continue;
705 move = DOWN;
707 else
708 move = RIGHT;
710 if (move == DOWN)
712 if (p->down)
713 p = p->down;
714 else
715 move = RIGHT;
718 if (p == node)
720 move = UP;
721 continue;
724 if (move == RIGHT)
726 if (p->right)
727 p = p->right;
728 else
729 move = UP;
731 if (move == UP)
732 p = _asn1_find_up (p);
736 /*******************************/
737 /* expand DEFAULT */
738 /*******************************/
739 p = node;
740 move = DOWN;
742 while (!((p == node) && (move == UP)))
744 if (move != UP)
746 if ((type_field (p->type) == TYPE_OBJECT_ID) &&
747 (p->type & CONST_DEFAULT))
749 p2 = p->down;
750 if (p2 && (type_field (p2->type) == TYPE_DEFAULT))
752 _asn1_str_cpy (name2, sizeof (name2), name_root);
753 _asn1_str_cat (name2, sizeof (name2), ".");
754 _asn1_str_cat (name2, sizeof (name2), (char *) p2->value);
755 p3 = asn1_find_node (node, name2);
756 if (!p3 || (type_field (p3->type) != TYPE_OBJECT_ID) ||
757 !(p3->type & CONST_ASSIGN))
758 return ASN1_ELEMENT_NOT_FOUND;
759 p4 = p3->down;
760 name2[0] = 0;
761 while (p4)
763 if (type_field (p4->type) == TYPE_CONSTANT)
765 if (name2[0])
766 _asn1_str_cat (name2, sizeof (name2), ".");
767 _asn1_str_cat (name2, sizeof (name2),
768 (char *) p4->value);
770 p4 = p4->right;
772 tlen = strlen (name2);
773 if (tlen > 0)
774 _asn1_set_value (p2, name2, tlen + 1);
777 move = DOWN;
779 else
780 move = RIGHT;
782 if (move == DOWN)
784 if (p->down)
785 p = p->down;
786 else
787 move = RIGHT;
790 if (p == node)
792 move = UP;
793 continue;
796 if (move == RIGHT)
798 if (p->right)
799 p = p->right;
800 else
801 move = UP;
803 if (move == UP)
804 p = _asn1_find_up (p);
807 return ASN1_SUCCESS;
811 /******************************************************************/
812 /* Function : _asn1_type_set_config */
813 /* Description: sets the CONST_SET and CONST_NOT_USED properties */
814 /* in the fields of the SET elements. */
815 /* Parameters: */
816 /* node: root of an ASN1 element. */
817 /* Return: */
818 /* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */
819 /* otherwise ASN1_SUCCESS */
820 /******************************************************************/
821 asn1_retCode
822 _asn1_type_set_config (ASN1_TYPE node)
824 ASN1_TYPE p, p2;
825 int move;
827 if (node == NULL)
828 return ASN1_ELEMENT_NOT_FOUND;
830 p = node;
831 move = DOWN;
833 while (!((p == node) && (move == UP)))
835 if (move != UP)
837 if (type_field (p->type) == TYPE_SET)
839 p2 = p->down;
840 while (p2)
842 if (type_field (p2->type) != TYPE_TAG)
843 p2->type |= CONST_SET | CONST_NOT_USED;
844 p2 = p2->right;
847 move = DOWN;
849 else
850 move = RIGHT;
852 if (move == DOWN)
854 if (p->down)
855 p = p->down;
856 else
857 move = RIGHT;
860 if (p == node)
862 move = UP;
863 continue;
866 if (move == RIGHT)
868 if (p->right)
869 p = p->right;
870 else
871 move = UP;
873 if (move == UP)
874 p = _asn1_find_up (p);
877 return ASN1_SUCCESS;
881 /******************************************************************/
882 /* Function : _asn1_check_identifier */
883 /* Description: checks the definitions of all the identifiers */
884 /* and the first element of an OBJECT_ID (e.g. {pkix 0 4}). */
885 /* The _asn1_identifierMissing global variable is filled if */
886 /* necessary. */
887 /* Parameters: */
888 /* node: root of an ASN1 element. */
889 /* Return: */
890 /* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */
891 /* ASN1_IDENTIFIER_NOT_FOUND if an identifier is not defined, */
892 /* otherwise ASN1_SUCCESS */
893 /******************************************************************/
894 asn1_retCode
895 _asn1_check_identifier (ASN1_TYPE node)
897 ASN1_TYPE p, p2;
898 char name2[ASN1_MAX_NAME_SIZE * 2 + 2];
900 if (node == NULL)
901 return ASN1_ELEMENT_NOT_FOUND;
903 p = node;
904 while (p)
906 if (type_field (p->type) == TYPE_IDENTIFIER)
908 _asn1_str_cpy (name2, sizeof (name2), node->name);
909 _asn1_str_cat (name2, sizeof (name2), ".");
910 _asn1_str_cat (name2, sizeof (name2), (char *) p->value);
911 p2 = asn1_find_node (node, name2);
912 if (p2 == NULL)
914 if (p->value)
915 _asn1_strcpy (_asn1_identifierMissing, p->value);
916 else
917 _asn1_strcpy (_asn1_identifierMissing, "(null)");
918 return ASN1_IDENTIFIER_NOT_FOUND;
921 else if ((type_field (p->type) == TYPE_OBJECT_ID) &&
922 (p->type & CONST_DEFAULT))
924 p2 = p->down;
925 if (p2 && (type_field (p2->type) == TYPE_DEFAULT))
927 _asn1_str_cpy (name2, sizeof (name2), node->name);
928 _asn1_str_cat (name2, sizeof (name2), ".");
929 _asn1_str_cat (name2, sizeof (name2), (char *) p2->value);
930 _asn1_strcpy (_asn1_identifierMissing, p2->value);
931 p2 = asn1_find_node (node, name2);
932 if (!p2 || (type_field (p2->type) != TYPE_OBJECT_ID) ||
933 !(p2->type & CONST_ASSIGN))
934 return ASN1_IDENTIFIER_NOT_FOUND;
935 else
936 _asn1_identifierMissing[0] = 0;
939 else if ((type_field (p->type) == TYPE_OBJECT_ID) &&
940 (p->type & CONST_ASSIGN))
942 p2 = p->down;
943 if (p2 && (type_field (p2->type) == TYPE_CONSTANT))
945 if (p2->value && !isdigit (p2->value[0]))
947 _asn1_str_cpy (name2, sizeof (name2), node->name);
948 _asn1_str_cat (name2, sizeof (name2), ".");
949 _asn1_str_cat (name2, sizeof (name2), (char *) p2->value);
950 _asn1_strcpy (_asn1_identifierMissing, p2->value);
951 p2 = asn1_find_node (node, name2);
952 if (!p2 || (type_field (p2->type) != TYPE_OBJECT_ID) ||
953 !(p2->type & CONST_ASSIGN))
954 return ASN1_IDENTIFIER_NOT_FOUND;
955 else
956 _asn1_identifierMissing[0] = 0;
961 if (p->down)
963 p = p->down;
965 else if (p->right)
966 p = p->right;
967 else
969 while (1)
971 p = _asn1_find_up (p);
972 if (p == node)
974 p = NULL;
975 break;
977 if (p->right)
979 p = p->right;
980 break;
986 return ASN1_SUCCESS;
990 /******************************************************************/
991 /* Function : _asn1_set_default_tag */
992 /* Description: sets the default IMPLICIT or EXPLICIT property in */
993 /* the tagged elements that don't have this declaration. */
994 /* Parameters: */
995 /* node: pointer to a DEFINITIONS element. */
996 /* Return: */
997 /* ASN1_ELEMENT_NOT_FOUND if NODE is NULL or not a pointer to */
998 /* a DEFINITIONS element, */
999 /* otherwise ASN1_SUCCESS */
1000 /******************************************************************/
1001 asn1_retCode
1002 _asn1_set_default_tag (ASN1_TYPE node)
1004 ASN1_TYPE p;
1006 if ((node == NULL) || (type_field (node->type) != TYPE_DEFINITIONS))
1007 return ASN1_ELEMENT_NOT_FOUND;
1009 p = node;
1010 while (p)
1012 if ((type_field (p->type) == TYPE_TAG) &&
1013 !(p->type & CONST_EXPLICIT) && !(p->type & CONST_IMPLICIT))
1015 if (node->type & CONST_EXPLICIT)
1016 p->type |= CONST_EXPLICIT;
1017 else
1018 p->type |= CONST_IMPLICIT;
1021 if (p->down)
1023 p = p->down;
1025 else if (p->right)
1026 p = p->right;
1027 else
1029 while (1)
1031 p = _asn1_find_up (p);
1032 if (p == node)
1034 p = NULL;
1035 break;
1037 if (p->right)
1039 p = p->right;
1040 break;
1046 return ASN1_SUCCESS;