blob: 8d43c99701821646dfec9a31946546484c75754a [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#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
Lev Walkin29a044b2004-06-14 07:24:36 +000032 * up to specified (_arc_slots) elements.
Lev Walkinf15320b2004-06-03 03:38:44 +000033 * The function always returns the real number of arcs, even if there is no
Lev Walkin29a044b2004-06-14 07:24:36 +000034 * sufficient (_arc_slots) provided.
Lev Walkinf15320b2004-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;
Lev Walkin29a044b2004-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
Lev Walkinf15320b2004-06-03 03:38:44 +000042 * int count; // Real number of arcs.
43 * int i;
44 *
Lev Walkin29a044b2004-06-14 07:24:36 +000045 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
46 * arc_type_size, arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000047 * // If necessary, reallocate arcs array and try again.
Lev Walkin29a044b2004-06-14 07:24:36 +000048 * if(count > arc_slots) {
49 * arc_slots = count;
50 * arcs = malloc(arc_type_size * arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000051 * if(!arcs) return;
Lev Walkin29a044b2004-06-14 07:24:36 +000052 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
53 * arc_type_size, arc_slots);
54 * assert(count == arc_slots);
Lev Walkinf15320b2004-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 */
Lev Walkin29a044b2004-06-14 07:24:36 +000070int OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *_oid,
Lev Walkin0787ff02004-06-17 23:43:39 +000071 void *_arcs, /* i.e., unsigned int arcs[N] */
72 unsigned int _arc_type_size, /* i.e., sizeof(arcs[0]) */
73 unsigned int _arc_slots /* i.e., N */);
Lev Walkinf15320b2004-06-03 03:38:44 +000074
75/*
76 * This functions initializes the OBJECT IDENTIFIER object with
77 * the given set of arcs.
78 * The minimum of two arcs must be present; some restrictions apply.
79 * RETURN VALUES:
80 * -1/EINVAL: Invalid arguments
81 * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions.
82 * -1/ENOMEM: Memory allocation failed
83 * 0: The object was initialized with new arcs.
84 */
Lev Walkin0787ff02004-06-17 23:43:39 +000085int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *_oid,
86 void *_arcs, /* i.e., unsigned int arcs[N] */
87 unsigned int _arc_type_size, /* i.e., sizeof(arcs[0]) */
88 unsigned int _arc_slots /* i.e., N */);
Lev Walkinf15320b2004-06-03 03:38:44 +000089
90/*
91 * Internal functions.
Lev Walkin0787ff02004-06-17 23:43:39 +000092 * Used by RELATIVE-OID implementation in particular.
Lev Walkinf15320b2004-06-03 03:38:44 +000093 */
Lev Walkin29a044b2004-06-14 07:24:36 +000094int OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen,
95 signed int add, void *value, unsigned int value_size);
Lev Walkin0787ff02004-06-17 23:43:39 +000096int OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf,
97 void *arcval, unsigned int arcval_size, int _prepared_order);
Lev Walkinf15320b2004-06-03 03:38:44 +000098
99#endif /* _OBJECT_IDENTIFIER_H_ */