1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
8 * \brief Implements BER OID encoding and decoding
10 * This source file implements BER encoding and decoding of
19 int ber_oidc(ODR o, Odr_oid *p, int max_oid_size)
23 unsigned char octs[8];
28 if ((res = ber_declen(o->op->bp, &len, odr_max(o))) < 1)
30 odr_seterror(o, OPROTO, 18);
35 odr_seterror(o, OPROTO, 19);
41 odr_seterror(o, OPROTO, 20);
52 odr_seterror(o, OPROTO, 21);
56 id |= *o->op->bp & 0X7F;
59 while (*(o->op->bp++) & 0X80);
63 odr_seterror(o, ODATA, 23);
73 p[1] = id - p[0] * 40;
76 if (pos >= max_oid_size)
78 odr_seterror(o, OPROTO, 55);
82 if (pos < 2 || p[0] < 0 || p[1] < 0)
84 odr_seterror(o, ODATA, 23);
90 /* we'll allow ourselves the quiet luxury of only doing encodings
93 if (odr_putc(o, 0) < 0) /* dummy */
95 if (p[0] < 0 || p[1] < 0)
97 odr_seterror(o, ODATA, 23);
100 for (pos = 1; p[pos] != -1; pos++)
109 octs[n++] = id & 0X7F;
117 p = octs[n] | ((n > 0) << 7);
118 if (odr_putc(o, p) < 0)
123 odr_seek(o, ODR_S_SET, lenp);
124 if (ber_enclen(o, (end - lenp) - 1, 1, 1) != 1)
126 odr_seterror(o, OOTHER, 52);
129 odr_seek(o, ODR_S_END, 0);
132 odr_seterror(o, OOTHER, 22);
139 * c-file-style: "Stroustrup"
140 * indent-tabs-mode: nil
142 * vim: shiftwidth=4 tabstop=8 expandtab