Sync from Azure to LF
[ric-plt/resource-status-manager.git] / RSM / asn1codec / e2ap_engine / OBJECT_IDENTIFIER.h
1
2 /*
3  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #ifndef _OBJECT_IDENTIFIER_H_
7 #define _OBJECT_IDENTIFIER_H_
8
9 #include <asn_application.h>
10 #include <asn_codecs_prim.h>
11 #include <OCTET_STRING.h>
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 typedef uint32_t asn_oid_arc_t;
18 #define ASN_OID_ARC_MAX (~((asn_oid_arc_t)0))
19
20 typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t;
21
22 extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER;
23 extern asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER;
24
25 asn_struct_print_f OBJECT_IDENTIFIER_print;
26 asn_constr_check_f OBJECT_IDENTIFIER_constraint;
27 der_type_encoder_f OBJECT_IDENTIFIER_encode_der;
28 xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer;
29 xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer;
30 asn_random_fill_f  OBJECT_IDENTIFIER_random_fill;
31
32 #define OBJECT_IDENTIFIER_free           ASN__PRIMITIVE_TYPE_free
33 #define OBJECT_IDENTIFIER_compare        OCTET_STRING_compare
34 #define OBJECT_IDENTIFIER_decode_ber     ber_decode_primitive
35 #define OBJECT_IDENTIFIER_encode_der     der_encode_primitive
36 #define OBJECT_IDENTIFIER_decode_oer     oer_decode_primitive
37 #define OBJECT_IDENTIFIER_encode_oer     oer_encode_primitive
38 #define OBJECT_IDENTIFIER_decode_uper    OCTET_STRING_decode_uper
39 #define OBJECT_IDENTIFIER_encode_uper    OCTET_STRING_encode_uper
40 #define OBJECT_IDENTIFIER_decode_aper    OCTET_STRING_decode_aper
41 #define OBJECT_IDENTIFIER_encode_aper    OCTET_STRING_encode_aper
42
43 /**********************************
44  * Some handy conversion routines *
45  **********************************/
46
47 /*
48  * This function fills an (arcs) array with OBJECT IDENTIFIER arcs
49  * up to specified (arc_slots) elements.
50  *
51  * EXAMPLE:
52  *      void print_arcs(OBJECT_IDENTIFIER_t *oid) {
53  *              asn_oid_arc_t fixed_arcs[10];   // Try with fixed space first
54  *              asn_oid_arc_t *arcs = fixed_arcs;
55  *              size_t arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10
56  *              ssize_t count;  // Real number of arcs.
57  *              int i;
58  *
59  *              count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots);
60  *              // If necessary, reallocate arcs array and try again.
61  *              if(count > arc_slots) {
62  *                      arc_slots = count;
63  *                      arcs = malloc(sizeof(asn_oid_arc_t) * arc_slots);
64  *                      if(!arcs) return;
65  *                      count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots);
66  *                      assert(count == arc_slots);
67  *              }
68  *
69  *              // Print the contents of the arcs array.
70  *              for(i = 0; i < count; i++)
71  *                      printf("%"PRIu32"\n", arcs[i]);
72  *
73  *              // Avoid memory leak.
74  *              if(arcs != fixed_arcs) free(arcs);
75  *      }
76  *
77  * RETURN VALUES:
78  * -1/EINVAL:   Invalid arguments (oid is missing)
79  * -1/ERANGE:   One or more arcs have value out of array cell type range.
80  * >=0:         Number of arcs contained in the OBJECT IDENTIFIER
81  *
82  * WARNING: The function always returns the actual number of arcs,
83  * even if there is no sufficient (arc_slots) provided.
84  */
85 ssize_t OBJECT_IDENTIFIER_get_arcs(const OBJECT_IDENTIFIER_t *oid,
86                                    asn_oid_arc_t *arcs, size_t arc_slots);
87
88 /*
89  * This functions initializes the OBJECT IDENTIFIER object with
90  * the given set of arcs.
91  * The minimum of two arcs must be present; some restrictions apply.
92  * RETURN VALUES:
93  * -1/EINVAL:   Invalid arguments
94  * -1/ERANGE:   The first two arcs do not conform to ASN.1 restrictions.
95  * -1/ENOMEM:   Memory allocation failed
96  * 0:           The object was initialized with new arcs.
97  */
98 int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *oid,
99                                const asn_oid_arc_t *arcs, size_t arcs_count);
100
101
102 /*
103  * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363").
104  * No arc can exceed the (0..ASN_OID_ARC_MAX, which is the same as UINT32_MAX).
105  * This function is not specific to OBJECT IDENTIFIER, it may be used to parse
106  * the RELATIVE-OID data, or any other data consisting of dot-separated
107  * series of numeric values.
108  *
109  * If (oid_txt_length == -1), the strlen() will be invoked to determine the
110  * size of the (oid_text) string.
111  * 
112  * After return, the optional (opt_oid_text_end) is set to the character after
113  * the last parsed one. (opt_oid_text_end) is never less than (oid_text).
114  * 
115  * RETURN VALUES:
116  *   -1:        Parse error.
117  * >= 0:        Number of arcs contained in the OBJECT IDENTIFIER.
118  * 
119  * WARNING: The function always returns the real number of arcs,
120  * even if there is no sufficient (arc_slots) provided.
121  * This is useful for (arc_slots) value estimation.
122  */
123 ssize_t OBJECT_IDENTIFIER_parse_arcs(const char *oid_text,
124                                      ssize_t oid_txt_length,
125                                      asn_oid_arc_t *arcs, size_t arcs_count,
126                                      const char **opt_oid_text_end);
127
128 /*
129  * Internal functions.
130  * Used by RELATIVE-OID implementation in particular.
131  */
132
133 /*
134  * Retrieve a single arc of size from the (arcbuf) buffer.
135  * RETURN VALUES:
136  *  -1: Failed to retrieve the value from the (arcbuf).
137  *  >0: Number of bytes consumed from the (arcbuf), <= (arcbuf_len).
138  */
139 ssize_t OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf,
140                                          size_t arcbuf_len,
141                                          asn_oid_arc_t *ret_value);
142
143 /*
144  * Write the unterminated arc value into the (arcbuf) which has the size at
145  * least (arcbuf_len).
146  * RETURN VALUES:
147  *   -1: (arcbuf_len) size is not sufficient to write the value.
148  *  <n>: Number of bytes appended to the arcbuf (<= arcbuf_len).
149  */
150 ssize_t OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, size_t arcbuf_len,
151                                          asn_oid_arc_t arc_value);
152
153 #ifdef __cplusplus
154 }
155 #endif
156
157 #endif  /* _OBJECT_IDENTIFIER_H_ */