blob: 73362853bc67091c475e7e33535128fd73710f93 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin2c34aad2005-03-10 11:50:24 +00002 * Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>.
3 * All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00004 * Redistribution and modifications are permitted subject to BSD license.
5 */
6#ifndef _OBJECT_IDENTIFIER_H_
7#define _OBJECT_IDENTIFIER_H_
8
Lev Walkin8e8078a2004-09-26 13:10:40 +00009#include <asn_application.h>
Lev Walkin3256d6f2004-10-21 11:22:12 +000010#include <asn_codecs_prim.h>
Bi-Ruei, Chiue1bf2192017-08-19 00:55:25 +080011#include <OCTET_STRING.h>
Lev Walkinf15320b2004-06-03 03:38:44 +000012
Lev Walkin21b41ac2005-07-24 09:03:44 +000013#ifdef __cplusplus
14extern "C" {
15#endif
16
Lev Walkin588bf0f2017-10-13 23:51:16 -070017typedef uint32_t asn_oid_arc_t;
18#define ASN_OID_ARC_MAX (~((asn_oid_arc_t)0))
19
Lev Walkin8e8078a2004-09-26 13:10:40 +000020typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t;
Lev Walkinf15320b2004-06-03 03:38:44 +000021
Lev Walkin5e033762004-09-29 13:26:15 +000022extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER;
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080023extern asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER;
Lev Walkinf15320b2004-06-03 03:38:44 +000024
Lev Walkinf15320b2004-06-03 03:38:44 +000025asn_struct_print_f OBJECT_IDENTIFIER_print;
Lev Walkina9cc46e2004-09-22 16:06:28 +000026asn_constr_check_f OBJECT_IDENTIFIER_constraint;
27der_type_encoder_f OBJECT_IDENTIFIER_encode_der;
Lev Walkin92302252004-10-23 10:16:51 +000028xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer;
Lev Walkina9cc46e2004-09-22 16:06:28 +000029xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer;
Lev Walkina5972be2017-09-29 23:15:58 -070030asn_random_fill_f OBJECT_IDENTIFIER_random_fill;
Lev Walkinf15320b2004-06-03 03:38:44 +000031
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080032#define OBJECT_IDENTIFIER_free ASN__PRIMITIVE_TYPE_free
Bi-Ruei, Chiue1bf2192017-08-19 00:55:25 +080033#define OBJECT_IDENTIFIER_compare OCTET_STRING_compare
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080034#define OBJECT_IDENTIFIER_decode_ber ber_decode_primitive
35#define OBJECT_IDENTIFIER_encode_der der_encode_primitive
Lev Walkinb5b524b2017-10-13 03:14:03 -070036#define OBJECT_IDENTIFIER_decode_oer oer_decode_primitive
37#define OBJECT_IDENTIFIER_encode_oer oer_encode_primitive
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080038#define OBJECT_IDENTIFIER_decode_uper OCTET_STRING_decode_uper
39#define OBJECT_IDENTIFIER_encode_uper OCTET_STRING_encode_uper
40
Lev Walkinf15320b2004-06-03 03:38:44 +000041/**********************************
42 * Some handy conversion routines *
43 **********************************/
44
45/*
Lev Walkin588bf0f2017-10-13 23:51:16 -070046 * This function fills an (arcs) array with OBJECT IDENTIFIER arcs
47 * up to specified (arc_slots) elements.
48 *
Lev Walkinf15320b2004-06-03 03:38:44 +000049 * EXAMPLE:
50 * void print_arcs(OBJECT_IDENTIFIER_t *oid) {
Lev Walkin588bf0f2017-10-13 23:51:16 -070051 * asn_oid_arc_t fixed_arcs[10]; // Try with fixed space first
52 * asn_oid_arc_t *arcs = fixed_arcs;
53 * size_t arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10
54 * ssize_t count; // Real number of arcs.
Lev Walkinf15320b2004-06-03 03:38:44 +000055 * int i;
Lev Walkin588bf0f2017-10-13 23:51:16 -070056 *
57 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000058 * // If necessary, reallocate arcs array and try again.
Lev Walkin29a044b2004-06-14 07:24:36 +000059 * if(count > arc_slots) {
60 * arc_slots = count;
Lev Walkin588bf0f2017-10-13 23:51:16 -070061 * arcs = malloc(sizeof(asn_oid_arc_t) * arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000062 * if(!arcs) return;
Lev Walkin588bf0f2017-10-13 23:51:16 -070063 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots);
Lev Walkin29a044b2004-06-14 07:24:36 +000064 * assert(count == arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000065 * }
Lev Walkin588bf0f2017-10-13 23:51:16 -070066 *
Lev Walkinf15320b2004-06-03 03:38:44 +000067 * // Print the contents of the arcs array.
68 * for(i = 0; i < count; i++)
Lev Walkin588bf0f2017-10-13 23:51:16 -070069 * printf("%"PRIu32"\n", arcs[i]);
70 *
Lev Walkinf15320b2004-06-03 03:38:44 +000071 * // Avoid memory leak.
72 * if(arcs != fixed_arcs) free(arcs);
73 * }
Lev Walkin588bf0f2017-10-13 23:51:16 -070074 *
Lev Walkinf15320b2004-06-03 03:38:44 +000075 * RETURN VALUES:
76 * -1/EINVAL: Invalid arguments (oid is missing)
77 * -1/ERANGE: One or more arcs have value out of array cell type range.
78 * >=0: Number of arcs contained in the OBJECT IDENTIFIER
Lev Walkin588bf0f2017-10-13 23:51:16 -070079 *
80 * WARNING: The function always returns the actual number of arcs,
81 * even if there is no sufficient (arc_slots) provided.
Lev Walkinf15320b2004-06-03 03:38:44 +000082 */
Lev Walkin588bf0f2017-10-13 23:51:16 -070083ssize_t OBJECT_IDENTIFIER_get_arcs(const OBJECT_IDENTIFIER_t *oid,
84 asn_oid_arc_t *arcs, size_t arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000085
86/*
87 * This functions initializes the OBJECT IDENTIFIER object with
88 * the given set of arcs.
89 * The minimum of two arcs must be present; some restrictions apply.
90 * RETURN VALUES:
91 * -1/EINVAL: Invalid arguments
92 * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions.
93 * -1/ENOMEM: Memory allocation failed
94 * 0: The object was initialized with new arcs.
95 */
Lev Walkin588bf0f2017-10-13 23:51:16 -070096int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *oid,
97 const asn_oid_arc_t *arcs, size_t arcs_count);
Lev Walkinf15320b2004-06-03 03:38:44 +000098
Lev Walkin92302252004-10-23 10:16:51 +000099
100/*
101 * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363").
Lev Walkin588bf0f2017-10-13 23:51:16 -0700102 * No arc can exceed the (0..ASN_OID_ARC_MAX, which is the same as UINT32_MAX).
Lev Walkin92302252004-10-23 10:16:51 +0000103 * This function is not specific to OBJECT IDENTIFIER, it may be used to parse
104 * the RELATIVE-OID data, or any other data consisting of dot-separated
105 * series of numeric values.
106 *
107 * If (oid_txt_length == -1), the strlen() will be invoked to determine the
108 * size of the (oid_text) string.
109 *
Lev Walkin093ba2e2005-04-04 21:10:06 +0000110 * After return, the optional (opt_oid_text_end) is set to the character after
111 * the last parsed one. (opt_oid_text_end) is never less than (oid_text).
Lev Walkin92302252004-10-23 10:16:51 +0000112 *
113 * RETURN VALUES:
114 * -1: Parse error.
115 * >= 0: Number of arcs contained in the OBJECT IDENTIFIER.
116 *
117 * WARNING: The function always returns the real number of arcs,
Lev Walkin588bf0f2017-10-13 23:51:16 -0700118 * even if there is no sufficient (arc_slots) provided.
119 * This is useful for (arc_slots) value estimation.
Lev Walkin92302252004-10-23 10:16:51 +0000120 */
Lev Walkin588bf0f2017-10-13 23:51:16 -0700121ssize_t OBJECT_IDENTIFIER_parse_arcs(const char *oid_text,
122 ssize_t oid_txt_length,
123 asn_oid_arc_t *arcs, size_t arcs_count,
124 const char **opt_oid_text_end);
Lev Walkin92302252004-10-23 10:16:51 +0000125
126/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000127 * Internal functions.
Lev Walkin0787ff02004-06-17 23:43:39 +0000128 * Used by RELATIVE-OID implementation in particular.
Lev Walkinf15320b2004-06-03 03:38:44 +0000129 */
Lev Walkin588bf0f2017-10-13 23:51:16 -0700130
131/*
132 * Retrieve a single arc of size from the (arcbuf) buffer.
133 * RETURN VALUES:
134 * -1: Failed to retrieve the value from the (arcbuf).
135 * >0: Number of bytes consumed from the (arcbuf), <= (arcbuf_len).
136 */
137ssize_t OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf,
138 size_t arcbuf_len,
139 asn_oid_arc_t *ret_value);
140
141/*
142 * Write the unterminated arc value into the (arcbuf) which has the size at
143 * least (arcbuf_len).
144 * RETURN VALUES:
145 * -1: (arcbuf_len) size is not sufficient to write the value.
146 * <n>: Number of bytes appended to the arcbuf (<= arcbuf_len).
147 */
148ssize_t OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, size_t arcbuf_len,
149 asn_oid_arc_t arc_value);
Lev Walkinf15320b2004-06-03 03:38:44 +0000150
Lev Walkin21b41ac2005-07-24 09:03:44 +0000151#ifdef __cplusplus
152}
153#endif
154
Lev Walkinf15320b2004-06-03 03:38:44 +0000155#endif /* _OBJECT_IDENTIFIER_H_ */