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.20 2003-01-06 08:20:27 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)) < 0)
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 */
43 if (len + 1 > p->size - p->len)
45 c = (unsigned char *)odr_malloc(o, p->size += len + 1);
47 memcpy(c, p->buf, p->len);
51 memcpy(p->buf + p->len, o->bp, len);
54 /* the final null is really not part of the buffer, but */
55 /* it helps somes applications that assumes C strings */
57 p->buf[p->len] = '\0';
60 if ((res = ber_enclen(o, p->len, 5, 0)) < 0)
64 if (odr_write(o, p->buf, p->len) < 0)
67 case ODR_PRINT: return 1;
68 default: o->error = OOTHER; return 0;