1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements ber_octetstring
10 * This source file implements BER encoding and decoding of
11 * the OCTETSTRING type.
20 int ber_octetstring(ODR o, Odr_oct *p, int cons)
23 const unsigned char *base;
29 if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
31 odr_seterror(o, OPROTO, 14);
35 if (cons) /* fetch component strings */
38 while (odp_more_chunks(o, base, len))
39 if (!odr_octetstring(o, &p, 0, 0))
43 /* primitive octetstring */
46 odr_seterror(o, OOTHER, 15);
51 odr_seterror(o, OOTHER, 16);
54 if (len + 1 > p->size - p->len)
56 c = (unsigned char *)odr_malloc(o, p->size += len + 1);
58 memcpy(c, p->buf, p->len);
62 memcpy(p->buf + p->len, o->bp, len);
65 /* the final null is really not part of the buffer, but */
66 /* it helps somes applications that assumes C strings */
68 p->buf[p->len] = '\0';
71 if ((res = ber_enclen(o, p->len, 5, 0)) < 0)
75 if (odr_write(o, p->buf, p->len) < 0)
81 odr_seterror(o, OOTHER, 17);
88 * c-file-style: "Stroustrup"
89 * indent-tabs-mode: nil
91 * vim: shiftwidth=4 tabstop=8 expandtab