blob: 3e71f3168a6c30faa97c3626acef6a3e1cf707fe [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
32 * up to specified (_arcs_slots) elements.
33 * The function always returns the real number of arcs, even if there is no
34 * sufficient (_arcs_slots) provided.
35 *
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;
40 * int arcs_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10
41 * int count; // Real number of arcs.
42 * int i;
43 *
44 * count = OBJECT_IDENTIFIER_get_arcs_l(oid, arcs, arcs_slots);
45 * // If necessary, reallocate arcs array and try again.
46 * if(count > arcs_slots) {
47 * arcs_slots = count;
48 * arcs = malloc(arcs_slots * sizeof(arcs[0]));
49 * if(!arcs) return;
50 * count = OBJECT_IDENTIFIER_get_arcs_l(oid,
51 * arcs, arcs_slots);
52 * assert(count == arcs_slots);
53 * }
54 *
55 * // Print the contents of the arcs array.
56 * for(i = 0; i < count; i++)
57 * printf("%d\n", arcs[i]);
58 *
59 * // Avoid memory leak.
60 * if(arcs != fixed_arcs) free(arcs);
61 * }
62 *
63 * RETURN VALUES:
64 * -1/EINVAL: Invalid arguments (oid is missing)
65 * -1/ERANGE: One or more arcs have value out of array cell type range.
66 * >=0: Number of arcs contained in the OBJECT IDENTIFIER
67 */
68int OBJECT_IDENTIFIER_get_arcs_l(OBJECT_IDENTIFIER_t *_oid,
69 unsigned long *_arcs, int _arcs_slots);
70/*
71int OBJECT_IDENTIFIER_get_arcs_im(OBJECT_IDENTIFIER_t *_oid,
72 uintmax_t *_arcs, int _arcs_slots);
73 */
74
75
76/*
77 * This functions initializes the OBJECT IDENTIFIER object with
78 * the given set of arcs.
79 * The minimum of two arcs must be present; some restrictions apply.
80 * RETURN VALUES:
81 * -1/EINVAL: Invalid arguments
82 * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions.
83 * -1/ENOMEM: Memory allocation failed
84 * 0: The object was initialized with new arcs.
85 */
86int OBJECT_IDENTIFIER_set_arcs_l(OBJECT_IDENTIFIER_t *_oid,
87 unsigned long *arcs, int arcs_slots);
88
89/*
90 * Internal functions.
91 */
92int OBJECT_IDENTIFIER_get_arc_l(uint8_t *arcbuf, int arclen,
93 int add, unsigned long *value);
94
95#endif /* _OBJECT_IDENTIFIER_H_ */