blob: 216aed832e5a43ca5f52c9fb4eacbf28ffb6d419 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#include <OBJECT_IDENTIFIER.h>
Lev Walkin29a044b2004-06-14 07:24:36 +00006#include <limits.h> /* for CHAR_BIT */
Lev Walkinf15320b2004-06-03 03:38:44 +00007#include <assert.h>
8#include <errno.h>
9
10/*
11 * OBJECT IDENTIFIER basic type description.
12 */
13static ber_tlv_tag_t asn1_DEF_OBJECT_IDENTIFIER_tags[] = {
14 (ASN_TAG_CLASS_UNIVERSAL | (6 << 2))
15};
16asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER = {
17 "OBJECT IDENTIFIER",
18 OBJECT_IDENTIFIER_constraint,
19 INTEGER_decode_ber, /* Implemented in terms of INTEGER type */
20 OBJECT_IDENTIFIER_encode_der,
21 OBJECT_IDENTIFIER_print,
22 INTEGER_free,
23 0, /* Use generic outmost tag fetcher */
24 asn1_DEF_OBJECT_IDENTIFIER_tags,
25 sizeof(asn1_DEF_OBJECT_IDENTIFIER_tags)
26 / sizeof(asn1_DEF_OBJECT_IDENTIFIER_tags[0]),
27 1, /* Single UNIVERSAL tag may be implicitly overriden */
Lev Walkind9bd7752004-06-05 08:17:50 +000028 0, /* Always in primitive form */
29 0 /* No specifics */
Lev Walkinf15320b2004-06-03 03:38:44 +000030};
31
32
33/*
34 * Encode OBJECT IDENTIFIER type using DER.
35 */
36der_enc_rval_t
37OBJECT_IDENTIFIER_encode_der(asn1_TYPE_descriptor_t *sd, void *ptr,
38 int tag_mode, ber_tlv_tag_t tag,
39 asn_app_consume_bytes_f *cb, void *app_key) {
40 der_enc_rval_t erval;
41 OBJECT_IDENTIFIER_t *st = ptr;
42
43 ASN_DEBUG("%s %s as OBJECT IDENTIFIER (tm=%d)",
44 cb?"Encoding":"Estimating", sd->name, tag_mode);
45
46 erval.encoded = der_write_tags(sd, st->size, tag_mode, tag,
47 cb, app_key);
48 ASN_DEBUG("OBJECT IDENTIFIER %s wrote tags %d",
49 sd->name, (int)erval.encoded);
50 if(erval.encoded == -1) {
51 erval.failed_type = sd;
52 erval.structure_ptr = ptr;
53 return erval;
54 }
55
56 if(cb && st->buf) {
57 ssize_t ret;
58
59 ret = cb(st->buf, st->size, app_key);
60 if(ret == -1) {
61 erval.encoded = -1;
62 erval.failed_type = sd;
63 erval.structure_ptr = ptr;
64 return erval;
65 }
66 } else {
67 assert(st->buf || st->size == 0);
68 }
69
70 erval.encoded += st->size;
71
72 return erval;
73}
74
75int
76OBJECT_IDENTIFIER_constraint(asn1_TYPE_descriptor_t *td, const void *sptr,
77 asn_app_consume_bytes_f *app_errlog, void *app_key) {
78 const OBJECT_IDENTIFIER_t *st = sptr;
79
80 if(st && st->buf) {
81 if(st->size < 1) {
82 _ASN_ERRLOG("%s: at least one numerical value expected",
83 td->name);
84 return -1;
85 }
86 } else {
87 _ASN_ERRLOG("%s: value not given", td->name);
88 return -1;
89 }
90
91 return 0;
92}
93
Lev Walkinc4c61962004-06-14 08:17:27 +000094
Lev Walkinf15320b2004-06-03 03:38:44 +000095int
Lev Walkin29a044b2004-06-14 07:24:36 +000096OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, signed int add, void *rvbuf, unsigned int rvsize) {
97 unsigned LE = 1; /* Little endian (x86) */
98 uint8_t *arcend = arcbuf + arclen; /* End of arc */
99 void *rvstart = rvbuf; /* Original start of the value buffer */
100 unsigned int cache = 0; /* No more than 14 significant bits */
101 int inc; /* Return value growth direction */
Lev Walkinf15320b2004-06-03 03:38:44 +0000102
Lev Walkin29a044b2004-06-14 07:24:36 +0000103 rvsize *= CHAR_BIT; /* bytes to bits */
104 arclen *= 7; /* bytes to bits */
105
106 /*
107 * The arc has the number of bits
108 * cannot be represented using supplied return value type.
109 */
110 if(arclen > rvsize) {
111 if(arclen > (rvsize + CHAR_BIT)) {
112 errno = ERANGE; /* Overflow */
113 return -1;
114 } else {
115 /*
116 * Even if the number of bits in the arc representation
117 * is higher than the width of supplied * return value
118 * type, there is still possible to fit it when there
119 * are few unused high bits in the arc value
120 * representaion.
Lev Walkin0787ff02004-06-17 23:43:39 +0000121 *
122 * Moreover, there is a possibility that the
123 * number could actually fit the arc space, given
124 * that add is negative, but we don't handle
125 * such "temporary lack of precision" situation here.
126 * May be considered as a bug.
Lev Walkin29a044b2004-06-14 07:24:36 +0000127 */
128 uint8_t mask = (0xff << (7-(arclen - rvsize))) & 0x7f;
129 if((*arcbuf & mask)) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000130 errno = ERANGE; /* Overflow */
131 return -1;
132 }
Lev Walkin29a044b2004-06-14 07:24:36 +0000133 /* Fool the routine computing unused bits */
134 arclen -= 7;
135 cache = *arcbuf & 0x7f;
136 arcbuf++;
137 }
138 }
139
Lev Walkinc4c61962004-06-14 08:17:27 +0000140 /* Faster path for common size */
141 if(rvsize == (CHAR_BIT * sizeof(unsigned long))) {
142 unsigned long accum;
143 /* Gather all bits into the accumulator */
144 for(accum = cache; arcbuf < arcend; arcbuf++)
145 accum = (accum << 7) | (*arcbuf & ~0x80);
146 if(accum < (unsigned)-add) {
147 errno = ERANGE; /* Overflow */
148 return -1;
149 }
150 *(unsigned long *)rvbuf = accum + add;
151 return 0;
152 }
153
Lev Walkin29a044b2004-06-14 07:24:36 +0000154#ifndef WORDS_BIGENDIAN
155 if(*(unsigned char *)&LE) { /* Little endian (x86) */
156 /* "Convert" to big endian */
Lev Walkinc4c61962004-06-14 08:17:27 +0000157 rvbuf += rvsize / CHAR_BIT - 1;
158 ((unsigned char *)rvstart)--;
Lev Walkin29a044b2004-06-14 07:24:36 +0000159 inc = -1; /* Descending */
Lev Walkinc4c61962004-06-14 08:17:27 +0000160 } else
Lev Walkin29a044b2004-06-14 07:24:36 +0000161#endif /* !WORDS_BIGENDIAN */
Lev Walkinc4c61962004-06-14 08:17:27 +0000162 inc = +1; /* Big endian is known [at compile time] */
Lev Walkin29a044b2004-06-14 07:24:36 +0000163
Lev Walkinc4c61962004-06-14 08:17:27 +0000164 {
Lev Walkin0787ff02004-06-17 23:43:39 +0000165 int bits; /* typically no more than 3-4 bits */
Lev Walkinc4c61962004-06-14 08:17:27 +0000166
Lev Walkin29a044b2004-06-14 07:24:36 +0000167 /* Clear the high unused bits */
168 for(bits = rvsize - arclen;
169 bits > CHAR_BIT;
170 rvbuf += inc, bits -= CHAR_BIT)
171 *(unsigned char *)rvbuf = 0;
Lev Walkinc4c61962004-06-14 08:17:27 +0000172
Lev Walkin29a044b2004-06-14 07:24:36 +0000173 /* Fill the body of a value */
174 for(; arcbuf < arcend; arcbuf++) {
175 cache = (cache << 7) | (*arcbuf & 0x7f);
176 bits += 7;
177 if(bits >= CHAR_BIT) {
178 bits -= CHAR_BIT;
179 *(unsigned char *)rvbuf = (cache >> bits);
180 rvbuf += inc;
181 }
182 }
183 if(bits) {
184 *(unsigned char *)rvbuf = cache;
185 rvbuf += inc;
186 }
187 }
188
189 if(add) {
190 for(rvbuf -= inc; rvbuf != rvstart; rvbuf -= inc) {
191 int v = add + *(unsigned char *)rvbuf;
192 if(v & (-1 << CHAR_BIT)) {
193 *(unsigned char *)rvbuf
194 = v + (1 << CHAR_BIT);
195 add = -1;
196 } else {
197 *(unsigned char *)rvbuf = v;
198 break;
199 }
200 }
201 if(rvbuf == rvstart) {
202 /* No space to carry over */
Lev Walkinf15320b2004-06-03 03:38:44 +0000203 errno = ERANGE; /* Overflow */
204 return -1;
205 }
206 }
207
Lev Walkinf15320b2004-06-03 03:38:44 +0000208 return 0;
209}
210
Lev Walkin29a044b2004-06-14 07:24:36 +0000211
Lev Walkinf15320b2004-06-03 03:38:44 +0000212int
213OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, int add,
214 asn_app_consume_bytes_f *cb, void *app_key) {
215 char scratch[64]; /* Conservative estimate */
216 unsigned long accum; /* Bits accumulator */
217 char *p; /* Position in the scratch buffer */
218
Lev Walkin29a044b2004-06-14 07:24:36 +0000219 if(OBJECT_IDENTIFIER_get_single_arc(arcbuf, arclen, add,
220 &accum, sizeof(accum)))
Lev Walkinf15320b2004-06-03 03:38:44 +0000221 return -1;
222
223 /* Fill the scratch buffer in reverse. */
224 p = scratch + sizeof(scratch);
225 for(; accum; accum /= 10)
226 *(--p) = (accum % 10) + 0x30;
227
228 return cb(p, sizeof(scratch) - (p - scratch), app_key);
229}
230
231int
232OBJECT_IDENTIFIER_print(asn1_TYPE_descriptor_t *td, const void *sptr,
233 int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
234 const OBJECT_IDENTIFIER_t *st = sptr;
235 int startn;
236 int add = 0;
237 int i;
238
Lev Walkind9bd7752004-06-05 08:17:50 +0000239 (void)td; /* Unused argument */
240 (void)ilevel; /* Unused argument */
241
Lev Walkinf15320b2004-06-03 03:38:44 +0000242 if(!st || !st->buf)
243 return cb("<absent>", 8, app_key);
244
245 /* Dump preamble */
246 if(cb("{ ", 2, app_key))
247 return -1;
248
249 for(i = 0, startn = 0; i < st->size; i++) {
250 uint8_t b = st->buf[i];
251 if((b & 0x80)) /* Continuation expected */
252 continue;
253
254 if(startn == 0) {
255 /*
256 * First two arcs are encoded through the backdoor.
257 */
258 if(i) {
259 add = -80;
260 if(cb("2", 1, app_key)) return -1;
261 } else if(b <= 39) {
262 add = 0;
263 if(cb("0", 1, app_key)) return -1;
264 } else if(b < 79) {
265 add = -40;
266 if(cb("1", 1, app_key)) return -1;
267 } else {
268 add = -80;
269 if(cb("2", 1, app_key)) return -1;
270 }
271 }
272
273 if(cb(" ", 1, app_key)) /* Separate arcs */
274 return -1;
275
276 if(OBJECT_IDENTIFIER_print_arc(&st->buf[startn],
277 i - startn + 1, add,
278 cb, app_key))
279 return -1;
280 startn = i + 1;
281 add = 0;
282 }
283
284 return cb(" }", 2, app_key);
285}
286
287int
Lev Walkin29a044b2004-06-14 07:24:36 +0000288OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *oid, void *arcs,
289 unsigned int arc_type_size, unsigned int arc_slots) {
290 void *arcs_end = arcs + (arc_type_size * arc_slots);
291 int num_arcs = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000292 int startn = 0;
293 int add = 0;
294 int i;
295
Lev Walkin0787ff02004-06-17 23:43:39 +0000296 if(!oid || !oid->buf || (arc_slots && arc_type_size <= 1)) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000297 errno = EINVAL;
298 return -1;
299 }
300
301 for(i = 0; i < oid->size; i++) {
302 uint8_t b = oid->buf[i];
303 if((b & 0x80)) /* Continuation expected */
304 continue;
305
Lev Walkin29a044b2004-06-14 07:24:36 +0000306 if(num_arcs == 0) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000307 /*
308 * First two arcs are encoded through the backdoor.
309 */
Lev Walkin29a044b2004-06-14 07:24:36 +0000310 unsigned LE = 1; /* Little endian */
311 int first_arc;
312 num_arcs++;
313 if(!arc_slots) { num_arcs++; continue; }
314
315 if(i) first_arc = 2;
316 else if(b <= 39) first_arc = 0;
317 else if(b < 79) first_arc = 1;
318 else first_arc = 2;
319
320 add = -40 * first_arc;
321 memset(arcs, 0, arc_type_size);
322 *(unsigned char *)(arcs
323 + ((*(char *)&LE)?0:(arc_type_size - 1)))
324 = first_arc;
325 arcs += arc_type_size;
Lev Walkinf15320b2004-06-03 03:38:44 +0000326 }
327
Lev Walkin29a044b2004-06-14 07:24:36 +0000328 /* Decode, if has space */
329 if(arcs < arcs_end) {
330 if(OBJECT_IDENTIFIER_get_single_arc(&oid->buf[startn],
331 i - startn + 1, add,
332 arcs, arc_type_size))
333 return -1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000334 startn = i + 1;
Lev Walkin29a044b2004-06-14 07:24:36 +0000335 arcs += arc_type_size;
336 add = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000337 }
Lev Walkin29a044b2004-06-14 07:24:36 +0000338 num_arcs++;
Lev Walkinf15320b2004-06-03 03:38:44 +0000339 }
340
Lev Walkin29a044b2004-06-14 07:24:36 +0000341 return num_arcs;
Lev Walkinf15320b2004-06-03 03:38:44 +0000342}
343
Lev Walkin0787ff02004-06-17 23:43:39 +0000344
345/*
346 * Save the single value as an object identifier arc.
347 */
348inline int
349OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, void *arcval, unsigned int arcval_size, int prepared_order) {
350 /*
351 * The following conditions must hold:
352 * assert(arcval);
353 * assert(arcval_size > 0);
354 * assert(arcbuf);
355 */
356#ifdef WORDS_BIGENDIAN
357 const unsigned isLittleEndian = 0;
358#else
359 unsigned LE = 1;
360 unsigned isLittleEndian = *(char *)&LE;
361#endif
Lev Walkin0787ff02004-06-17 23:43:39 +0000362 uint8_t *tp, *tend;
363 unsigned int cache;
364 uint8_t *bp = arcbuf;
365 int bits;
Lev Walkin64399722004-08-11 07:17:22 +0000366#ifdef __GNUC__
367 uint8_t buffer[arcval_size];
368#else
369 uint8_t *buffer = alloca(arcval_size);
Lev Walkin7e0d2cb2004-08-11 07:41:45 +0000370 if(!buffer) { errno = ENOMEM; return -1; }
Lev Walkin64399722004-08-11 07:17:22 +0000371#endif
Lev Walkin0787ff02004-06-17 23:43:39 +0000372
373 if(isLittleEndian && !prepared_order) {
374 uint8_t *a = arcval + arcval_size - 1;
375 uint8_t *aend = arcval;
376 uint8_t *msb = buffer + arcval_size - 1;
377 for(tp = buffer; a >= aend; tp++, a--)
378 if((*tp = *a) && (tp < msb))
379 msb = tp;
380 tend = &buffer[arcval_size];
381 tp = msb; /* Most significant non-zero byte */
382 } else {
383 /* Look for most significant non-zero byte */
384 tend = arcval + arcval_size;
385 for(tp = arcval; tp < tend - 1; tp++)
386 if(*tp) break;
387 }
388
389 /*
390 * Split the value in 7-bits chunks.
391 */
392 bits = ((tend - tp) * CHAR_BIT) % 7;
393 if(bits) {
394 cache = *tp >> (CHAR_BIT - bits);
395 if(cache) {
396 *bp++ = cache | 0x80;
397 cache = *tp++;
398 bits = CHAR_BIT - bits;
399 } else {
400 bits = -bits;
401 }
402 } else {
403 cache = 0;
404 }
405 for(; tp < tend; tp++) {
406 cache = (cache << CHAR_BIT) + *tp;
407 bits += CHAR_BIT;
408 while(bits >= 7) {
409 bits -= 7;
410 *bp++ = 0x80 | (cache >> bits);
411 }
412 }
413 if(bits) *bp++ = cache;
414 bp[-1] &= 0x7f; /* Clear the last bit */
415
416 return bp - arcbuf;
417}
418
Lev Walkinf15320b2004-06-03 03:38:44 +0000419int
Lev Walkin0787ff02004-06-17 23:43:39 +0000420OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *oid, void *arcs, unsigned int arc_type_size, unsigned int arc_slots) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000421 uint8_t *buf;
422 uint8_t *bp;
Lev Walkin0787ff02004-06-17 23:43:39 +0000423 unsigned LE = 1; /* Little endian (x86) */
424 unsigned isLittleEndian = *((char *)&LE);
425 unsigned int arc0;
426 unsigned int arc1;
427 unsigned size;
Lev Walkinc4c61962004-06-14 08:17:27 +0000428 unsigned i;
Lev Walkinf15320b2004-06-03 03:38:44 +0000429
Lev Walkin0787ff02004-06-17 23:43:39 +0000430 if(!oid || !arcs || arc_type_size < 1 || arc_slots < 2) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000431 errno = EINVAL;
432 return -1;
433 }
434
Lev Walkin0787ff02004-06-17 23:43:39 +0000435 switch(arc_type_size) {
436 case sizeof(char):
437 arc0 = ((unsigned char *)arcs)[0];
438 arc1 = ((unsigned char *)arcs)[1];
439 break;
440 case sizeof(short):
441 arc0 = ((unsigned short *)arcs)[0];
442 arc1 = ((unsigned short *)arcs)[1];
443 break;
444 case sizeof(int):
445 arc0 = ((unsigned int *)arcs)[0];
446 arc1 = ((unsigned int *)arcs)[1];
447 break;
448 default:
449 arc1 = arc0 = 0;
450 if(isLittleEndian) { /* Little endian (x86) */
451 unsigned char *ps, *pe;
452 /* If more significant bytes are present,
453 * make them > 255 quick */
454 for(ps = arcs + 1, pe = ps+arc_type_size; ps < pe; ps++)
455 arc0 |= *ps, arc1 |= *(ps + arc_type_size);
456 arc0 <<= CHAR_BIT, arc1 <<= CHAR_BIT;
457 arc0 = *((unsigned char *)arcs + 0);
458 arc1 = *((unsigned char *)arcs + arc_type_size);
459 } else {
460 unsigned char *ps, *pe;
461 /* If more significant bytes are present,
462 * make them > 255 quick */
463 for(ps = arcs, pe = ps+arc_type_size - 1; ps < pe; ps++)
464 arc0 |= *ps, arc1 |= *(ps + arc_type_size);
465 arc0 = *((unsigned char *)arcs + arc_type_size - 1);
466 arc1 = *((unsigned char *)arcs +(arc_type_size<< 1)-1);
467 }
468 }
469
470 /*
471 * The previous chapter left us with the first and the second arcs.
472 * The values are not precise (that is, they are valid only if
473 * they're less than 255), but OK for the purposes of making
474 * the sanity test below.
475 */
476 if(arc0 <= 1) {
477 if(arc1 >= 39) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000478 /* 8.19.4: At most 39 subsequent values (including 0) */
479 errno = ERANGE;
480 return -1;
481 }
Lev Walkin0787ff02004-06-17 23:43:39 +0000482 } else if(arc0 > 2) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000483 /* 8.19.4: Only three values are allocated from the root node */
484 errno = ERANGE;
485 return -1;
486 }
Lev Walkin0787ff02004-06-17 23:43:39 +0000487 /*
488 * After above tests it is known that the value of arc0 is completely
489 * trustworthy (0..2). However, the arc1's value is still meaningless.
490 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000491
492 /*
493 * Roughly estimate the maximum size necessary to encode these arcs.
Lev Walkin0787ff02004-06-17 23:43:39 +0000494 * This estimation implicitly takes in account the following facts,
495 * that cancel each other:
496 * * the first two arcs are encoded in a single value.
497 * * the first value may require more space (+1 byte)
498 * * the value of the first arc which is in range (0..2)
Lev Walkinf15320b2004-06-03 03:38:44 +0000499 */
Lev Walkin0787ff02004-06-17 23:43:39 +0000500 size = ((arc_type_size * CHAR_BIT + 6) / 7) * arc_slots;
Lev Walkinf15320b2004-06-03 03:38:44 +0000501 bp = buf = MALLOC(size + 1);
502 if(!buf) {
503 /* ENOMEM */
504 return -1;
505 }
506
507 /*
Lev Walkin0787ff02004-06-17 23:43:39 +0000508 * Encode the first two arcs.
509 * These require special treatment.
Lev Walkinf15320b2004-06-03 03:38:44 +0000510 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000511 {
Lev Walkin0787ff02004-06-17 23:43:39 +0000512 uint8_t *tp;
Lev Walkin90fcd442004-08-11 07:48:19 +0000513#ifdef __GNUC__
514 uint8_t first_value[1 + arc_type_size]; /* of two arcs */
515#else
516 uint8_t *first_value = alloca(1 + arc_type_size);
517#endif
518 uint8_t *fv = first_value;
Lev Walkinf15320b2004-06-03 03:38:44 +0000519
Lev Walkin0787ff02004-06-17 23:43:39 +0000520 /*
521 * Simulate first_value = arc0 * 40 + arc1;
522 */
523 /* Copy the second (1'st) arcs[1] into the first_value */
524 *fv++ = 0;
525 (char *)arcs += arc_type_size;
526 if(isLittleEndian) {
527 uint8_t *aend = arcs - 1;
528 uint8_t *a1 = arcs + arc_type_size - 1;
529 for(; a1 > aend; fv++, a1--) *fv = *a1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000530 } else {
Lev Walkin0787ff02004-06-17 23:43:39 +0000531 uint8_t *a1 = arcs;
532 uint8_t *aend = a1 + arc_type_size;
533 for(; a1 < aend; fv++, a1++) *fv = *a1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000534 }
Lev Walkin0787ff02004-06-17 23:43:39 +0000535 /* Increase the first_value by arc0 */
536 arc0 *= 40; /* (0..80) */
537 for(tp = first_value + arc_type_size; tp >= first_value; tp--) {
538 unsigned int v = *tp;
539 v += arc0;
540 *tp = v;
541 if(v >= (1 << CHAR_BIT)) arc0 = v >> CHAR_BIT;
542 else break;
543 }
544
545 assert(tp >= first_value);
546
547 bp += OBJECT_IDENTIFIER_set_single_arc(bp, first_value,
548 fv - first_value, 1);
549 }
550
551 /*
552 * Save the rest of arcs.
553 */
554 for((char *)arcs += arc_type_size, i = 2;
555 i < arc_slots; i++, (char *)arcs += arc_type_size) {
556 bp += OBJECT_IDENTIFIER_set_single_arc(bp,
557 arcs, arc_type_size, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000558 }
559
Lev Walkin34b2a932004-06-17 23:46:45 +0000560 assert((unsigned)(bp - buf) <= size);
Lev Walkinf15320b2004-06-03 03:38:44 +0000561
562 /*
563 * Replace buffer.
564 */
Lev Walkin0787ff02004-06-17 23:43:39 +0000565 oid->size = bp - buf;
Lev Walkinf15320b2004-06-03 03:38:44 +0000566 bp = oid->buf;
567 oid->buf = buf;
568 if(bp) FREEMEM(bp);
569
570 return 0;
571}
Lev Walkinc4c61962004-06-14 08:17:27 +0000572