]> pd.if.org Git - zpackage/blob - libtomcrypt/src/pk/asn1/der/sequence/der_sequence_free.c
commit files needed for zpm-fetchurl
[zpackage] / libtomcrypt / src / 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 #include "tomcrypt.h"
10
11 /**
12   @file der_sequence_free.c
13   ASN.1 DER, free's a structure allocated by der_decode_sequence_flexi(), Tom St Denis
14 */
15
16 #ifdef LTC_DER
17
18 /**
19   Free memory allocated by der_decode_sequence_flexi()
20   @param in     The list to free
21 */
22 void der_sequence_free(ltc_asn1_list *in)
23 {
24    ltc_asn1_list *l;
25
26    if (!in) return;
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_SETOF: break;
48          case LTC_ASN1_INTEGER : if (in->data != NULL) { mp_clear(in->data); } break;
49          default               : if (in->data != NULL) { XFREE(in->data);    }
50       }
51
52       /* move to next and free current */
53       l = in->next;
54       XFREE(in);
55       in = l;
56    }
57 }
58
59 #endif
60
61 /* ref:         $Format:%D$ */
62 /* git commit:  $Format:%H$ */
63 /* commit time: $Format:%ai$ */