3 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #ifndef ASN_RANDOM_FILL
7 #define ASN_RANDOM_FILL
9 /* Forward declarations */
10 struct asn_TYPE_descriptor_s;
11 struct asn_encoding_constraints_s;
14 * Initialize a structure with random data according to the type specification
15 * and optional member constraints.
17 * (max_length) - See (approx_max_length_limit).
18 * (memb_constraints) - Member constraints, if exist.
19 * The type can be constrained differently according
20 * to PER and OER specifications, so we find a value
21 * at the intersection of these constraints.
22 * In case the return differs from ARFILL_OK, the (struct_ptr) contents
23 * and (current_length) value remain in their original state.
25 typedef struct asn_random_fill_result_s {
27 ARFILL_FAILED = -1, /* System error (memory?) */
28 ARFILL_OK = 0, /* Initialization succeeded */
29 ARFILL_SKIPPED = 1 /* Not done due to (length?) constraint */
31 size_t length; /* Approximate number of bytes created. */
32 } asn_random_fill_result_t;
33 typedef asn_random_fill_result_t(asn_random_fill_f)(
34 const struct asn_TYPE_descriptor_s *td, void **struct_ptr,
35 const struct asn_encoding_constraints_s *memb_constraints,
39 * Returns 0 if the structure was properly initialized, -1 otherwise.
40 * The (approx_max_length_limit) specifies the approximate limit of the
41 * resulting structure in units closely resembling bytes. The actual result
42 * might be several times larger or smaller than the length limit.
44 int asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr,
45 size_t approx_max_length_limit);
48 * Returns a random number between min and max.
50 intmax_t asn_random_between(intmax_t min, intmax_t max);
52 #endif /* ASN_RANDOM_FILL */