1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 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.
22 int ber_octetstring(ODR o, Odr_oct *p, int cons)
33 if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
35 odr_seterror(o, OPROTO, 14);
39 if (cons) /* fetch component strings */
42 while (odp_more_chunks(o, base, len))
43 if (!odr_octetstring(o, &p, 0, 0))
47 /* primitive octetstring */
50 odr_seterror(o, OOTHER, 15);
55 odr_seterror(o, OOTHER, 16);
61 if (len + 1 > p->size - p->len)
63 c = (unsigned char *)odr_malloc(o, p->size += len + 1);
65 memcpy(c, p->buf, p->len);
69 memcpy(p->buf + p->len, o->bp, len);
72 /* the final null is really not part of the buffer, but */
73 /* it helps somes applications that assumes C strings */
75 p->buf[p->len] = '\0';
78 p->buf = odr_malloc(o, len + 1);
79 memcpy(p->buf, o->bp, len);
85 if ((res = ber_enclen(o, p->len, 5, 0)) < 0)
89 if (odr_write(o, p->buf, p->len) < 0)
95 odr_seterror(o, OOTHER, 17);
102 * c-file-style: "Stroustrup"
103 * indent-tabs-mode: nil
105 * vim: shiftwidth=4 tabstop=8 expandtab