2 * Copyright (c) 1995-2003, Index Data
3 * See the file LICENSE for details.
5 * $Id: ber_any.c,v 1.23 2003-02-21 12:08:58 adam Exp $
13 int ber_any(ODR o, Odr_any **p)
16 int left = o->size - (o->bp - o->buf);
21 if ((res = completeBER(o->bp, left)) <= 0) /* FIX THIS */
26 (*p)->buf = (unsigned char *)odr_malloc(o, res);
27 memcpy((*p)->buf, o->bp, res);
28 (*p)->len = (*p)->size = res;
32 if (odr_write(o, (*p)->buf, (*p)->len) < 0)
35 default: o->error = OOTHER; return 0;
40 * Return length of BER-package or 0.
42 int completeBER(const unsigned char *buf, int len)
44 int res, ll, zclass, tag, cons;
45 const unsigned char *b = buf;
49 if (!buf[0] && !buf[1])
51 if ((res = ber_dectag(b, &zclass, &tag, &cons)) <= 0)
57 if ((res = ber_declen(b, &ll)) <= 0)
64 return (len >= ll ? ll + (b-buf) : 0);
67 /* constructed - cycle through children */
70 if (*b == 0 && *(b + 1) == 0)
72 if (!(res = completeBER(b, len)))