2 * Copyright (c) 1995-2002, Index Data
3 * See the file LICENSE for details.
5 * $Id: ber_any.c,v 1.19 2002-07-25 12:51:08 adam Exp $
12 int ber_any(ODR o, Odr_any **p)
15 int left = o->size - (o->bp - o->buf);
20 if ((res = completeBER(o->bp, left)) <= 0) /* FIX THIS */
25 (*p)->buf = (unsigned char *)odr_malloc(o, res);
26 memcpy((*p)->buf, o->bp, res);
27 (*p)->len = (*p)->size = res;
31 if (odr_write(o, (*p)->buf, (*p)->len) < 0)
34 default: o->error = OOTHER; return 0;
39 * Return length of BER-package or 0.
41 int completeBER(const unsigned char *buf, int len)
43 int res, ll, zclass, tag, cons;
44 const unsigned char *b = buf;
48 if (!buf[0] && !buf[1])
50 if ((res = ber_dectag(b, &zclass, &tag, &cons)) <= 0)
56 if ((res = ber_declen(b, &ll)) <= 0)
63 return (len >= ll ? ll + (b-buf) : 0);
66 /* constructed - cycle through children */
69 if (*b == 0 && *(b + 1) == 0)
71 if (!(res = completeBER(b, len)))