2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: ber_bit.c,v 1.5 2007-01-03 08:42:15 adam Exp $
10 * \brief Implements BER BITSTRING encoding and decoding.
12 * This source file implements BER encoding and decoding of
22 int ber_bitstring(ODR o, Odr_bitmask *p, int cons)
25 const unsigned char *base;
30 if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
32 odr_seterror(o, OPROTO, 4);
36 if (cons) /* fetch component strings */
39 while (odp_more_chunks(o, base, len))
40 if (!odr_bitstring(o, &p, 0, 0))
44 /* primitive bitstring */
47 odr_seterror(o, OOTHER, 5);
52 if (len - 1 > ODR_BITMASK_SIZE)
54 odr_seterror(o, OOTHER, 6);
59 odr_seterror(o, OOTHER, 7);
62 o->bp++; /* silently ignore the unused-bits field */
64 memcpy(p->bits + p->top + 1, o->bp, len);
69 if ((res = ber_enclen(o, p->top + 2, 5, 0)) < 0)
71 if (odr_putc(o, 0) < 0) /* no unused bits here */
75 if (odr_write(o, p->bits, p->top + 1) < 0)
81 odr_seterror(o, OOTHER, 8);
88 * indent-tabs-mode: nil
90 * vim: shiftwidth=4 tabstop=8 expandtab