64bd0ceaf8008ddcc5c9f2eb24c1efc760e30bf9
[ric-plt/resource-status-manager.git] / RSM / asn1codec / e2ap_engine / asn_random_fill.h
1
2 /*
3  * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #ifndef ASN_RANDOM_FILL
7 #define ASN_RANDOM_FILL
8
9 /* Forward declarations */
10 struct asn_TYPE_descriptor_s;
11 struct asn_encoding_constraints_s;
12
13 /*
14  * Initialize a structure with random data according to the type specification
15  * and optional member constraints.
16  * ARGUMENTS:
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.
24  */
25 typedef struct asn_random_fill_result_s {
26     enum {
27         ARFILL_FAILED = -1, /* System error (memory?) */
28         ARFILL_OK = 0,      /* Initialization succeeded */
29         ARFILL_SKIPPED = 1  /* Not done due to (length?) constraint */
30     } code;
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,
36     size_t max_length);
37
38 /*
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.
43  */
44 int asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr,
45                     size_t approx_max_length_limit);
46
47 /*
48  * Returns a random number between min and max.
49  */
50 intmax_t asn_random_between(intmax_t min, intmax_t max);
51
52 #endif  /* ASN_RANDOM_FILL */