--- /dev/null
+/*\r
+ * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.\r
+ * Redistribution and modifications are permitted subject to BSD license.\r
+ */\r
+#ifndef _OBJECT_IDENTIFIER_H_\r
+#define _OBJECT_IDENTIFIER_H_\r
+\r
+#include <asn_application.h>\r
+#include <asn_codecs_prim.h>\r
+#include <OCTET_STRING.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef uint32_t asn_oid_arc_t;\r
+#define ASN_OID_ARC_MAX (~((asn_oid_arc_t)0))\r
+\r
+typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t;\r
+\r
+extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER;\r
+extern asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER;\r
+\r
+asn_struct_print_f OBJECT_IDENTIFIER_print;\r
+asn_constr_check_f OBJECT_IDENTIFIER_constraint;\r
+der_type_encoder_f OBJECT_IDENTIFIER_encode_der;\r
+xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer;\r
+xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer;\r
+asn_random_fill_f OBJECT_IDENTIFIER_random_fill;\r
+\r
+#define OBJECT_IDENTIFIER_free ASN__PRIMITIVE_TYPE_free\r
+#define OBJECT_IDENTIFIER_compare OCTET_STRING_compare\r
+#define OBJECT_IDENTIFIER_decode_ber ber_decode_primitive\r
+#define OBJECT_IDENTIFIER_encode_der der_encode_primitive\r
+#define OBJECT_IDENTIFIER_decode_oer oer_decode_primitive\r
+#define OBJECT_IDENTIFIER_encode_oer oer_encode_primitive\r
+#define OBJECT_IDENTIFIER_decode_uper OCTET_STRING_decode_uper\r
+#define OBJECT_IDENTIFIER_encode_uper OCTET_STRING_encode_uper\r
+#define OBJECT_IDENTIFIER_decode_aper OCTET_STRING_decode_aper\r
+#define OBJECT_IDENTIFIER_encode_aper OCTET_STRING_encode_aper\r
+\r
+/**********************************\r
+ * Some handy conversion routines *\r
+ **********************************/\r
+\r
+/*\r
+ * This function fills an (arcs) array with OBJECT IDENTIFIER arcs\r
+ * up to specified (arc_slots) elements.\r
+ *\r
+ * EXAMPLE:\r
+ * void print_arcs(OBJECT_IDENTIFIER_t *oid) {\r
+ * asn_oid_arc_t fixed_arcs[10]; // Try with fixed space first\r
+ * asn_oid_arc_t *arcs = fixed_arcs;\r
+ * size_t arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10\r
+ * ssize_t count; // Real number of arcs.\r
+ * int i;\r
+ *\r
+ * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots);\r
+ * // If necessary, reallocate arcs array and try again.\r
+ * if(count > arc_slots) {\r
+ * arc_slots = count;\r
+ * arcs = malloc(sizeof(asn_oid_arc_t) * arc_slots);\r
+ * if(!arcs) return;\r
+ * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots);\r
+ * assert(count == arc_slots);\r
+ * }\r
+ *\r
+ * // Print the contents of the arcs array.\r
+ * for(i = 0; i < count; i++)\r
+ * printf("%"PRIu32"\n", arcs[i]);\r
+ *\r
+ * // Avoid memory leak.\r
+ * if(arcs != fixed_arcs) free(arcs);\r
+ * }\r
+ *\r
+ * RETURN VALUES:\r
+ * -1/EINVAL: Invalid arguments (oid is missing)\r
+ * -1/ERANGE: One or more arcs have value out of array cell type range.\r
+ * >=0: Number of arcs contained in the OBJECT IDENTIFIER\r
+ *\r
+ * WARNING: The function always returns the actual number of arcs,\r
+ * even if there is no sufficient (arc_slots) provided.\r
+ */\r
+ssize_t OBJECT_IDENTIFIER_get_arcs(const OBJECT_IDENTIFIER_t *oid,\r
+ asn_oid_arc_t *arcs, size_t arc_slots);\r
+\r
+/*\r
+ * This functions initializes the OBJECT IDENTIFIER object with\r
+ * the given set of arcs.\r
+ * The minimum of two arcs must be present; some restrictions apply.\r
+ * RETURN VALUES:\r
+ * -1/EINVAL: Invalid arguments\r
+ * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions.\r
+ * -1/ENOMEM: Memory allocation failed\r
+ * 0: The object was initialized with new arcs.\r
+ */\r
+int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *oid,\r
+ const asn_oid_arc_t *arcs, size_t arcs_count);\r
+\r
+\r
+/*\r
+ * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363").\r
+ * No arc can exceed the (0..ASN_OID_ARC_MAX, which is the same as UINT32_MAX).\r
+ * This function is not specific to OBJECT IDENTIFIER, it may be used to parse\r
+ * the RELATIVE-OID data, or any other data consisting of dot-separated\r
+ * series of numeric values.\r
+ *\r
+ * If (oid_txt_length == -1), the strlen() will be invoked to determine the\r
+ * size of the (oid_text) string.\r
+ * \r
+ * After return, the optional (opt_oid_text_end) is set to the character after\r
+ * the last parsed one. (opt_oid_text_end) is never less than (oid_text).\r
+ * \r
+ * RETURN VALUES:\r
+ * -1: Parse error.\r
+ * >= 0: Number of arcs contained in the OBJECT IDENTIFIER.\r
+ * \r
+ * WARNING: The function always returns the real number of arcs,\r
+ * even if there is no sufficient (arc_slots) provided.\r
+ * This is useful for (arc_slots) value estimation.\r
+ */\r
+ssize_t OBJECT_IDENTIFIER_parse_arcs(const char *oid_text,\r
+ ssize_t oid_txt_length,\r
+ asn_oid_arc_t *arcs, size_t arcs_count,\r
+ const char **opt_oid_text_end);\r
+\r
+/*\r
+ * Internal functions.\r
+ * Used by RELATIVE-OID implementation in particular.\r
+ */\r
+\r
+/*\r
+ * Retrieve a single arc of size from the (arcbuf) buffer.\r
+ * RETURN VALUES:\r
+ * -1: Failed to retrieve the value from the (arcbuf).\r
+ * >0: Number of bytes consumed from the (arcbuf), <= (arcbuf_len).\r
+ */\r
+ssize_t OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf,\r
+ size_t arcbuf_len,\r
+ asn_oid_arc_t *ret_value);\r
+\r
+/*\r
+ * Write the unterminated arc value into the (arcbuf) which has the size at\r
+ * least (arcbuf_len).\r
+ * RETURN VALUES:\r
+ * -1: (arcbuf_len) size is not sufficient to write the value.\r
+ * <n>: Number of bytes appended to the arcbuf (<= arcbuf_len).\r
+ */\r
+ssize_t OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, size_t arcbuf_len,\r
+ asn_oid_arc_t arc_value);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* _OBJECT_IDENTIFIER_H_ */\r