INTEGER_rfill.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
8 
11  const asn_encoding_constraints_t *constraints,
12  size_t max_length) {
13  const asn_INTEGER_specifics_t *specs =
15  asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
16  asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
17  asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
18  INTEGER_t *st = *sptr;
19  const asn_INTEGER_enum_map_t *emap;
20  size_t emap_len;
21  intmax_t value;
22  int find_inside_map;
23 
24  if(max_length == 0) return result_skipped;
25 
26  if(st == NULL) {
27  st = (INTEGER_t *)CALLOC(1, sizeof(*st));
28  if(st == NULL) {
29  return result_failed;
30  }
31  }
32 
33  if(specs) {
34  emap = specs->value2enum;
35  emap_len = specs->map_count;
36  if(specs->strict_enumeration) {
37  find_inside_map = emap_len > 0;
38  } else {
39  find_inside_map = emap_len ? asn_random_between(0, 1) : 0;
40  }
41  } else {
42  emap = 0;
43  emap_len = 0;
44  find_inside_map = 0;
45  }
46 
47  if(find_inside_map) {
48  assert(emap_len > 0);
49  value = emap[asn_random_between(0, emap_len - 1)].nat_value;
50  } else {
51  static const long variants[] = {
52  -65536, -65535, -65534, -32769, -32768, -32767, -16385, -16384,
53  -16383, -257, -256, -255, -254, -129, -128, -127,
54  -126, -1, 0, 1, 126, 127, 128, 129,
55  254, 255, 256, 257, 16383, 16384, 16385, 32767,
56  32768, 32769, 65534, 65535, 65536, 65537};
57  if(specs && specs->field_unsigned) {
58  assert(variants[18] == 0);
59  value = variants[asn_random_between(
60  18, sizeof(variants) / sizeof(variants[0]) - 1)];
61  } else {
62  value = variants[asn_random_between(
63  0, sizeof(variants) / sizeof(variants[0]) - 1)];
64  }
65 
66  if(!constraints) constraints = &td->encoding_constraints;
67 #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
68  const asn_per_constraints_t *ct;
69 
70  ct = constraints ? constraints->per_constraints : 0;
71  if(ct && (ct->value.flags & APC_CONSTRAINED)) {
72  if(value < ct->value.lower_bound || value > ct->value.upper_bound) {
74  ct->value.upper_bound);
75  }
76  }
77 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
78  }
79 
80  if(asn_imax2INTEGER(st, value)) {
81  if(st == *sptr) {
82  ASN_STRUCT_RESET(*td, st);
83  } else {
84  ASN_STRUCT_FREE(*td, st);
85  }
86  return result_failed;
87  } else {
88  *sptr = st;
89  result_ok.length = st->size;
90  return result_ok;
91  }
92 }
ASN_STRUCT_FREE
#define ASN_STRUCT_FREE(asn_DEF, ptr)
Definition: constr_TYPE.h:102
ASN__PRIMITIVE_TYPE_s
Definition: asn_codecs_prim.h:14
ASN__PRIMITIVE_TYPE_s::size
size_t size
Definition: asn_codecs_prim.h:16
asn_per_constraint_s::lower_bound
intmax_t lower_bound
Definition: per_support.h:27
CALLOC
#define CALLOC(nmemb, size)
Definition: asn_internal.h:37
asn_per_constraints_s::value
asn_per_constraint_t value
Definition: per_support.h:31
ASN_STRUCT_RESET
#define ASN_STRUCT_RESET(asn_DEF, ptr)
Definition: constr_TYPE.h:112
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
asn_random_fill_result_s
Definition: asn_random_fill.h:24
asn_TYPE_descriptor_s::specifics
const void * specifics
Definition: constr_TYPE.h:259
asn_imax2INTEGER
int asn_imax2INTEGER(INTEGER_t *i, intmax_t l)
Definition: INTEGER.c:329
asn_random_between
intmax_t asn_random_between(intmax_t min, intmax_t max)
Definition: asn_random_fill.c:38
asn_INTEGER_specifics_s
Definition: INTEGER.h:28
asn_INTEGER_enum_map_s::nat_value
long nat_value
Definition: INTEGER.h:22
INTEGER.h
asn_encoding_constraints_s
Definition: constr_TYPE.h:208
INTEGER_random_fill
asn_random_fill_result_t INTEGER_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, const asn_encoding_constraints_t *constraints, size_t max_length)
Definition: INTEGER_rfill.c:10
asn_internal.h
asn_per_constraints_s
Definition: per_support.h:30
asn_per_constraint_s::upper_bound
intmax_t upper_bound
Definition: per_support.h:28
asn_per_constraint_s::flags
enum asn_per_constraint_s::asn_per_constraint_flags flags
asn_INTEGER_enum_map_s
Definition: INTEGER.h:21


etsi_its_cam_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:21:23