00001
00002
00003
00004
00005
00013 #if HAVE_CONFIG_H
00014 #include <config.h>
00015 #endif
00016
00017 #include "odr-priv.h"
00018
00019 int ber_oidc(ODR o, Odr_oid *p, int max_oid_size)
00020 {
00021 int len, lenp, end;
00022 int pos, n, res, id;
00023 unsigned char octs[8];
00024
00025 switch (o->direction)
00026 {
00027 case ODR_DECODE:
00028 if ((res = ber_declen(o->bp, &len, odr_max(o))) < 1)
00029 {
00030 odr_seterror(o, OPROTO, 18);
00031 return 0;
00032 }
00033 if (len < 0)
00034 {
00035 odr_seterror(o, OPROTO, 19);
00036 return 0;
00037 }
00038 o->bp += res;
00039 if (len > odr_max(o))
00040 {
00041 odr_seterror(o, OPROTO, 20);
00042 return 0;
00043 }
00044 pos = 0;
00045 while (len)
00046 {
00047 int id = 0;
00048 do
00049 {
00050 if (!len)
00051 {
00052 odr_seterror(o, OPROTO, 21);
00053 return 0;
00054 }
00055 id <<= 7;
00056 id |= *o->bp & 0X7F;
00057 len--;
00058 }
00059 while (*(o->bp++) & 0X80);
00060
00061 if (id < 0)
00062 {
00063 odr_seterror(o, ODATA, 23);
00064 return 0;
00065 }
00066 if (pos > 0)
00067 p[pos++] = id;
00068 else
00069 {
00070 p[0] = id / 40;
00071 if (p[0] > 2)
00072 p[0] = 2;
00073 p[1] = id - p[0] * 40;
00074 pos = 2;
00075 }
00076 if (pos >= max_oid_size)
00077 {
00078 odr_seterror(o, OPROTO, 55);
00079 return 0;
00080 }
00081 }
00082 if (pos < 2 || p[0] < 0 || p[1] < 0)
00083 {
00084 odr_seterror(o, ODATA, 23);
00085 return 0;
00086 }
00087 p[pos] = -1;
00088 return 1;
00089 case ODR_ENCODE:
00090
00091
00092 lenp = odr_tell(o);
00093 if (odr_putc(o, 0) < 0)
00094 return 0;
00095 if (p[0] < 0 || p[1] < 0)
00096 {
00097 odr_seterror(o, ODATA, 23);
00098 return 0;
00099 }
00100 for (pos = 1; p[pos] != -1; pos++)
00101 {
00102 n = 0;
00103 if (pos == 1)
00104 id = p[0]*40 + p[1];
00105 else
00106 id = p[pos];
00107 do
00108 {
00109 octs[n++] = id & 0X7F;
00110 id >>= 7;
00111 }
00112 while (id);
00113 while (n--)
00114 {
00115 unsigned char p;
00116
00117 p = octs[n] | ((n > 0) << 7);
00118 if (odr_putc(o, p) < 0)
00119 return 0;
00120 }
00121 }
00122 end = odr_tell(o);
00123 odr_seek(o, ODR_S_SET, lenp);
00124 if (ber_enclen(o, (end - lenp) - 1, 1, 1) != 1)
00125 {
00126 odr_seterror(o, OOTHER, 52);
00127 return 0;
00128 }
00129 odr_seek(o, ODR_S_END, 0);
00130 return 1;
00131 default:
00132 odr_seterror(o, OOTHER, 22);
00133 return 0;
00134 }
00135 }
00136
00137
00138
00139
00140
00141
00142
00143