Static support for constraint checks
In line with the simplicity and static generation of Quick DER, we might do the following to implement constraints:
- Produce a macro for testing constraints in individual fields
- Compose those macros into contraint tests for composite structures
- Rely on the compiler to skip
&& true
mantras, and evenassert (true);
The following constraints on a field f
could be implemented thusly:
-
SIZE(n..m)
could translate to(f.derlen >= n) && (f.derlen <= m)
-
UTF8String
could call an UTF-8 grammar checker (no0x00
and proper high bits) -
IA5String
could call an ASCII grammar checker - consider
regexec()
forms for all strings, especially for TIME and DATE forms -
(min..max)
ranges forINTEGER
could callder_cmp_int()
with compiledmin
andmax
values
Quick DER applications can choose to call these macros at any time. We might provide a der_unpack_constrained()
wrapper for der_unpack()
that automatically makes this call. At the macro level, the type name can be used to find the right grammar checker. We could even provide a der_pack_constrained()
wrapper. A generic macro der_constrain()
that uses type type name to locate the constraints may also be helpful to the programmer.
Edited by Rick van Rein