Previous: Schema commands, Up: Schemas [Index]
Validation commands are pretty low-level and are inconvenient to write
by hand, at least because of huge quantity of TAKEs.
tcl/schema.tcl
utility gives ability to convert much more
nicer schemas written on Tcl language to the KEKS-encoded commands. We
call that Tcl-written schemas KEKS/Schema.
Example with "our" structure can be written as:
ai {{field . {str} >0}} fpr {{field . {bin} len=32}} our { {field a {with ai}} {field v {bin str}} {field fpr {with fpr}} {field comment {str} optional} }
and cm/pub as:
pub { {field load {with load}} {field sigs {list} {of sig} >0 optional} {field pubs {list} {of pub} >0 optional} } load { {field . {map}} {field t {str} =pub} {field v {with pub-load}} } av { {field . {map}} {field a {str} >0} {field v {bin}} } sig { {field tbs {with pub-sig-tbs}} {field sign {with av}} } schema-include fpr.tcl schema-include pub-load.tcl schema-include pub-sig-tbs.tcl
fpr {{field . {bin} len=32}}
pub-load { {field . {map}} {field id {with fpr}} {field crit {} !exists} {field ku {set} >0 optional} {field pub {list} {of av} >0} {field sub {map} {of str} >0} }
exp-tai {{field . {tai} prec=s utc}} expiration {{field . {list} {of exp-tai} len=2}} pub-sig-tbs { {field . {map}} {field sid {with fpr}} {field cid {hexlet}} {field exp {with expiration}} {field nonce {bin} >0 optional} {field when {tai} utc prec=ms optional} }
schema.tcl
calls schemas{s0 cmds0 s1 cmds1 ...}
commands to produce an encoded map with cmds*
commands for
s*
schemas. There is field
command that helps creation of
commands related to the field.
Its first argument is either field’s name in the map, or list’s index or dot, meaning the self-structure itself.
Second argument is a list of allowable types, written in lowercase. If
that list consists of with S
, then SCHEMA command will be called
instead of TYPE checking. If list consists of set
, then it is
checked to be a MAP with EACH value of NIL.
All other arguments are optional.
By default, if no optional
argument is specified, then explicit
EXISTS check is called for the field. If !exists
argument is
specified, then it is explicitly checked to be non-existent and you can
specify empty list of types in second argument.
>n
and <n
arguments allow checking of the integer value or
the lengths. >0
assures that either list/map or strings are not
empty. len=n
checks the exact length. =v
checks that given
element has specified string/binary value (use len=
for integers).
prec=p
issues TIMEPREC command, but instead of specifying the raw
integer values, you choose one of: s, ms, us, ns, ps, fs, as. utc
issues UTC command.
of s
argument issues checking of EACH element of the list or map
against the specified schema, or against specified type if s
is a
known type.
schema-include filename.tcl
command used instead of field
allows inclusion of the specified file with the path relative to given
schema file.
Previous: Schema commands, Up: Schemas [Index]