vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | #ifndef _OBJECT_IDENTIFIER_H_ |
| 6 | #define _OBJECT_IDENTIFIER_H_ |
| 7 | |
| 8 | #include <constr_TYPE.h> |
| 9 | #include <INTEGER.h> |
| 10 | |
| 11 | typedef INTEGER_t OBJECT_IDENTIFIER_t; /* Implemented in terms of INTEGER */ |
| 12 | |
| 13 | extern asn1_TYPE_descriptor_t asn1_DEF_OBJECT_IDENTIFIER; |
| 14 | |
| 15 | der_type_encoder_f OBJECT_IDENTIFIER_encode_der; |
| 16 | asn_constr_check_f OBJECT_IDENTIFIER_constraint; |
| 17 | asn_struct_print_f OBJECT_IDENTIFIER_print; |
| 18 | |
| 19 | /********************************** |
| 20 | * Some handy conversion routines * |
| 21 | **********************************/ |
| 22 | |
| 23 | /* |
| 24 | * Print the specified OBJECT IDENTIFIER arc. |
| 25 | */ |
| 26 | int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, |
| 27 | int add, /* Arbitrary offset, required to process the first two arcs */ |
| 28 | asn_app_consume_bytes_f *cb, void *app_key); |
| 29 | |
| 30 | /* |
| 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 | * The function always returns the real number of arcs, even if there is no |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 34 | * sufficient (_arc_slots) provided. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 35 | * |
| 36 | * EXAMPLE: |
| 37 | * void print_arcs(OBJECT_IDENTIFIER_t *oid) { |
| 38 | * unsigned long fixed_arcs[10]; // Try with fixed space first |
| 39 | * unsigned long *arcs = fixed_arcs; |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 40 | * int arc_type_size = sizeof(fixed_arcs[0]); // sizeof(long) |
| 41 | * int arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10 |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 42 | * int count; // Real number of arcs. |
| 43 | * int i; |
| 44 | * |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 45 | * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, |
| 46 | * arc_type_size, arc_slots); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 47 | * // If necessary, reallocate arcs array and try again. |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 48 | * if(count > arc_slots) { |
| 49 | * arc_slots = count; |
| 50 | * arcs = malloc(arc_type_size * arc_slots); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 51 | * if(!arcs) return; |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 52 | * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, |
| 53 | * arc_type_size, arc_slots); |
| 54 | * assert(count == arc_slots); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 55 | * } |
| 56 | * |
| 57 | * // Print the contents of the arcs array. |
| 58 | * for(i = 0; i < count; i++) |
| 59 | * printf("%d\n", arcs[i]); |
| 60 | * |
| 61 | * // Avoid memory leak. |
| 62 | * if(arcs != fixed_arcs) free(arcs); |
| 63 | * } |
| 64 | * |
| 65 | * RETURN VALUES: |
| 66 | * -1/EINVAL: Invalid arguments (oid is missing) |
| 67 | * -1/ERANGE: One or more arcs have value out of array cell type range. |
| 68 | * >=0: Number of arcs contained in the OBJECT IDENTIFIER |
| 69 | */ |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 70 | int OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *_oid, |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 71 | void *_arcs, /* i.e., unsigned int arcs[N] */ |
| 72 | unsigned int _arc_type_size, /* i.e., sizeof(arcs[0]) */ |
| 73 | unsigned int _arc_slots /* i.e., N */); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * This functions initializes the OBJECT IDENTIFIER object with |
| 77 | * the given set of arcs. |
| 78 | * The minimum of two arcs must be present; some restrictions apply. |
| 79 | * RETURN VALUES: |
| 80 | * -1/EINVAL: Invalid arguments |
| 81 | * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions. |
| 82 | * -1/ENOMEM: Memory allocation failed |
| 83 | * 0: The object was initialized with new arcs. |
| 84 | */ |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 85 | int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *_oid, |
| 86 | void *_arcs, /* i.e., unsigned int arcs[N] */ |
| 87 | unsigned int _arc_type_size, /* i.e., sizeof(arcs[0]) */ |
| 88 | unsigned int _arc_slots /* i.e., N */); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Internal functions. |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 92 | * Used by RELATIVE-OID implementation in particular. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 93 | */ |
vlm | 2e3dd3b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 94 | int OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, |
| 95 | signed int add, void *value, unsigned int value_size); |
vlm | 1255771 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 96 | int OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, |
| 97 | void *arcval, unsigned int arcval_size, int _prepared_order); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 98 | |
| 99 | #endif /* _OBJECT_IDENTIFIER_H_ */ |