blob: 77b07def1678458e644dbd3312f333966c037eb5 [file] [log] [blame]
vlmfa67ddc2004-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#ifndef _OBJECT_IDENTIFIER_H_
6#define _OBJECT_IDENTIFIER_H_
7
8#include <constr_TYPE.h>
9#include <INTEGER.h>
10
11typedef INTEGER_t OBJECT_IDENTIFIER_t; /* Implemented in terms of INTEGER */
12
13extern asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER;
14
15der_type_encoder_f OBJECT_IDENTIFIER_encode_der;
16asn_constr_check_f OBJECT_IDENTIFIER_constraint;
17asn_struct_print_f OBJECT_IDENTIFIER_print;
18
19/**********************************
20 * Some handy conversion routines *
21 **********************************/
22
23/*
24 * Print the specified OBJECT IDENTIFIER arc.
25 */
26int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen,
27 int add, /* Arbitrary offset, required to process the first two arcs */
28 asn_app_consume_bytes_f *cb, void *app_key);
29
30/*
31 * This function fills an (_arcs) array with OBJECT IDENTIFIER arcs
vlm2e3dd3b2004-06-14 07:24:36 +000032 * up to specified (_arc_slots) elements.
vlmfa67ddc2004-06-03 03:38:44 +000033 * The function always returns the real number of arcs, even if there is no
vlm2e3dd3b2004-06-14 07:24:36 +000034 * sufficient (_arc_slots) provided.
vlmfa67ddc2004-06-03 03:38:44 +000035 *
36 * EXAMPLE:
37 * void print_arcs(OBJECT_IDENTIFIER_t *oid) {
38 * unsigned long fixed_arcs[10]; // Try with fixed space first
39 * unsigned long *arcs = fixed_arcs;
vlm2e3dd3b2004-06-14 07:24:36 +000040 * int arc_type_size = sizeof(fixed_arcs[0]); // sizeof(long)
41 * int arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10
vlmfa67ddc2004-06-03 03:38:44 +000042 * int count; // Real number of arcs.
43 * int i;
44 *
vlm2e3dd3b2004-06-14 07:24:36 +000045 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
46 * arc_type_size, arc_slots);
vlmfa67ddc2004-06-03 03:38:44 +000047 * // If necessary, reallocate arcs array and try again.
vlm2e3dd3b2004-06-14 07:24:36 +000048 * if(count > arc_slots) {
49 * arc_slots = count;
50 * arcs = malloc(arc_type_size * arc_slots);
vlmfa67ddc2004-06-03 03:38:44 +000051 * if(!arcs) return;
vlm2e3dd3b2004-06-14 07:24:36 +000052 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
53 * arc_type_size, arc_slots);
54 * assert(count == arc_slots);
vlmfa67ddc2004-06-03 03:38:44 +000055 * }
56 *
57 * // Print the contents of the arcs array.
58 * for(i = 0; i < count; i++)
59 * printf("%d\n", arcs[i]);
60 *
61 * // Avoid memory leak.
62 * if(arcs != fixed_arcs) free(arcs);
63 * }
64 *
65 * RETURN VALUES:
66 * -1/EINVAL: Invalid arguments (oid is missing)
67 * -1/ERANGE: One or more arcs have value out of array cell type range.
68 * >=0: Number of arcs contained in the OBJECT IDENTIFIER
69 */
vlm2e3dd3b2004-06-14 07:24:36 +000070int OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *_oid,
71 void *_arcs, unsigned int _arc_type_size, unsigned int _arc_slots);
vlmfa67ddc2004-06-03 03:38:44 +000072
73/*
74 * This functions initializes the OBJECT IDENTIFIER object with
75 * the given set of arcs.
76 * The minimum of two arcs must be present; some restrictions apply.
77 * RETURN VALUES:
78 * -1/EINVAL: Invalid arguments
79 * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions.
80 * -1/ENOMEM: Memory allocation failed
81 * 0: The object was initialized with new arcs.
82 */
83int OBJECT_IDENTIFIER_set_arcs_l(OBJECT_IDENTIFIER_t *_oid,
vlm2e3dd3b2004-06-14 07:24:36 +000084 unsigned long *_arcs, unsigned int _arc_slots);
vlmfa67ddc2004-06-03 03:38:44 +000085
86/*
87 * Internal functions.
88 */
vlm2e3dd3b2004-06-14 07:24:36 +000089int OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen,
90 signed int add, void *value, unsigned int value_size);
91int OBJECT_IDENTIFIER_get_single_arc_l(uint8_t *arcbuf, unsigned int arclen,
92 signed int add, unsigned long *value);
vlmfa67ddc2004-06-03 03:38:44 +000093
94#endif /* _OBJECT_IDENTIFIER_H_ */