2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: ber_oct.c,v 1.5 2007-01-03 08:42:15 adam Exp $
10 * \brief Implements ber_octetstring
12 * This source file implements BER encoding and decoding of
13 * the OCTETSTRING type.
22 int ber_octetstring(ODR o, Odr_oct *p, int cons)
25 const unsigned char *base;
31 if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
33 odr_seterror(o, OPROTO, 14);
37 if (cons) /* fetch component strings */
40 while (odp_more_chunks(o, base, len))
41 if (!odr_octetstring(o, &p, 0, 0))
45 /* primitive octetstring */
48 odr_seterror(o, OOTHER, 15);
53 odr_seterror(o, OOTHER, 16);
56 if (len + 1 > p->size - p->len)
58 c = (unsigned char *)odr_malloc(o, p->size += len + 1);
60 memcpy(c, p->buf, p->len);
64 memcpy(p->buf + p->len, o->bp, len);
67 /* the final null is really not part of the buffer, but */
68 /* it helps somes applications that assumes C strings */
70 p->buf[p->len] = '\0';
73 if ((res = ber_enclen(o, p->len, 5, 0)) < 0)
77 if (odr_write(o, p->buf, p->len) < 0)
83 odr_seterror(o, OOTHER, 17);
90 * indent-tabs-mode: nil
92 * vim: shiftwidth=4 tabstop=8 expandtab