version 0.3.33
[fms.git] / libs / libtomcrypt / pk / asn1 / der / sequence / der_sequence_free.c
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2  *
3  * LibTomCrypt is a library that provides various cryptographic
4  * algorithms in a highly modular and flexible manner.
5  *
6  * The library is free for all purposes without any express
7  * guarantee it works.
8  *
9  * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
10  */
11 #include "tomcrypt.h"
12
13 /**
14   @file der_sequence_free.c
15   ASN.1 DER, free's a structure allocated by der_decode_sequence_flexi(), Tom St Denis
16 */
17
18 #ifdef LTC_DER
19
20 /**
21   Free memory allocated by der_decode_sequence_flexi()
22   @param in     The list to free
23 */  
24 void der_sequence_free(ltc_asn1_list *in)
25 {
26    ltc_asn1_list *l;
27    
28    /* walk to the start of the chain */
29    while (in->prev != NULL || in->parent != NULL) {
30       if (in->parent != NULL) {
31           in = in->parent;
32       } else {
33           in = in->prev;
34       }
35    }
36    
37    /* now walk the list and free stuff */
38    while (in != NULL) {
39       /* is there a child? */
40       if (in->child) {
41          /* disconnect */
42          in->child->parent = NULL;
43          der_sequence_free(in->child);
44       }
45       
46       switch (in->type) { 
47          case LTC_ASN1_SET:
48          case LTC_ASN1_SETOF:
49          case LTC_ASN1_SEQUENCE: break;
50          case LTC_ASN1_INTEGER : if (in->data != NULL) { mp_clear(in->data); } break;
51          default               : if (in->data != NULL) { XFREE(in->data);    }
52       }
53       
54       /* move to next and free current */
55       l = in->next;
56       free(in);
57       in = l;
58    }     
59 }
60
61 #endif
62
63 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_sequence_free.c,v $ */
64 /* $Revision: 1.3 $ */
65 /* $Date: 2006/03/31 14:15:35 $ */