summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/lib/asn1/gen_length.c
diff options
context:
space:
mode:
authorassar <assar@FreeBSD.org>2001-02-13 16:46:19 +0000
committerassar <assar@FreeBSD.org>2001-02-13 16:46:19 +0000
commitebfe6dc471c206300fd82c7c0fd145f683aa52f6 (patch)
treee66aa570ad1d12c43b32a7313b0f8e28971bf8a9 /crypto/heimdal/lib/asn1/gen_length.c
parente5f617598c2db0dd51906a38ecea9208123a8b70 (diff)
downloadFreeBSD-src-ebfe6dc471c206300fd82c7c0fd145f683aa52f6.zip
FreeBSD-src-ebfe6dc471c206300fd82c7c0fd145f683aa52f6.tar.gz
import of heimdal 0.3e
Diffstat (limited to 'crypto/heimdal/lib/asn1/gen_length.c')
-rw-r--r--crypto/heimdal/lib/asn1/gen_length.c170
1 files changed, 91 insertions, 79 deletions
diff --git a/crypto/heimdal/lib/asn1/gen_length.c b/crypto/heimdal/lib/asn1/gen_length.c
index 1c3566d..ca2af6f 100644
--- a/crypto/heimdal/lib/asn1/gen_length.c
+++ b/crypto/heimdal/lib/asn1/gen_length.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997 - 1999 Kungliga Tekniska Högskolan
+ * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -33,7 +33,7 @@
#include "gen_locl.h"
-RCSID("$Id: gen_length.c,v 1.7 1999/12/02 17:05:02 joda Exp $");
+RCSID("$Id: gen_length.c,v 1.10 2000/06/21 22:40:53 assar Exp $");
static void
length_primitive (const char *typename,
@@ -46,91 +46,103 @@ length_primitive (const char *typename,
static void
length_type (const char *name, const Type *t, const char *variable)
{
- switch (t->type) {
- case TType:
+ switch (t->type) {
+ case TType:
#if 0
- length_type (name, t->symbol->type);
+ length_type (name, t->symbol->type);
#endif
- fprintf (codefile, "%s += length_%s(%s);\n",
- variable, t->symbol->gen_name, name);
- break;
- case TInteger:
- length_primitive ("integer", name, variable);
- break;
- case TOctetString:
- length_primitive ("octet_string", name, variable);
- break;
- case TBitString: {
- /*
- * XXX - Hope this is correct
- * look at TBitString case in `encode_type'
- */
- fprintf (codefile, "%s += 7;\n", variable);
- break;
- }
- case TSequence: {
- Member *m;
- int tag = -1;
+ fprintf (codefile, "%s += length_%s(%s);\n",
+ variable, t->symbol->gen_name, name);
+ break;
+ case TInteger:
+ if(t->members == NULL)
+ length_primitive ("integer", name, variable);
+ else {
+ char *s;
+ asprintf(&s, "(const int*)%s", name);
+ if(s == NULL)
+ errx (1, "out of memory");
+ length_primitive ("integer", s, variable);
+ free(s);
+ }
+ break;
+ case TUInteger:
+ length_primitive ("unsigned", name, variable);
+ break;
+ case TOctetString:
+ length_primitive ("octet_string", name, variable);
+ break;
+ case TBitString: {
+ /*
+ * XXX - Hope this is correct
+ * look at TBitString case in `encode_type'
+ */
+ fprintf (codefile, "%s += 7;\n", variable);
+ break;
+ }
+ case TSequence: {
+ Member *m;
+ int tag = -1;
- if (t->members == NULL)
- break;
+ if (t->members == NULL)
+ break;
- for (m = t->members; m && tag != m->val; m = m->next) {
- char *s;
+ for (m = t->members; m && tag != m->val; m = m->next) {
+ char *s;
- asprintf (&s, "%s(%s)->%s",
- m->optional ? "" : "&", name, m->gen_name);
- if (m->optional)
- fprintf (codefile, "if(%s)", s);
- fprintf (codefile, "{\n"
- "int oldret = %s;\n"
- "%s = 0;\n", variable, variable);
- length_type (s, m->type, "ret");
- fprintf (codefile, "%s += 1 + length_len(%s) + oldret;\n",
- variable, variable);
- fprintf (codefile, "}\n");
- if (tag == -1)
- tag = m->val;
- free (s);
- }
- fprintf (codefile,
- "%s += 1 + length_len(%s);\n", variable, variable);
- break;
- }
- case TSequenceOf: {
- char *n;
+ asprintf (&s, "%s(%s)->%s",
+ m->optional ? "" : "&", name, m->gen_name);
+ if (m->optional)
+ fprintf (codefile, "if(%s)", s);
+ fprintf (codefile, "{\n"
+ "int oldret = %s;\n"
+ "%s = 0;\n", variable, variable);
+ length_type (s, m->type, "ret");
+ fprintf (codefile, "%s += 1 + length_len(%s) + oldret;\n",
+ variable, variable);
+ fprintf (codefile, "}\n");
+ if (tag == -1)
+ tag = m->val;
+ free (s);
+ }
+ fprintf (codefile,
+ "%s += 1 + length_len(%s);\n", variable, variable);
+ break;
+ }
+ case TSequenceOf: {
+ char *n;
- fprintf (codefile,
- "{\n"
- "int oldret = %s;\n"
- "int i;\n"
- "%s = 0;\n",
- variable, variable);
+ fprintf (codefile,
+ "{\n"
+ "int oldret = %s;\n"
+ "int i;\n"
+ "%s = 0;\n",
+ variable, variable);
- fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name);
- asprintf (&n, "&(%s)->val[i]", name);
- length_type(n, t->subtype, variable);
- fprintf (codefile, "}\n");
+ fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name);
+ asprintf (&n, "&(%s)->val[i]", name);
+ length_type(n, t->subtype, variable);
+ fprintf (codefile, "}\n");
- fprintf (codefile,
- "%s += 1 + length_len(%s) + oldret;\n"
- "}\n", variable, variable);
- free(n);
- break;
- }
- case TGeneralizedTime:
- length_primitive ("generalized_time", name, variable);
- break;
- case TGeneralString:
- length_primitive ("general_string", name, variable);
- break;
- case TApplication:
- length_type (name, t->subtype, variable);
- fprintf (codefile, "ret += 1 + length_len (ret);\n");
- break;
- default :
- abort ();
- }
+ fprintf (codefile,
+ "%s += 1 + length_len(%s) + oldret;\n"
+ "}\n", variable, variable);
+ free(n);
+ break;
+ }
+ case TGeneralizedTime:
+ length_primitive ("generalized_time", name, variable);
+ break;
+ case TGeneralString:
+ length_primitive ("general_string", name, variable);
+ break;
+ case TApplication:
+ length_type (name, t->subtype, variable);
+ fprintf (codefile, "ret += 1 + length_len (ret);\n");
+ break;
+ default :
+ abort ();
+ }
}
void
OpenPOWER on IntegriCloud