vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
vlm | 31feaf3 | 2005-03-10 11:50:24 +0000 | [diff] [blame] | 2 | * Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>. |
| 3 | * All rights reserved. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 4 | * Redistribution and modifications are permitted subject to BSD license. |
| 5 | */ |
| 6 | #ifndef _OBJECT_IDENTIFIER_H_ |
| 7 | #define _OBJECT_IDENTIFIER_H_ |
| 8 | |
vlm | 6678cb1 | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 9 | #include <asn_application.h> |
vlm | 3b6e112 | 2004-10-21 11:22:12 +0000 | [diff] [blame] | 10 | #include <asn_codecs_prim.h> |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 11 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 12 | #ifdef __cplusplus |
| 13 | extern "C" { |
| 14 | #endif |
| 15 | |
vlm | 6678cb1 | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 16 | typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 18 | extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 19 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | asn_struct_print_f OBJECT_IDENTIFIER_print; |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 21 | asn_constr_check_f OBJECT_IDENTIFIER_constraint; |
| 22 | der_type_encoder_f OBJECT_IDENTIFIER_encode_der; |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 23 | xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer; |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 24 | xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 25 | |
| 26 | /********************************** |
| 27 | * Some handy conversion routines * |
| 28 | **********************************/ |
| 29 | |
| 30 | /* |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | * This function fills an (_arcs) array with OBJECT IDENTIFIER arcs |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 32 | * up to specified (_arc_slots) elements. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 33 | * |
| 34 | * EXAMPLE: |
| 35 | * void print_arcs(OBJECT_IDENTIFIER_t *oid) { |
| 36 | * unsigned long fixed_arcs[10]; // Try with fixed space first |
| 37 | * unsigned long *arcs = fixed_arcs; |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 38 | * int arc_type_size = sizeof(fixed_arcs[0]); // sizeof(long) |
| 39 | * int arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10 |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 40 | * int count; // Real number of arcs. |
| 41 | * int i; |
| 42 | * |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 43 | * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, |
| 44 | * arc_type_size, arc_slots); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 45 | * // If necessary, reallocate arcs array and try again. |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 46 | * if(count > arc_slots) { |
| 47 | * arc_slots = count; |
| 48 | * arcs = malloc(arc_type_size * arc_slots); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 49 | * if(!arcs) return; |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 50 | * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, |
| 51 | * arc_type_size, arc_slots); |
| 52 | * assert(count == arc_slots); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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 |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 67 | * |
| 68 | * WARNING: The function always returns the real number of arcs, |
| 69 | * even if there is no sufficient (_arc_slots) provided. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 70 | */ |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 71 | int OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *_oid, |
vlm | fe39ae9 | 2006-08-10 22:09:41 +0000 | [diff] [blame] | 72 | void *_arcs, /* e.g., unsigned int arcs[N] */ |
| 73 | unsigned int _arc_type_size, /* e.g., sizeof(arcs[0]) */ |
| 74 | unsigned int _arc_slots /* e.g., N */); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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 | */ |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 86 | int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *_oid, |
vlm | fe39ae9 | 2006-08-10 22:09:41 +0000 | [diff] [blame] | 87 | const void *_arcs, /* e.g., unsigned int arcs[N] */ |
| 88 | unsigned int _arc_type_size, /* e.g., sizeof(arcs[0]) */ |
| 89 | unsigned int _arc_slots /* e.g., N */); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 90 | |
| 91 | /* |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 92 | * Print the specified OBJECT IDENTIFIER arc. |
| 93 | */ |
| 94 | int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, |
| 95 | int add, /* Arbitrary offset, required to process the first two arcs */ |
| 96 | asn_app_consume_bytes_f *cb, void *app_key); |
| 97 | |
| 98 | /* Same as above, but returns the number of written digits, instead of 0 */ |
| 99 | ssize_t OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add, |
| 100 | asn_app_consume_bytes_f *cb, void *app_key); |
| 101 | |
| 102 | /* |
| 103 | * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363"). |
| 104 | * No arc can exceed the (0..signed_long_max) range (typically, 0..2G if L32). |
| 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 | * |
vlm | 70034ce | 2005-04-04 21:10:06 +0000 | [diff] [blame] | 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). |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 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. |
vlm | 0282046 | 2005-03-10 11:32:57 +0000 | [diff] [blame] | 121 | * This is useful for (_arc_slots) value estimation. |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 122 | */ |
| 123 | int OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length, |
vlm | 70034ce | 2005-04-04 21:10:06 +0000 | [diff] [blame] | 124 | long arcs[], unsigned int arcs_slots, const char **opt_oid_text_end); |
vlm | 1f73df2 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 125 | |
| 126 | /* |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 127 | * Internal functions. |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 128 | * Used by RELATIVE-OID implementation in particular. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 129 | */ |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 130 | int OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, |
| 131 | signed int add, void *value, unsigned int value_size); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 132 | int OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, |
vlm | adae77b | 2005-12-22 21:39:44 +0000 | [diff] [blame] | 133 | const void *arcval, unsigned int arcval_size, int _prepared_order); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 134 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 135 | #ifdef __cplusplus |
| 136 | } |
| 137 | #endif |
| 138 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 139 | #endif /* _OBJECT_IDENTIFIER_H_ */ |