blob: 1896392b5e6c123b896b3b9a89984086961e6395 [file] [log] [blame]
Lev Walkinb45e0672004-08-18 05:42:05 +00001#ifndef ASN1FIX_CRANGE_H
2#define ASN1FIX_CRANGE_H
3
4typedef struct asn1cnst_edge_s {
5 enum asn1cnst_range_edge {
6 ARE_MIN,
7 ARE_MAX,
8 ARE_VALUE,
9 } type;
10 int lineno; /* Line where the corresponding token was found */
Lev Walkinb8108ec2004-09-29 13:17:17 +000011 asn1c_integer_t value; /* Value when type is ARE_VALUE */
Lev Walkinb45e0672004-08-18 05:42:05 +000012} asn1cnst_edge_t;
13
14typedef struct asn1cnst_range_s {
15 asn1cnst_edge_t left; /* MIN from (MIN..10) */
16 asn1cnst_edge_t right; /* 10 from (MIN..10) */
17
Lev Walkin026e21a2017-10-04 00:49:01 -070018 enum asn1cnst_range_narrowing {
Lev Walkin43292722017-10-05 00:33:32 -070019 /* Sorted from softest to strictest narrowing */
Lev Walkin026e21a2017-10-04 00:49:01 -070020 NOT_NARROW,
Lev Walkin43292722017-10-05 00:33:32 -070021 NARROW_DOUBLE64,
Lev Walkin026e21a2017-10-04 00:49:01 -070022 NARROW_FLOAT32,
23 } narrowing; /* Constrained to a known narrow type */
24
25 /* If range is split in parts, these are the parts */
Lev Walkinb45e0672004-08-18 05:42:05 +000026 struct asn1cnst_range_s **elements;
27 int el_count;
28 int el_size;
29
30 int empty_constraint; /* If yes, too bad. */
Lev Walkinb74ac572004-08-25 02:05:28 +000031 int extensible; /* Extension marker (...) is in effect. */
Lev Walkinb45e0672004-08-18 05:42:05 +000032
Lev Walkinb74ac572004-08-25 02:05:28 +000033 int incompatible; /* Constraint incompatible with argument */
Lev Walkin98eabc12017-07-19 08:51:11 +040034 int not_OER_visible; /* Contains not OER-visible components */
Lev Walkinb74ac572004-08-25 02:05:28 +000035 int not_PER_visible; /* Contains not PER-visible components */
Lev Walkinb45e0672004-08-18 05:42:05 +000036} asn1cnst_range_t;
37
38/*
Lev Walkin98eabc12017-07-19 08:51:11 +040039 * Compute the constraint range with variable visibility restrictions.
Lev Walkinb45e0672004-08-18 05:42:05 +000040 *
41 * (expr_type) must have the type of the top-level parent ASN.1 type.
42 * (required_type) must be one of ACT_EL_RANGE, ACT_CT_SIZE or ACT_CT_FROM.
43 * (minmax) and (expectation_met) should be 0.
44 * ERRORS:
45 * EINVAL: Mandatory arguments missing.
46 * ENOMEM: Memory allocation failure.
47 * EPERM: Invalid constraint reference.
48 */
Lev Walkin4b553412005-08-14 14:45:44 +000049enum cpr_flags {
50 CPR_noflags = 0x00,
Lev Walkin98eabc12017-07-19 08:51:11 +040051 CPR_strict_OER_visibility = 0x01,
52 CPR_strict_PER_visibility = 0x02,
53 CPR_simulate_fbless_SIZE = 0x04,
Lev Walkin4b553412005-08-14 14:45:44 +000054};
Lev Walkina28cbb92017-07-31 20:20:17 -070055asn1cnst_range_t *asn1constraint_compute_OER_range(const char *dbg_name,
56 asn1p_expr_type_e expr_type,
Lev Walkin98eabc12017-07-19 08:51:11 +040057 const asn1p_constraint_t *ct,
58 enum asn1p_constraint_type_e required_type,
59 const asn1cnst_range_t *minmax,
60 int *expectation_met,
61 enum cpr_flags);
Lev Walkina28cbb92017-07-31 20:20:17 -070062asn1cnst_range_t *asn1constraint_compute_PER_range(const char *dbg_name,
63 asn1p_expr_type_e expr_type,
Lev Walkinb45e0672004-08-18 05:42:05 +000064 const asn1p_constraint_t *ct,
65 enum asn1p_constraint_type_e required_type,
66 const asn1cnst_range_t *minmax,
Lev Walkinb74ac572004-08-25 02:05:28 +000067 int *expectation_met,
Lev Walkin4b553412005-08-14 14:45:44 +000068 enum cpr_flags);
Lev Walkin98eabc12017-07-19 08:51:11 +040069/* Base implementation */
Lev Walkina28cbb92017-07-31 20:20:17 -070070asn1cnst_range_t *asn1constraint_compute_constraint_range(const char *dbg_name,
71 asn1p_expr_type_e expr_type,
Lev Walkin98eabc12017-07-19 08:51:11 +040072 const asn1p_constraint_t *ct,
73 enum asn1p_constraint_type_e required_type,
74 const asn1cnst_range_t *minmax,
75 int *expectation_met,
76 enum cpr_flags);
77
Lev Walkinb45e0672004-08-18 05:42:05 +000078void asn1constraint_range_free(asn1cnst_range_t *);
79
80/*
81 * Check that a specific constraint is compatible
82 * with the given expression type.
83 */
84int asn1constraint_compatible(asn1p_expr_type_e expr_type,
Lev Walkin4b553412005-08-14 14:45:44 +000085 enum asn1p_constraint_type_e constr_type, int fbless_SIZE);
Lev Walkinb45e0672004-08-18 05:42:05 +000086
87/*
88 * Fetch a default alphabet for this type.
89 */
90asn1cnst_range_t *asn1constraint_default_alphabet(asn1p_expr_type_e expr_type);
91
92#endif /* ASN1FIX_CRANGE_H */