Expand description
The fog-pack Validators, for building Schemas and Queries.
This submodule contains various validators, which can be transformed into the Validator
enum type for use in a Schema or a Query. Each struct acts as a constructor that can be
built into a Validator
.
Validators are not used directly; instead, they should be used to build a Schema or Query, which will run them against fog-pack data.
There are validators for each fog-pack core type:
Validator::Null
- for the null type.BoolValidator
- for booleans.IntValidator
- forInteger
and other integer values.F32Validator
- forf32
values.F64Validator
- forf64
values.BinValidator
- for byte sequences.StrValidator
- for UTF-8 strings.ArrayValidator
- for sequences, likeVec
, arrays, or tuples.MapValidator
- for maps, likestruct
,BTreeMap
, andHashMap
TimeValidator
- forTimestamp
HashValidator
- forHash
IdentityValidator
- forIdentity
StreamIdValidator
- forStreamId
LockIdValidator
- forLockId
BareIdKey
- forBareIdKey
DataLockboxValidator
- forDataLockbox
IdentityLockboxValidator
- forIdentityLockbox
StreamLockboxValidator
- forStreamLockbox
LockLockboxValidator
- forLockLockbox
In addition to the core types, there are 4 special validators:
Validator::Ref
- a reference to a validator stored in a schema’s map of types. Uses a name to look up the validator.MultiValidator
- Will attempt a sequence of validators, passing if any one of them pass.EnumValidator
- Acts as a validator for serialized Rust enums. This can also be implemented throughMapValidator
, but this validator is generally easier to use correctly in such cases.Validator::Any
- accepts any fog-pack value without examining it.
Examples
Say we want to build a Document that acts like a file directory. We want to store the creation time of the directory, and a list of file names with associated Hashes, each of which will be the Hash of a file or directory. Let’s also assume we want a valid Unix file name, meaning “/” and NUL cannot be in the name, it cannot be longer than 255 bytes, and shouldn’t be “.” or “..”. A validator for this Document might look like:
let dir = MapValidator::new()
.req_add("created", TimeValidator::new().build())
.req_add("contents", MapValidator::new()
.keys(StrValidator::new()
.nin_add(".")
.nin_add("..")
.ban_char("/\0")
.max_len(255)
.min_len(1)
)
.values(HashValidator::new().build())
.build()
)
.build();
Structs
- Validator for arrays.
- Validator for byte sequences.
- Validator for boolean values.
- A Checklist of documents that must be verified before the contained data is yielded.
- Validator for a
DataLockbox
. - “Enum” validator that selects a validator based on the value’s enum variant.
- Validator for 32-bit floating-point values.
- Validator for 64-bit floating-point values.
- Validator for hashes.
- Validator for a
IdentityLockbox
. - Validator for a cryptographic
Identity
. - Validator for integer values.
- An item in a Checklist. To complete it, find a document whose hash matches the one that was provided alongside this item, then feed that document to the
check
function of this item. If the check fails, checking should be halted and the checklist should be discarded. - Validator for a cryptographic
LockId
. - Validator for a
LockLockbox
. - Validator for maps.
- “Multi” validator that checks with several validators at once.
- Validator for UTF-8 strings.
- Validator for a cryptographic
StreamId
. - Validator for a
StreamLockbox
. - Validator for timestamps.
Enums
- Unicode Normalization settings.
- A fog-pack Validator, for verifying the form of a fog-pack Document or Entry.