Lines Matching +full:0 +full:- +full:n

2  * Copyright (c) 1997 - 2006 Kungliga Tekniska Högskolan
42 "e = der_put_%s(p, len, %s, &l);\n"
43 "if (e) return e;\np -= l; len -= l; ret += l;\n\n",
96 { -1, NULL }
99 for(p = values; p->value != -1; p++)
100 if(p->value == value)
101 return p->s;
112 switch (t->type) {
114 #if 0
115 encode_type (name, t->symbol->type);
118 "e = encode_%s(p, len, %s, &l);\n"
119 "if (e) return e;\np -= l; len -= l; ret += l;\n\n",
120 t->symbol->gen_name, name);
123 if(t->members) {
125 "{\n"
126 "int enumint = (int)*%s;\n",
129 fprintf(codefile, "}\n;");
130 } else if (t->range == NULL) {
132 } else if (t->range->min < INT_MIN && t->range->max <= INT64_MAX) {
134 } else if (t->range->min >= 0 && t->range->max > UINT_MAX) {
136 } else if (t->range->min >= INT_MIN && t->range->max <= INT_MAX) {
138 } else if (t->range->min >= 0 && t->range->max <= UINT_MAX) {
141 errx(1, "%s: unsupported range %" PRId64 " -> %" PRId64,
142 name, t->range->min, t->range->max);
143 constructed = 0;
147 constructed = 0;
151 constructed = 0;
157 if (ASN1_TAILQ_EMPTY(t->members)) {
159 constructed = 0;
163 fprintf (codefile, "{\n"
164 "unsigned char c = 0;\n");
167 "int rest = 0;\n"
168 "int bit_set = 0;\n");
169 #if 0
170 pos = t->members->prev->val;
182 pos = ASN1_TAILQ_LAST(t->members, memhead)->val;
188 ASN1_TAILQ_FOREACH_REVERSE(m, t->members, memhead, members) {
189 while (m->val / 8 < pos / 8) {
192 "if (c != 0 || bit_set) {\n");
194 "if (len < 1) return ASN1_OVERFLOW;\n"
195 "*p-- = c; len--; ret++;\n");
198 "if (!bit_set) {\n"
199 "rest = 0;\n"
200 "while(c) { \n"
201 "if (c & 1) break;\n"
202 "c = c >> 1;\n"
203 "rest++;\n"
204 "}\n"
205 "bit_set = 1;\n"
206 "}\n"
207 "}\n");
209 "c = 0;\n");
210 pos -= 8;
213 "if((%s)->%s) {\n"
214 "c |= 1<<%d;\n",
215 name, m->gen_name, 7 - m->val % 8);
217 "}\n");
222 "if (c != 0 || bit_set) {\n");
224 "if (len < 1) return ASN1_OVERFLOW;\n"
225 "*p-- = c; len--; ret++;\n");
228 "if (!bit_set) {\n"
229 "rest = 0;\n"
230 "if(c) { \n"
231 "while(c) { \n"
232 "if (c & 1) break;\n"
233 "c = c >> 1;\n"
234 "rest++;\n"
235 "}\n"
236 "}\n"
237 "}\n"
238 "}\n");
241 "if (len < 1) return ASN1_OVERFLOW;\n"
242 "*p-- = %s;\n"
243 "len -= 1;\n"
244 "ret += 1;\n"
245 "}\n\n",
246 rfc1510_bitstring ? "0" : "rest");
247 constructed = 0;
252 constructed = 0;
260 if (t->members == NULL)
263 ASN1_TAILQ_FOREACH_REVERSE(m, t->members, memhead, members) {
266 if (m->ellipsis)
269 if (asprintf (&s, "%s(%s)->%s", m->optional ? "" : "&", name, m->gen_name) < 0 || s == NULL)
271 fprintf(codefile, "/* %s */\n", m->name);
272 if (m->optional)
276 else if(m->defval)
277 gen_compare_defval(s + 1, m->defval);
278 fprintf (codefile, "{\n");
279 fprintf (codefile, "size_t %s_oldret HEIMDAL_UNUSED_ATTRIBUTE = ret;\n", tmpstr);
280 fprintf (codefile, "ret = 0;\n");
281 encode_type (s, m->type, m->gen_name);
282 fprintf (codefile, "ret += %s_oldret;\n", tmpstr);
283 fprintf (codefile, "}\n");
291 "{\n"
292 "struct heim_octet_string *val;\n"
293 "size_t elen = 0, totallen = 0;\n"
294 "int eret = 0;\n");
297 "if ((%s)->len > UINT_MAX/sizeof(val[0]))\n"
298 "return ERANGE;\n",
302 "val = malloc(sizeof(val[0]) * (%s)->len);\n"
303 "if (val == NULL && (%s)->len != 0) return ENOMEM;\n",
307 "for(i = 0; i < (int)(%s)->len; i++) {\n",
312 "val[i].length, &(%s)->val[i], &elen, eret);\n",
313 t->subtype->symbol->gen_name,
317 "if(eret) {\n"
318 "i--;\n"
319 "while (i >= 0) {\n"
320 "free(val[i].data);\n"
321 "i--;\n"
322 "}\n"
323 "free(val);\n"
324 "return eret;\n"
325 "}\n"
326 "totallen += elen;\n"
327 "}\n");
330 "if (totallen > len) {\n"
331 "for (i = 0; i < (int)(%s)->len; i++) {\n"
332 "free(val[i].data);\n"
333 "}\n"
334 "free(val);\n"
335 "return ASN1_OVERFLOW;\n"
336 "}\n",
340 "qsort(val, (%s)->len, sizeof(val[0]), _heim_der_set_sort);\n",
344 "for(i = (int)(%s)->len - 1; i >= 0; --i) {\n"
345 "p -= val[i].length;\n"
346 "ret += val[i].length;\n"
347 "memcpy(p + 1, val[i].data, val[i].length);\n"
348 "free(val[i].data);\n"
349 "}\n"
350 "free(val);\n"
351 "}\n",
357 char *n = NULL;
360 "for(i = (int)(%s)->len - 1; i >= 0; --i) {\n"
361 "size_t %s_for_oldret = ret;\n"
362 "ret = 0;\n",
364 if (asprintf (&n, "&(%s)->val[i]", name) < 0 || n == NULL)
366 if (asprintf (&sname, "%s_S_Of", tmpstr) < 0 || sname == NULL)
368 encode_type (n, t->subtype, sname);
370 "ret += %s_for_oldret;\n"
371 "}\n",
373 free (n);
379 constructed = 0;
383 constructed = 0;
387 constructed = 0;
392 if (asprintf (&tname, "%s_tag", tmpstr) < 0 || tname == NULL)
394 c = encode_type (name, t->subtype, tname);
396 "e = der_put_length_and_tag (p, len, ret, %s, %s, %s, &l);\n"
397 "if (e) return e;\np -= l; len -= l; ret += l;\n\n",
398 classname(t->tag.tagclass),
400 valuename(t->tag.tagclass, t->tag.tagvalue));
408 if (t->members == NULL)
411 fprintf(codefile, "\n");
413 if (asprintf (&s, "(%s)", name) < 0 || s == NULL)
415 fprintf(codefile, "switch(%s->element) {\n", s);
417 ASN1_TAILQ_FOREACH_REVERSE(m, t->members, memhead, members) {
420 if (m->ellipsis) {
425 fprintf (codefile, "case %s: {", m->label);
426 if (asprintf(&s2, "%s(%s)->u.%s", m->optional ? "" : "&",
427 s, m->gen_name) < 0 || s2 == NULL)
429 if (m->optional)
430 fprintf (codefile, "if(%s) {\n", s2);
431 fprintf (codefile, "size_t %s_oldret = ret;\n", tmpstr);
432 fprintf (codefile, "ret = 0;\n");
433 constructed = encode_type (s2, m->type, m->gen_name);
434 fprintf (codefile, "ret += %s_oldret;\n", tmpstr);
435 if(m->optional)
436 fprintf (codefile, "}\n");
437 fprintf(codefile, "break;\n");
438 fprintf(codefile, "}\n");
444 "case %s: {\n"
445 "if (len < (%s)->u.%s.length)\n"
446 "return ASN1_OVERFLOW;\n"
447 "p -= (%s)->u.%s.length;\n"
448 "ret += (%s)->u.%s.length;\n"
449 "memcpy(p + 1, (%s)->u.%s.data, (%s)->u.%s.length);\n"
450 "break;\n"
451 "}\n",
452 have_ellipsis->label,
453 name, have_ellipsis->gen_name,
454 name, have_ellipsis->gen_name,
455 name, have_ellipsis->gen_name,
456 name, have_ellipsis->gen_name,
457 name, have_ellipsis->gen_name);
459 fprintf(codefile, "};\n");
464 constructed = 0;
468 constructed = 0;
472 constructed = 0;
476 constructed = 0;
480 constructed = 0;
484 constructed = 0;
488 constructed = 0;
492 constructed = 0;
495 fprintf (codefile, "/* NULL */\n");
496 constructed = 0;
507 fprintf (codefile, "int ASN1CALL\n"
509 " const %s *data, size_t *size)\n"
510 "{\n",
511 s->gen_name, s->gen_name);
513 switch (s->type->type) {
539 "size_t ret HEIMDAL_UNUSED_ATTRIBUTE = 0;\n"
540 "size_t l HEIMDAL_UNUSED_ATTRIBUTE;\n"
541 "int i HEIMDAL_UNUSED_ATTRIBUTE, e HEIMDAL_UNUSED_ATTRIBUTE;\n\n");
543 encode_type("data", s->type, "Top");
545 fprintf (codefile, "*size = ret;\n"
546 "return 0;\n");
551 fprintf (codefile, "}\n\n");