2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: ber_oid.c,v 1.9 2007-01-03 08:42:15 adam Exp $
10 * \brief Implements BER OID encoding and decoding
12 * This source file implements BER encoding and decoding of
21 int ber_oidc(ODR o, Odr_oid *p, int max_oid_size)
25 unsigned char octs[8];
30 if ((res = ber_declen(o->bp, &len, odr_max(o))) < 1)
32 odr_seterror(o, OPROTO, 18);
37 odr_seterror(o, OPROTO, 19);
43 odr_seterror(o, OPROTO, 20);
54 odr_seterror(o, OPROTO, 21);
61 while (*(o->bp++) & 0X80);
65 odr_seterror(o, ODATA, 23);
75 p[1] = id - p[0] * 40;
78 if (pos >= max_oid_size)
80 odr_seterror(o, OPROTO, 55);
84 if (pos < 2 || p[0] < 0 || p[1] < 0)
86 odr_seterror(o, ODATA, 23);
92 /* we'll allow ourselves the quiet luxury of only doing encodings
95 if (odr_putc(o, 0) < 0) /* dummy */
97 if (p[0] < 0 || p[1] < 0)
99 odr_seterror(o, ODATA, 23);
102 for (pos = 1; p[pos] != -1; pos++)
111 octs[n++] = id & 0X7F;
119 p = octs[n] | ((n > 0) << 7);
120 if (odr_putc(o, p) < 0)
125 odr_seek(o, ODR_S_SET, lenp);
126 if (ber_enclen(o, (end - lenp) - 1, 1, 1) != 1)
128 odr_seterror(o, OOTHER, 52);
131 odr_seek(o, ODR_S_END, 0);
134 odr_seterror(o, OOTHER, 22);
141 * indent-tabs-mode: nil
143 * vim: shiftwidth=4 tabstop=8 expandtab