aboutsummaryrefslogtreecommitdiffstats
path: root/libasn1parser/asn1p_constr.h
blob: 8dd547b8523c501dcde575174712f9984061b58b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Type constraints.
 */
#ifndef	ASN1_PARSER_CONSTRAINT_H
#define	ASN1_PARSER_CONSTRAINT_H

typedef struct asn1p_constraint_s {

	enum asn1p_constraint_type_e {
		ACT_INVALID,		/* for assertions */
		/*
		 * Constraint elements.
		 */
		ACT_EL_TYPE,		/* T (contained subtype) */
		ACT_EL_VALUE,		/* 123, "A", (elementary value) */
		ACT_EL_RANGE,		/* 1..2 (elementary range) */
		ACT_EL_LLRANGE,		/* 1<..2 (elementary range) */
		ACT_EL_RLRANGE,		/* 1..<2 (elementary range) */
		ACT_EL_ULRANGE,		/* 1<..<2 (elementary range) */
		ACT_EL_EXT,		/* ... (extensibility mark) */
		/*
		 * Constraint types.
		 */
		ACT_CT_SIZE,		/* SIZE constraint type */
		ACT_CT_FROM,		/* FROM constraint type */
		ACT_CT_WCOMP,		/* WITH COMPONENT */
		ACT_CT_WCOMPS,		/* WITH COMPONENTS */
		ACT_CT_CTDBY,		/* CONSTRAINED BY */
		/*
		 * Arrays of constraints.
		 */
		ACT_CA_SET,		/* A set of constraints: (c1)(c2) */
		ACT_CA_CRC,		/* Comp. relation c-t: ({a})({@b}) */
		ACT_CA_CSV,		/* Comma-separated constraints array */
		ACT_CA_UNI,		/* UNION (|) */
		ACT_CA_INT,		/* INTERSECTION (^) */
		ACT_CA_EXC,		/* EXCEPT */
		ACT_CA_AEX,		/* ALL EXCEPT */
	} type;

	enum asn1p_constr_pres_e {
		ACPRES_DEFAULT,
		ACPRES_PRESENT,
		ACPRES_ABSENT,
		ACPRES_OPTIONAL,
	} presence;

	/*
	 * Separate types and values.
	 */
	asn1p_value_t *containedSubtype;
	asn1p_value_t *value;
	asn1p_value_t *range_start;
	asn1p_value_t *range_stop;

	/*
	 * A collection of constraint elements.
	 */
	struct asn1p_constraint_s **elements;
	unsigned int el_count;	/* Number of meaningful elements */
	unsigned int el_size;	/* Size of the allocated (elements) */

	int _lineno;	/* Position in a source file */
} asn1p_constraint_t;

/* Human-readable constraint type description */
char *asn1p_constraint_type2str(enum asn1p_constraint_type_e);

/*
 * Constructors and a recursive destructor.
 */
asn1p_constraint_t *asn1p_constraint_new(int _lineno);
void asn1p_constraint_free(asn1p_constraint_t *);

/*
 * Clone the constraint and all its children.
 */
asn1p_constraint_t *asn1p_constraint_clone(asn1p_constraint_t *source_to_clone);

/*
 * Insert additional element into the element array of a (to) constraint.
 */
int asn1p_constraint_insert(asn1p_constraint_t *into, asn1p_constraint_t *what);

#endif	/* ASN1_PARSER_CONSTRAINT_H */