2 * Copyright (c) 1995-2003, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Id: ber_oct.c,v 1.1 2003-10-27 12:21:30 adam Exp $
14 int ber_octetstring(ODR o, Odr_oct *p, int cons)
17 const unsigned char *base;
23 if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
25 odr_seterror(o, OPROTO, 14);
29 if (cons) /* fetch component strings */
32 while (odp_more_chunks(o, base, len))
33 if (!odr_octetstring(o, &p, 0, 0))
37 /* primitive octetstring */
40 odr_seterror(o, OOTHER, 15);
45 odr_seterror(o, OOTHER, 16);
48 if (len + 1 > p->size - p->len)
50 c = (unsigned char *)odr_malloc(o, p->size += len + 1);
52 memcpy(c, p->buf, p->len);
56 memcpy(p->buf + p->len, o->bp, len);
59 /* the final null is really not part of the buffer, but */
60 /* it helps somes applications that assumes C strings */
62 p->buf[p->len] = '\0';
65 if ((res = ber_enclen(o, p->len, 5, 0)) < 0)
69 if (odr_write(o, p->buf, p->len) < 0)
72 case ODR_PRINT: return 1;
73 default: odr_seterror(o, OOTHER, 17); return 0;