2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
9 asn_random_fill_result_t
10 BOOLEAN_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
11 const asn_encoding_constraints_t *constraints,
13 asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
14 asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
15 asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
16 BOOLEAN_t *st = *sptr;
18 if(max_length == 0) return result_skipped;
21 st = (BOOLEAN_t *)(*sptr = CALLOC(1, sizeof(*st)));
27 #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
28 if(!constraints || !constraints->per_constraints)
29 constraints = &td->encoding_constraints;
30 if(constraints->per_constraints) {
31 const asn_per_constraint_t *pc = &constraints->per_constraints->value;
32 if(pc->flags & APC_CONSTRAINED) {
33 *st = asn_random_between(pc->lower_bound, pc->upper_bound);
38 if(!constraints) constraints = &td->encoding_constraints;
39 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
41 /* Simulate booleans that are sloppily set and biased. */
42 switch(asn_random_between(0, 7)) {
47 case 3: *st = -1; break;
48 case 4: *st = 1; break;
49 case 5: *st = INT_MIN; break;
50 case 6: *st = INT_MAX; break;
52 *st = asn_random_between(INT_MIN, INT_MAX);