1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
5 # Licensed under the Apache License, Version 2.0 (the "License"); *
6 # you may not use this file except in compliance with the License. *
7 # You may obtain a copy of the License at *
9 # http://www.apache.org/licenses/LICENSE-2.0 *
11 # Unless required by applicable law or agreed to in writing, software *
12 # distributed under the License is distributed on an "AS IS" BASIS, *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 # See the License for the specific language governing permissions and *
15 # limitations under the License. *
17 ******************************************************************************/
20 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
23 #ifndef ASN_RANDOM_FILL
24 #define ASN_RANDOM_FILL
26 /* Forward declarations */
27 struct asn_TYPE_descriptor_s;
28 struct asn_encoding_constraints_s;
31 * Initialize a structure with random data according to the type specification
32 * and optional member constraints.
34 * (max_length) - See (approx_max_length_limit).
35 * (memb_constraints) - Member constraints, if exist.
36 * The type can be constrained differently according
37 * to PER and OER specifications, so we find a value
38 * at the intersection of these constraints.
39 * In case the return differs from ARFILL_OK, the (struct_ptr) contents
40 * and (current_length) value remain in their original state.
42 typedef struct asn_random_fill_result_s {
44 ARFILL_FAILED = -1, /* System error (memory?) */
45 ARFILL_OK = 0, /* Initialization succeeded */
46 ARFILL_SKIPPED = 1 /* Not done due to (length?) constraint */
48 size_t length; /* Approximate number of bytes created. */
49 } asn_random_fill_result_t;
50 typedef asn_random_fill_result_t(asn_random_fill_f)(
51 const struct asn_TYPE_descriptor_s *td, void **struct_ptr,
52 const struct asn_encoding_constraints_s *memb_constraints,
56 * Returns 0 if the structure was properly initialized, -1 otherwise.
57 * The (approx_max_length_limit) specifies the approximate limit of the
58 * resulting structure in units closely resembling bytes. The actual result
59 * might be several times larger or smaller than the length limit.
61 int asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr,
62 size_t approx_max_length_limit);
65 * Returns a random number between min and max.
67 intmax_t asn_random_between(intmax_t min, intmax_t max);
69 #endif /* ASN_RANDOM_FILL */