#include "silcasn1.h"
#include "silcber.h"
+#define SILC_ASN1_BUFFER_FREE(b, stack) if (!stack) silc_buffer_purge(b);
+
/************************** ASN.1 Encoder routines **************************/
/* Encode string from UTF-8 string to other string encodings. Encodes
ret = silc_asn1_encoder(asn1, stack2, stack1, type, type,
SILC_BER_CLASS_UNIVERSAL, opts,
&buf, depth + 1, primitive);
- silc_stack_pop(stack2);
if (!ret) {
SILC_LOG_DEBUG(("Error encoding explicit tag"));
+ silc_stack_pop(stack2);
goto fail;
}
silc_buffer_truelen(dest) + len);
ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_CONSTRUCTED,
tag, buf.data, silc_buffer_len(&buf), FALSE);
+ SILC_ASN1_BUFFER_FREE(&buf, stack2);
+ silc_stack_pop(stack2);
if (!ret)
goto fail;
if (primitive) {
silc_stack_push(stack2, &frame);
ret = silc_asn1_encoder(asn1, stack2, stack1, rtype, rtag, rclass,
ropts, &buf, depth + 1, FALSE);
- silc_stack_pop(stack2);
if (!ret) {
SILC_LOG_DEBUG(("Error traversing a SEQUENCE/SET"));
+ silc_stack_pop(stack2);
goto fail;
}
silc_buffer_truelen(dest) + len);
ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_CONSTRUCTED,
tag, buf.data, silc_buffer_len(&buf), indef);
+ SILC_ASN1_BUFFER_FREE(&buf, stack2);
+ silc_stack_pop(stack2);
if (!ret)
goto fail;
break;
silc_buffer_truelen(dest) + len);
ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_PRIMITIVE,
tag, buf.data, silc_buffer_len(&buf), FALSE);
+ SILC_ASN1_BUFFER_FREE(&buf, stack2);
silc_stack_pop(stack2);
if (!ret)
goto fail;
silc_buffer_truelen(dest) + len);
ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_PRIMITIVE,
tag, buf.data, silc_buffer_len(&buf), FALSE);
+ SILC_ASN1_BUFFER_FREE(&buf, stack2);
silc_stack_pop(stack2);
if (!ret)
goto fail;
silc_buffer_truelen(dest) + len);
ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_PRIMITIVE,
tag, buf.data, silc_buffer_len(&buf), FALSE);
+ SILC_ASN1_BUFFER_FREE(&buf, stack2);
silc_stack_pop(stack2);
if (!ret)
goto fail;
silc_buffer_truelen(dest) + len);
ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_PRIMITIVE,
tag, buf.data, silc_buffer_len(&buf), indef);
+ SILC_ASN1_BUFFER_FREE(&buf, stack2);
silc_stack_pop(stack2);
if (!ret)
goto fail;