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 BITSTRING encoding and decoding.
10 * This source file implements BER encoding and decoding of
20 int ber_bitstring(ODR o, Odr_bitmask *p, int cons)
23 const unsigned char *base;
28 if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
30 odr_seterror(o, OPROTO, 4);
34 if (cons) /* fetch component strings */
37 while (odp_more_chunks(o, base, len))
38 if (!odr_bitstring(o, &p, 0, 0))
42 /* primitive bitstring */
45 odr_seterror(o, OOTHER, 5);
50 if (len - 1 > ODR_BITMASK_SIZE)
52 odr_seterror(o, OOTHER, 6);
57 odr_seterror(o, OOTHER, 7);
60 o->bp++; /* silently ignore the unused-bits field */
62 memcpy(p->bits + p->top + 1, o->bp, len);
67 if ((res = ber_enclen(o, p->top + 2, 5, 0)) < 0)
69 if (odr_putc(o, 0) < 0) /* no unused bits here */
73 if (odr_write(o, p->bits, p->top + 1) < 0)
79 odr_seterror(o, OOTHER, 8);
86 * c-file-style: "Stroustrup"
87 * indent-tabs-mode: nil
89 * vim: shiftwidth=4 tabstop=8 expandtab