Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 1 | #ifndef ASN1FIX_CRANGE_H |
| 2 | #define ASN1FIX_CRANGE_H |
| 3 | |
| 4 | typedef 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 Walkin | b8108ec | 2004-09-29 13:17:17 +0000 | [diff] [blame] | 11 | asn1c_integer_t value; /* Value when type is ARE_VALUE */ |
Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 12 | } asn1cnst_edge_t; |
| 13 | |
| 14 | typedef struct asn1cnst_range_s { |
| 15 | asn1cnst_edge_t left; /* MIN from (MIN..10) */ |
| 16 | asn1cnst_edge_t right; /* 10 from (MIN..10) */ |
| 17 | |
| 18 | /* If range is split in parts, these are the parts */ |
| 19 | struct asn1cnst_range_s **elements; |
| 20 | int el_count; |
| 21 | int el_size; |
| 22 | |
| 23 | int empty_constraint; /* If yes, too bad. */ |
Lev Walkin | b74ac57 | 2004-08-25 02:05:28 +0000 | [diff] [blame] | 24 | int extensible; /* Extension marker (...) is in effect. */ |
Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 25 | |
Lev Walkin | b74ac57 | 2004-08-25 02:05:28 +0000 | [diff] [blame] | 26 | int incompatible; /* Constraint incompatible with argument */ |
Lev Walkin | 98eabc1 | 2017-07-19 08:51:11 +0400 | [diff] [blame] | 27 | int not_OER_visible; /* Contains not OER-visible components */ |
Lev Walkin | b74ac57 | 2004-08-25 02:05:28 +0000 | [diff] [blame] | 28 | int not_PER_visible; /* Contains not PER-visible components */ |
Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 29 | } asn1cnst_range_t; |
| 30 | |
| 31 | /* |
Lev Walkin | 98eabc1 | 2017-07-19 08:51:11 +0400 | [diff] [blame] | 32 | * Compute the constraint range with variable visibility restrictions. |
Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 33 | * |
| 34 | * (expr_type) must have the type of the top-level parent ASN.1 type. |
| 35 | * (required_type) must be one of ACT_EL_RANGE, ACT_CT_SIZE or ACT_CT_FROM. |
| 36 | * (minmax) and (expectation_met) should be 0. |
| 37 | * ERRORS: |
| 38 | * EINVAL: Mandatory arguments missing. |
| 39 | * ENOMEM: Memory allocation failure. |
| 40 | * EPERM: Invalid constraint reference. |
| 41 | */ |
Lev Walkin | 4b55341 | 2005-08-14 14:45:44 +0000 | [diff] [blame] | 42 | enum cpr_flags { |
| 43 | CPR_noflags = 0x00, |
Lev Walkin | 98eabc1 | 2017-07-19 08:51:11 +0400 | [diff] [blame] | 44 | CPR_strict_OER_visibility = 0x01, |
| 45 | CPR_strict_PER_visibility = 0x02, |
| 46 | CPR_simulate_fbless_SIZE = 0x04, |
Lev Walkin | 4b55341 | 2005-08-14 14:45:44 +0000 | [diff] [blame] | 47 | }; |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 48 | asn1cnst_range_t *asn1constraint_compute_OER_range(const char *dbg_name, |
| 49 | asn1p_expr_type_e expr_type, |
Lev Walkin | 98eabc1 | 2017-07-19 08:51:11 +0400 | [diff] [blame] | 50 | const asn1p_constraint_t *ct, |
| 51 | enum asn1p_constraint_type_e required_type, |
| 52 | const asn1cnst_range_t *minmax, |
| 53 | int *expectation_met, |
| 54 | enum cpr_flags); |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 55 | asn1cnst_range_t *asn1constraint_compute_PER_range(const char *dbg_name, |
| 56 | asn1p_expr_type_e expr_type, |
Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 57 | const asn1p_constraint_t *ct, |
| 58 | enum asn1p_constraint_type_e required_type, |
| 59 | const asn1cnst_range_t *minmax, |
Lev Walkin | b74ac57 | 2004-08-25 02:05:28 +0000 | [diff] [blame] | 60 | int *expectation_met, |
Lev Walkin | 4b55341 | 2005-08-14 14:45:44 +0000 | [diff] [blame] | 61 | enum cpr_flags); |
Lev Walkin | 98eabc1 | 2017-07-19 08:51:11 +0400 | [diff] [blame] | 62 | /* Base implementation */ |
Lev Walkin | a28cbb9 | 2017-07-31 20:20:17 -0700 | [diff] [blame] | 63 | asn1cnst_range_t *asn1constraint_compute_constraint_range(const char *dbg_name, |
| 64 | asn1p_expr_type_e expr_type, |
Lev Walkin | 98eabc1 | 2017-07-19 08:51:11 +0400 | [diff] [blame] | 65 | const asn1p_constraint_t *ct, |
| 66 | enum asn1p_constraint_type_e required_type, |
| 67 | const asn1cnst_range_t *minmax, |
| 68 | int *expectation_met, |
| 69 | enum cpr_flags); |
| 70 | |
Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 71 | void asn1constraint_range_free(asn1cnst_range_t *); |
| 72 | |
| 73 | /* |
| 74 | * Check that a specific constraint is compatible |
| 75 | * with the given expression type. |
| 76 | */ |
| 77 | int asn1constraint_compatible(asn1p_expr_type_e expr_type, |
Lev Walkin | 4b55341 | 2005-08-14 14:45:44 +0000 | [diff] [blame] | 78 | enum asn1p_constraint_type_e constr_type, int fbless_SIZE); |
Lev Walkin | b45e067 | 2004-08-18 05:42:05 +0000 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Fetch a default alphabet for this type. |
| 82 | */ |
| 83 | asn1cnst_range_t *asn1constraint_default_alphabet(asn1p_expr_type_e expr_type); |
| 84 | |
| 85 | #endif /* ASN1FIX_CRANGE_H */ |