Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2003 - 2005 Pekka Riikonen
+ Copyright (C) 2003 - 2007 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* Allocate ASN.1 context. */
-SilcAsn1 silc_asn1_alloc(void)
+SilcAsn1 silc_asn1_alloc(SilcStack stack)
{
- SilcAsn1 asn1 = silc_calloc(1, sizeof(*asn1));
- if (!asn1)
+ SilcAsn1 asn1;
+ SilcStack stack1;
+
+ stack1 = silc_stack_alloc(0, stack);
+ if (!stack1)
return NULL;
- if (!silc_asn1_init(asn1))
+ /* Allocate itself from the stack */
+ asn1 = silc_scalloc(stack1, 1, sizeof(*asn1));
+ if (!asn1) {
+ silc_stack_free(stack1);
return NULL;
+ }
+
+ asn1->orig_stack = stack;
+ asn1->stack1 = stack1;
+ asn1->stack2 = silc_stack_alloc(0, stack);
+ if (!asn1->stack2) {
+ silc_stack_free(stack1);
+ return NULL;
+ }
+
+ asn1->accumul = 0;
return asn1;
}
void silc_asn1_free(SilcAsn1 asn1)
{
silc_asn1_uninit(asn1);
- silc_free(asn1);
}
/* Init pre-allocated ASN.1 context */
-SilcBool silc_asn1_init(SilcAsn1 asn1)
+SilcBool silc_asn1_init(SilcAsn1 asn1, SilcStack stack)
{
- asn1->stack1 = silc_stack_alloc(768);
+ asn1->orig_stack = stack;
+
+ asn1->stack1 = silc_stack_alloc(0, stack);
if (!asn1->stack1)
return FALSE;
- asn1->stack2 = silc_stack_alloc(768);
+ asn1->stack2 = silc_stack_alloc(0, stack);
if (!asn1->stack2) {
- silc_stack_free(asn1->stack2);
+ silc_stack_free(asn1->stack1);
return FALSE;
}
void silc_asn1_uninit(SilcAsn1 asn1)
{
-#if 1
- silc_stack_stats(asn1->stack1);
- silc_stack_stats(asn1->stack2);
-#endif
- silc_stack_free(asn1->stack1);
+ SilcStack stack1 = asn1->stack1;
+
+ if (asn1->switched) {
+ stack1 = asn1->stack2;
+ asn1->stack2 = asn1->stack1;
+ }
+
silc_stack_free(asn1->stack2);
+ silc_stack_free(stack1);
}
-#ifdef SILC_DIST_INPLACE
+#if defined(SILC_DEBUG)
/* Returns string representation of a tag */
const char *silc_asn1_tag_name(SilcAsn1Tag tag)
return "choice";
case SILC_ASN1_TAG_ANY:
return "any";
+ case SILC_ASN1_TAG_ANY_PRIMITIVE:
+ return "any primitive";
case SILC_ASN1_TAG_SEQUENCE_OF:
return "sequence of";
-
case SILC_ASN1_TAG_SEQUENCE:
return "sequence";
case SILC_ASN1_TAG_SET:
return "set";
case SILC_ASN1_TAG_INTEGER:
return "integer";
+ case SILC_ASN1_TAG_SHORT_INTEGER:
+ return "short integer";
case SILC_ASN1_TAG_OID:
return "oid";
case SILC_ASN1_TAG_BOOLEAN:
}
return "unknown";
}
+#endif /* SILC_DEBUG */
+#ifdef SILC_DIST_TOOLKIT
+#ifdef SILC_DEBUG
/* Dumps the ASN.1 data block into standard output (stdout). */
SilcBool silc_asn1_dump(SilcAsn1 asn1, SilcBuffer src)
{
SilcBool ret = FALSE;
SilcBerEncoding renc;
- SilcAsn1Tag rtag;
+ SilcUInt32 rtag;
const unsigned char *rdata;
SilcUInt32 rdata_len, len = 0;
SilcBool rindef;
while (silc_buffer_len(src)) {
/* Decode the BER block */
- ret = silc_ber_decode(src, NULL, &renc, (SilcUInt32 *)&rtag, &rdata,
+ ret = silc_ber_decode(src, NULL, &renc, &rtag, &rdata,
&rdata_len, &rindef, &len);
if (!ret) {
SILC_LOG_DEBUG(("Error parsing BER block, malformed ASN.1 data"));
}
fprintf(stdout, "Type %s [%d]\n",
- silc_asn1_tag_name(rtag), rtag);
+ silc_asn1_tag_name(rtag), (int)rtag);
if (renc == SILC_BER_ENC_PRIMITIVE)
len = len + rdata_len;
return TRUE;
}
-
-#endif /* SILC_DIST_INPLACE */
+#endif /* SILC_DEBUG */
+#endif /* SILC_DIST_TOOLKIT */