Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | a5972be | 2017-09-29 23:15:58 -0700 | [diff] [blame] | 2 | * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. |
Lev Walkin | 2c34aad | 2005-03-10 11:50:24 +0000 | [diff] [blame] | 3 | * All rights reserved. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 4 | * Redistribution and modifications are permitted subject to BSD license. |
| 5 | */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 6 | #include <asn_internal.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 7 | #include <RELATIVE-OID.h> |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 8 | #include <OCTET_STRING.h> |
Lev Walkin | 3256d6f | 2004-10-21 11:22:12 +0000 | [diff] [blame] | 9 | #include <asn_codecs_prim.h> /* Encoder and decoder of a primitive type */ |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 10 | #include <limits.h> /* for CHAR_BIT */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 11 | #include <errno.h> |
| 12 | |
| 13 | /* |
| 14 | * RELATIVE-OID basic type description. |
| 15 | */ |
Wim Lewis | 18c2ec9 | 2014-07-29 11:30:10 -0700 | [diff] [blame] | 16 | static const ber_tlv_tag_t asn_DEF_RELATIVE_OID_tags[] = { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | (ASN_TAG_CLASS_UNIVERSAL | (13 << 2)) |
| 18 | }; |
Bi-Ruei, Chiu | 1f87ac0 | 2017-08-20 01:25:45 +0800 | [diff] [blame] | 19 | asn_TYPE_operation_t asn_OP_RELATIVE_OID = { |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 20 | ASN__PRIMITIVE_TYPE_free, |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 21 | RELATIVE_OID_print, |
Lev Walkin | cd2f48e | 2017-08-10 02:14:59 -0700 | [diff] [blame] | 22 | OCTET_STRING_compare, /* Implemented in terms of opaque comparison */ |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 23 | ber_decode_primitive, |
| 24 | der_encode_primitive, |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 25 | RELATIVE_OID_decode_xer, |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 26 | RELATIVE_OID_encode_xer, |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 27 | #ifdef ASN_DISABLE_OER_SUPPORT |
| 28 | 0, |
| 29 | 0, |
| 30 | #else |
| 31 | 0, |
| 32 | 0, |
| 33 | #endif /* ASN_DISABLE_OER_SUPPORT */ |
Lev Walkin | b33425f | 2017-07-14 14:59:52 +0400 | [diff] [blame] | 34 | #ifdef ASN_DISABLE_PER_SUPPORT |
| 35 | 0, |
| 36 | 0, |
| 37 | #else |
| 38 | OCTET_STRING_decode_uper, |
| 39 | OCTET_STRING_encode_uper, |
| 40 | #endif /* ASN_DISABLE_PER_SUPPORT */ |
Lev Walkin | a5972be | 2017-09-29 23:15:58 -0700 | [diff] [blame] | 41 | RELATIVE_OID_random_fill, |
Bi-Ruei, Chiu | 1f87ac0 | 2017-08-20 01:25:45 +0800 | [diff] [blame] | 42 | 0 /* Use generic outmost tag fetcher */ |
| 43 | }; |
| 44 | asn_TYPE_descriptor_t asn_DEF_RELATIVE_OID = { |
| 45 | "RELATIVE-OID", |
| 46 | "RELATIVE_OID", |
| 47 | &asn_OP_RELATIVE_OID, |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 48 | asn_DEF_RELATIVE_OID_tags, |
| 49 | sizeof(asn_DEF_RELATIVE_OID_tags) |
| 50 | / sizeof(asn_DEF_RELATIVE_OID_tags[0]), |
| 51 | asn_DEF_RELATIVE_OID_tags, /* Same as above */ |
| 52 | sizeof(asn_DEF_RELATIVE_OID_tags) |
| 53 | / sizeof(asn_DEF_RELATIVE_OID_tags[0]), |
Lev Walkin | a5972be | 2017-09-29 23:15:58 -0700 | [diff] [blame] | 54 | { 0, 0, asn_generic_no_constraint }, |
Lev Walkin | 449f832 | 2004-08-20 13:23:42 +0000 | [diff] [blame] | 55 | 0, 0, /* No members */ |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 56 | 0 /* No specifics */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 59 | static ssize_t |
| 60 | RELATIVE_OID__dump_body(const RELATIVE_OID_t *st, asn_app_consume_bytes_f *cb, void *app_key) { |
| 61 | ssize_t wrote = 0; |
| 62 | ssize_t ret; |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 63 | size_t startn; |
| 64 | size_t i; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 65 | |
| 66 | for(i = 0, startn = 0; i < st->size; i++) { |
| 67 | uint8_t b = st->buf[i]; |
| 68 | if((b & 0x80)) /* Continuation expected */ |
| 69 | continue; |
| 70 | if(startn) { |
| 71 | /* Separate arcs */ |
| 72 | if(cb(".", 1, app_key) < 0) |
| 73 | return -1; |
| 74 | wrote++; |
| 75 | } |
| 76 | |
| 77 | ret = OBJECT_IDENTIFIER__dump_arc(&st->buf[startn], |
| 78 | i - startn + 1, 0, cb, app_key); |
| 79 | if(ret < 0) return -1; |
| 80 | wrote += ret; |
| 81 | |
| 82 | startn = i + 1; |
| 83 | } |
| 84 | |
| 85 | return wrote; |
| 86 | } |
| 87 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 88 | int |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 89 | RELATIVE_OID_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 90 | asn_app_consume_bytes_f *cb, void *app_key) { |
Lev Walkin | c234657 | 2004-08-11 09:07:36 +0000 | [diff] [blame] | 91 | const RELATIVE_OID_t *st = (const RELATIVE_OID_t *)sptr; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 92 | |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 93 | (void)td; /* Unused argument */ |
| 94 | (void)ilevel; /* Unused argument */ |
| 95 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 96 | if(!st || !st->buf) |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 97 | return (cb("<absent>", 8, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 98 | |
| 99 | /* Dump preamble */ |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 100 | if(cb("{ ", 2, app_key) < 0) |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 101 | return -1; |
| 102 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 103 | if(RELATIVE_OID__dump_body(st, cb, app_key) < 0) |
| 104 | return -1; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 105 | |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 106 | return (cb(" }", 2, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 109 | static enum xer_pbd_rval |
| 110 | RELATIVE_OID__xer_body_decode(asn_TYPE_descriptor_t *td, void *sptr, const void *chunk_buf, size_t chunk_size) { |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 111 | RELATIVE_OID_t *st = (RELATIVE_OID_t *)sptr; |
Lev Walkin | 2c34aad | 2005-03-10 11:50:24 +0000 | [diff] [blame] | 112 | const char *chunk_end = (const char *)chunk_buf + chunk_size; |
| 113 | const char *endptr; |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 114 | long s_arcs[6]; |
| 115 | long *arcs = s_arcs; |
| 116 | int arcs_count; |
| 117 | int ret; |
| 118 | |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 119 | (void)td; |
| 120 | |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 121 | arcs_count = OBJECT_IDENTIFIER_parse_arcs( |
| 122 | (const char *)chunk_buf, chunk_size, |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 123 | arcs, sizeof(s_arcs)/sizeof(s_arcs[0]), &endptr); |
| 124 | if(arcs_count < 0) { |
Lev Walkin | aed43c8 | 2012-09-04 14:56:27 -0700 | [diff] [blame] | 125 | /* Expecting at least one arc arcs */ |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 126 | return XPBD_BROKEN_ENCODING; |
Lev Walkin | aed43c8 | 2012-09-04 14:56:27 -0700 | [diff] [blame] | 127 | } else if(arcs_count == 0) { |
| 128 | return XPBD_NOT_BODY_IGNORE; |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 129 | } |
Lev Walkin | aed43c8 | 2012-09-04 14:56:27 -0700 | [diff] [blame] | 130 | assert(endptr == chunk_end); |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 131 | |
| 132 | if((size_t)arcs_count > sizeof(s_arcs)/sizeof(s_arcs[0])) { |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 133 | arcs = (long *)MALLOC(arcs_count * sizeof(long)); |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 134 | if(!arcs) return XPBD_SYSTEM_FAILURE; |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 135 | ret = OBJECT_IDENTIFIER_parse_arcs( |
| 136 | (const char *)chunk_buf, chunk_size, |
| 137 | arcs, arcs_count, &endptr); |
| 138 | if(ret != arcs_count) |
Lev Walkin | 0fab1a6 | 2005-03-09 22:19:25 +0000 | [diff] [blame] | 139 | return XPBD_SYSTEM_FAILURE; /* assert?.. */ |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* |
| 143 | * Convert arcs into BER representation. |
| 144 | */ |
| 145 | ret = RELATIVE_OID_set_arcs(st, arcs, sizeof(*arcs), arcs_count); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 146 | if(arcs != s_arcs) FREEMEM(arcs); |
| 147 | |
Lev Walkin | 2c34aad | 2005-03-10 11:50:24 +0000 | [diff] [blame] | 148 | return ret ? XPBD_SYSTEM_FAILURE : XPBD_BODY_CONSUMED; |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | asn_dec_rval_t |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 152 | RELATIVE_OID_decode_xer(const asn_codec_ctx_t *opt_codec_ctx, |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 153 | asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname, |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 154 | const void *buf_ptr, size_t size) { |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 155 | |
| 156 | return xer_decode_primitive(opt_codec_ctx, td, |
| 157 | sptr, sizeof(RELATIVE_OID_t), opt_mname, |
| 158 | buf_ptr, size, RELATIVE_OID__xer_body_decode); |
| 159 | } |
| 160 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 161 | asn_enc_rval_t |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 162 | RELATIVE_OID_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 163 | int ilevel, enum xer_encoder_flags_e flags, |
| 164 | asn_app_consume_bytes_f *cb, void *app_key) { |
| 165 | RELATIVE_OID_t *st = (RELATIVE_OID_t *)sptr; |
| 166 | asn_enc_rval_t er; |
| 167 | |
| 168 | (void)ilevel; /* Unused argument */ |
| 169 | (void)flags; /* Unused argument */ |
| 170 | |
| 171 | if(!st || !st->buf) |
Lev Walkin | 7c1dc05 | 2016-03-14 03:08:15 -0700 | [diff] [blame] | 172 | ASN__ENCODE_FAILED; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 173 | |
| 174 | er.encoded = RELATIVE_OID__dump_body(st, cb, app_key); |
Lev Walkin | 7c1dc05 | 2016-03-14 03:08:15 -0700 | [diff] [blame] | 175 | if(er.encoded < 0) ASN__ENCODE_FAILED; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 176 | |
Lev Walkin | 7c1dc05 | 2016-03-14 03:08:15 -0700 | [diff] [blame] | 177 | ASN__ENCODED_OK(er); |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 178 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 179 | |
| 180 | int |
Wim Lewis | 14e6b16 | 2014-07-23 16:06:01 -0700 | [diff] [blame] | 181 | RELATIVE_OID_get_arcs(const RELATIVE_OID_t *roid, |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 182 | void *arcs, unsigned int arc_type_size, unsigned int arc_slots) { |
Lev Walkin | 4d9528c | 2004-08-11 08:10:13 +0000 | [diff] [blame] | 183 | void *arcs_end = (char *)arcs + (arc_slots * arc_type_size); |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 184 | int num_arcs = 0; |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 185 | size_t startn = 0; |
| 186 | size_t i; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 187 | |
| 188 | if(!roid || !roid->buf) { |
| 189 | errno = EINVAL; |
| 190 | return -1; |
| 191 | } |
| 192 | |
| 193 | for(i = 0; i < roid->size; i++) { |
| 194 | uint8_t b = roid->buf[i]; |
| 195 | if((b & 0x80)) /* Continuation expected */ |
| 196 | continue; |
| 197 | |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 198 | if(arcs < arcs_end) { |
| 199 | if(OBJECT_IDENTIFIER_get_single_arc( |
| 200 | &roid->buf[startn], |
| 201 | i - startn + 1, 0, |
| 202 | arcs, arc_type_size)) |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 203 | return -1; |
Lev Walkin | 4ce78ca | 2004-08-25 01:34:11 +0000 | [diff] [blame] | 204 | arcs = ((char *)arcs) + arc_type_size; |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 205 | num_arcs++; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | startn = i + 1; |
| 209 | } |
| 210 | |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 211 | return num_arcs; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | int |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 215 | RELATIVE_OID_set_arcs(RELATIVE_OID_t *roid, void *arcs, unsigned int arc_type_size, unsigned int arcs_slots) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 216 | uint8_t *buf; |
| 217 | uint8_t *bp; |
Lev Walkin | 34b2a93 | 2004-06-17 23:46:45 +0000 | [diff] [blame] | 218 | unsigned int size; |
| 219 | unsigned int i; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 220 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 221 | if(roid == NULL || arcs == NULL || arc_type_size < 1) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 222 | errno = EINVAL; |
| 223 | return -1; |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * Roughly estimate the maximum size necessary to encode these arcs. |
| 228 | */ |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 229 | size = ((arc_type_size * CHAR_BIT + 6) / 7) * arcs_slots; |
Lev Walkin | c234657 | 2004-08-11 09:07:36 +0000 | [diff] [blame] | 230 | bp = buf = (uint8_t *)MALLOC(size + 1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 231 | if(!buf) { |
| 232 | /* ENOMEM */ |
| 233 | return -1; |
| 234 | } |
| 235 | |
| 236 | /* |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 237 | * Encode the arcs. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 238 | */ |
Lev Walkin | 4ce78ca | 2004-08-25 01:34:11 +0000 | [diff] [blame] | 239 | for(i = 0; i < arcs_slots; i++, arcs = ((char *)arcs) + arc_type_size) { |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 240 | bp += OBJECT_IDENTIFIER_set_single_arc(bp, |
| 241 | arcs, arc_type_size, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Lev Walkin | 34b2a93 | 2004-06-17 23:46:45 +0000 | [diff] [blame] | 244 | assert((unsigned)(bp - buf) <= size); |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 245 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 246 | /* |
| 247 | * Replace buffer. |
| 248 | */ |
Lev Walkin | 4efbfb7 | 2005-02-25 14:20:30 +0000 | [diff] [blame] | 249 | roid->size = (int)(bp - buf); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 250 | bp = roid->buf; |
| 251 | roid->buf = buf; |
| 252 | if(bp) FREEMEM(bp); |
| 253 | |
| 254 | return 0; |
| 255 | } |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 256 | |
Lev Walkin | a5972be | 2017-09-29 23:15:58 -0700 | [diff] [blame] | 257 | |
| 258 | /* |
| 259 | * Generate values from the list of interesting values, or just a random value. |
| 260 | */ |
| 261 | static uint32_t |
| 262 | RELATIVE_OID__biased_random_arc() { |
| 263 | static const uint16_t values[] = {0, 1, 127, 128, 129, 254, 255, 256}; |
| 264 | |
| 265 | size_t idx = asn_random_between(0, 2 * sizeof(values)/sizeof(values[0])); |
| 266 | if(idx < sizeof(values) / sizeof(values[0])) { |
| 267 | return values[idx]; |
| 268 | } |
| 269 | |
| 270 | return asn_random_between(0, INT32_MAX); |
| 271 | } |
| 272 | |
| 273 | asn_random_fill_result_t |
| 274 | RELATIVE_OID_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, |
| 275 | const asn_encoding_constraints_t *constraints, |
| 276 | size_t max_length) { |
| 277 | asn_random_fill_result_t result_ok = {ARFILL_OK, 1}; |
| 278 | asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0}; |
| 279 | asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0}; |
| 280 | RELATIVE_OID_t *st; |
| 281 | uint32_t arcs[3]; |
| 282 | size_t arcs_len = asn_random_between(0, 3); |
| 283 | size_t i; |
| 284 | |
| 285 | (void)constraints; |
| 286 | |
| 287 | if(max_length < arcs_len) return result_skipped; |
| 288 | |
| 289 | if(*sptr) { |
| 290 | st = *sptr; |
| 291 | } else { |
| 292 | st = CALLOC(1, sizeof(*st)); |
| 293 | } |
| 294 | |
| 295 | for(i = 0; i < arcs_len; i++) { |
| 296 | arcs[i] = RELATIVE_OID__biased_random_arc(); |
| 297 | } |
| 298 | |
| 299 | if(RELATIVE_OID_set_arcs(st, arcs, sizeof(arcs[0]), arcs_len)) { |
| 300 | if(st != *sptr) { |
| 301 | ASN_STRUCT_FREE(*td, st); |
| 302 | } |
| 303 | return result_failed; |
| 304 | } |
| 305 | |
| 306 | *sptr = st; |
| 307 | |
| 308 | return result_ok; |
| 309 | } |