blob: 668bd495fc0940ece9953d7ad953b296fcf09dae [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
Lev Walkin8e8078a2004-09-26 13:10:40 +00008#include <asn_application.h>
Lev Walkin3256d6f2004-10-21 11:22:12 +00009#include <asn_codecs_prim.h>
Lev Walkinf15320b2004-06-03 03:38:44 +000010
Lev Walkin8e8078a2004-09-26 13:10:40 +000011typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t;
Lev Walkinf15320b2004-06-03 03:38:44 +000012
Lev Walkin5e033762004-09-29 13:26:15 +000013extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER;
Lev Walkinf15320b2004-06-03 03:38:44 +000014
Lev Walkinf15320b2004-06-03 03:38:44 +000015asn_struct_print_f OBJECT_IDENTIFIER_print;
Lev Walkina9cc46e2004-09-22 16:06:28 +000016asn_constr_check_f OBJECT_IDENTIFIER_constraint;
17der_type_encoder_f OBJECT_IDENTIFIER_encode_der;
18xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer;
Lev Walkinf15320b2004-06-03 03:38:44 +000019
20/**********************************
21 * Some handy conversion routines *
22 **********************************/
23
24/*
25 * Print the specified OBJECT IDENTIFIER arc.
26 */
27int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen,
28 int add, /* Arbitrary offset, required to process the first two arcs */
29 asn_app_consume_bytes_f *cb, void *app_key);
30
Lev Walkina9cc46e2004-09-22 16:06:28 +000031/* Same as above, but returns the number of written digits, instead of 0 */
32ssize_t OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add,
33 asn_app_consume_bytes_f *cb, void *app_key);
34
Lev Walkinf15320b2004-06-03 03:38:44 +000035/*
36 * This function fills an (_arcs) array with OBJECT IDENTIFIER arcs
Lev Walkin29a044b2004-06-14 07:24:36 +000037 * up to specified (_arc_slots) elements.
Lev Walkinf15320b2004-06-03 03:38:44 +000038 * The function always returns the real number of arcs, even if there is no
Lev Walkin29a044b2004-06-14 07:24:36 +000039 * sufficient (_arc_slots) provided.
Lev Walkinf15320b2004-06-03 03:38:44 +000040 *
41 * EXAMPLE:
42 * void print_arcs(OBJECT_IDENTIFIER_t *oid) {
43 * unsigned long fixed_arcs[10]; // Try with fixed space first
44 * unsigned long *arcs = fixed_arcs;
Lev Walkin29a044b2004-06-14 07:24:36 +000045 * int arc_type_size = sizeof(fixed_arcs[0]); // sizeof(long)
46 * int arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10
Lev Walkinf15320b2004-06-03 03:38:44 +000047 * int count; // Real number of arcs.
48 * int i;
49 *
Lev Walkin29a044b2004-06-14 07:24:36 +000050 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
51 * arc_type_size, arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000052 * // If necessary, reallocate arcs array and try again.
Lev Walkin29a044b2004-06-14 07:24:36 +000053 * if(count > arc_slots) {
54 * arc_slots = count;
55 * arcs = malloc(arc_type_size * arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000056 * if(!arcs) return;
Lev Walkin29a044b2004-06-14 07:24:36 +000057 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
58 * arc_type_size, arc_slots);
59 * assert(count == arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000060 * }
61 *
62 * // Print the contents of the arcs array.
63 * for(i = 0; i < count; i++)
64 * printf("%d\n", arcs[i]);
65 *
66 * // Avoid memory leak.
67 * if(arcs != fixed_arcs) free(arcs);
68 * }
69 *
70 * RETURN VALUES:
71 * -1/EINVAL: Invalid arguments (oid is missing)
72 * -1/ERANGE: One or more arcs have value out of array cell type range.
73 * >=0: Number of arcs contained in the OBJECT IDENTIFIER
74 */
Lev Walkin29a044b2004-06-14 07:24:36 +000075int OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *_oid,
Lev Walkin0787ff02004-06-17 23:43:39 +000076 void *_arcs, /* i.e., unsigned int arcs[N] */
77 unsigned int _arc_type_size, /* i.e., sizeof(arcs[0]) */
78 unsigned int _arc_slots /* i.e., N */);
Lev Walkinf15320b2004-06-03 03:38:44 +000079
80/*
81 * This functions initializes the OBJECT IDENTIFIER object with
82 * the given set of arcs.
83 * The minimum of two arcs must be present; some restrictions apply.
84 * RETURN VALUES:
85 * -1/EINVAL: Invalid arguments
86 * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions.
87 * -1/ENOMEM: Memory allocation failed
88 * 0: The object was initialized with new arcs.
89 */
Lev Walkin0787ff02004-06-17 23:43:39 +000090int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *_oid,
91 void *_arcs, /* i.e., unsigned int arcs[N] */
92 unsigned int _arc_type_size, /* i.e., sizeof(arcs[0]) */
93 unsigned int _arc_slots /* i.e., N */);
Lev Walkinf15320b2004-06-03 03:38:44 +000094
95/*
96 * Internal functions.
Lev Walkin0787ff02004-06-17 23:43:39 +000097 * Used by RELATIVE-OID implementation in particular.
Lev Walkinf15320b2004-06-03 03:38:44 +000098 */
Lev Walkin29a044b2004-06-14 07:24:36 +000099int OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen,
100 signed int add, void *value, unsigned int value_size);
Lev Walkin0787ff02004-06-17 23:43:39 +0000101int OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf,
102 void *arcval, unsigned int arcval_size, int _prepared_order);
Lev Walkinf15320b2004-06-03 03:38:44 +0000103
104#endif /* _OBJECT_IDENTIFIER_H_ */