blob: 02dde9c8371adcf3f2221f9080b18e358b98853c [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 Walkin8e8078a2004-09-26 13:10:40 +000017typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t;
Lev Walkinf15320b2004-06-03 03:38:44 +000018
Lev Walkin5e033762004-09-29 13:26:15 +000019extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER;
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080020extern asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER;
Lev Walkinf15320b2004-06-03 03:38:44 +000021
Lev Walkinf15320b2004-06-03 03:38:44 +000022asn_struct_print_f OBJECT_IDENTIFIER_print;
Lev Walkina9cc46e2004-09-22 16:06:28 +000023asn_constr_check_f OBJECT_IDENTIFIER_constraint;
24der_type_encoder_f OBJECT_IDENTIFIER_encode_der;
Lev Walkin92302252004-10-23 10:16:51 +000025xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer;
Lev Walkina9cc46e2004-09-22 16:06:28 +000026xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer;
Lev Walkina5972be2017-09-29 23:15:58 -070027asn_random_fill_f OBJECT_IDENTIFIER_random_fill;
Lev Walkinf15320b2004-06-03 03:38:44 +000028
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080029#define OBJECT_IDENTIFIER_free ASN__PRIMITIVE_TYPE_free
Bi-Ruei, Chiue1bf2192017-08-19 00:55:25 +080030#define OBJECT_IDENTIFIER_compare OCTET_STRING_compare
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080031#define OBJECT_IDENTIFIER_decode_ber ber_decode_primitive
32#define OBJECT_IDENTIFIER_encode_der der_encode_primitive
33#define OBJECT_IDENTIFIER_decode_uper OCTET_STRING_decode_uper
34#define OBJECT_IDENTIFIER_encode_uper OCTET_STRING_encode_uper
35
Lev Walkinf15320b2004-06-03 03:38:44 +000036/**********************************
37 * Some handy conversion routines *
38 **********************************/
39
40/*
Lev Walkinf15320b2004-06-03 03:38:44 +000041 * This function fills an (_arcs) array with OBJECT IDENTIFIER arcs
Lev Walkin29a044b2004-06-14 07:24:36 +000042 * up to specified (_arc_slots) elements.
Lev Walkinf15320b2004-06-03 03:38:44 +000043 *
44 * EXAMPLE:
45 * void print_arcs(OBJECT_IDENTIFIER_t *oid) {
46 * unsigned long fixed_arcs[10]; // Try with fixed space first
47 * unsigned long *arcs = fixed_arcs;
Lev Walkin29a044b2004-06-14 07:24:36 +000048 * int arc_type_size = sizeof(fixed_arcs[0]); // sizeof(long)
49 * int arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10
Lev Walkinf15320b2004-06-03 03:38:44 +000050 * int count; // Real number of arcs.
51 * int i;
52 *
Lev Walkin29a044b2004-06-14 07:24:36 +000053 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
54 * arc_type_size, arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000055 * // If necessary, reallocate arcs array and try again.
Lev Walkin29a044b2004-06-14 07:24:36 +000056 * if(count > arc_slots) {
57 * arc_slots = count;
58 * arcs = malloc(arc_type_size * arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000059 * if(!arcs) return;
Lev Walkin29a044b2004-06-14 07:24:36 +000060 * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs,
61 * arc_type_size, arc_slots);
62 * assert(count == arc_slots);
Lev Walkinf15320b2004-06-03 03:38:44 +000063 * }
64 *
65 * // Print the contents of the arcs array.
66 * for(i = 0; i < count; i++)
67 * printf("%d\n", arcs[i]);
68 *
69 * // Avoid memory leak.
70 * if(arcs != fixed_arcs) free(arcs);
71 * }
72 *
73 * RETURN VALUES:
74 * -1/EINVAL: Invalid arguments (oid is missing)
75 * -1/ERANGE: One or more arcs have value out of array cell type range.
76 * >=0: Number of arcs contained in the OBJECT IDENTIFIER
Lev Walkin92302252004-10-23 10:16:51 +000077 *
78 * WARNING: The function always returns the real number of arcs,
79 * even if there is no sufficient (_arc_slots) provided.
Lev Walkinf15320b2004-06-03 03:38:44 +000080 */
Wim Lewis14e6b162014-07-23 16:06:01 -070081int OBJECT_IDENTIFIER_get_arcs(const OBJECT_IDENTIFIER_t *_oid,
Lev Walkin4a4d06e2006-08-10 22:09:41 +000082 void *_arcs, /* e.g., unsigned int arcs[N] */
83 unsigned int _arc_type_size, /* e.g., sizeof(arcs[0]) */
84 unsigned int _arc_slots /* e.g., N */);
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 Walkin0787ff02004-06-17 23:43:39 +000096int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *_oid,
Lev Walkin4a4d06e2006-08-10 22:09:41 +000097 const void *_arcs, /* e.g., unsigned int arcs[N] */
98 unsigned int _arc_type_size, /* e.g., sizeof(arcs[0]) */
99 unsigned int _arc_slots /* e.g., N */);
Lev Walkinf15320b2004-06-03 03:38:44 +0000100
101/*
Lev Walkin92302252004-10-23 10:16:51 +0000102 * Print the specified OBJECT IDENTIFIER arc.
103 */
Wim Lewis14e6b162014-07-23 16:06:01 -0700104int OBJECT_IDENTIFIER_print_arc(const uint8_t *arcbuf, int arclen,
Lev Walkin92302252004-10-23 10:16:51 +0000105 int add, /* Arbitrary offset, required to process the first two arcs */
106 asn_app_consume_bytes_f *cb, void *app_key);
107
108/* Same as above, but returns the number of written digits, instead of 0 */
Wim Lewis14e6b162014-07-23 16:06:01 -0700109ssize_t OBJECT_IDENTIFIER__dump_arc(const uint8_t *arcbuf, int arclen, int add,
Lev Walkin92302252004-10-23 10:16:51 +0000110 asn_app_consume_bytes_f *cb, void *app_key);
111
112/*
113 * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363").
114 * No arc can exceed the (0..signed_long_max) range (typically, 0..2G if L32).
115 * This function is not specific to OBJECT IDENTIFIER, it may be used to parse
116 * the RELATIVE-OID data, or any other data consisting of dot-separated
117 * series of numeric values.
118 *
119 * If (oid_txt_length == -1), the strlen() will be invoked to determine the
120 * size of the (oid_text) string.
121 *
Lev Walkin093ba2e2005-04-04 21:10:06 +0000122 * After return, the optional (opt_oid_text_end) is set to the character after
123 * the last parsed one. (opt_oid_text_end) is never less than (oid_text).
Lev Walkin92302252004-10-23 10:16:51 +0000124 *
125 * RETURN VALUES:
126 * -1: Parse error.
127 * >= 0: Number of arcs contained in the OBJECT IDENTIFIER.
128 *
129 * WARNING: The function always returns the real number of arcs,
130 * even if there is no sufficient (_arc_slots) provided.
Lev Walkinb9c91022005-03-10 11:32:57 +0000131 * This is useful for (_arc_slots) value estimation.
Lev Walkin92302252004-10-23 10:16:51 +0000132 */
133int OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length,
Lev Walkin093ba2e2005-04-04 21:10:06 +0000134 long arcs[], unsigned int arcs_slots, const char **opt_oid_text_end);
Lev Walkin92302252004-10-23 10:16:51 +0000135
136/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000137 * Internal functions.
Lev Walkin0787ff02004-06-17 23:43:39 +0000138 * Used by RELATIVE-OID implementation in particular.
Lev Walkinf15320b2004-06-03 03:38:44 +0000139 */
Wim Lewis14e6b162014-07-23 16:06:01 -0700140int OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf, unsigned int arclen,
Lev Walkin29a044b2004-06-14 07:24:36 +0000141 signed int add, void *value, unsigned int value_size);
Lev Walkin0787ff02004-06-17 23:43:39 +0000142int OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf,
Lev Walkinb1a15552005-12-22 21:39:44 +0000143 const void *arcval, unsigned int arcval_size, int _prepared_order);
Lev Walkinf15320b2004-06-03 03:38:44 +0000144
Lev Walkin21b41ac2005-07-24 09:03:44 +0000145#ifdef __cplusplus
146}
147#endif
148
Lev Walkinf15320b2004-06-03 03:38:44 +0000149#endif /* _OBJECT_IDENTIFIER_H_ */