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- forIntegerand other integer values.F32Validator- forf32values.F64Validator- forf64values.BinValidator- for byte sequences.StrValidator- for UTF-8 strings.ArrayValidator- for sequences, likeVec, arrays, or tuples.MapValidator- for maps, likestruct,BTreeMap, andHashMapTimeValidator- forTimestampHashValidator- forHashIdentityValidator- forIdentityStreamIdValidator- forStreamIdLockIdValidator- forLockIdBareIdKey- forBareIdKeyDataLockboxValidator- forDataLockboxIdentityLockboxValidator- forIdentityLockboxStreamLockboxValidator- forStreamLockboxLockLockboxValidator- 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§
- Array
Validator - Validator for arrays.
- BinValidator
- Validator for byte sequences.
- Bool
Validator - Validator for boolean values.
- Data
Checklist - A Checklist of documents that must be verified before the contained data is yielded.
- Data
Lockbox Validator - Validator for a
DataLockbox. - Enum
Validator - “Enum” validator that selects a validator based on the value’s enum variant.
- F32Validator
- Validator for 32-bit floating-point values.
- F64Validator
- Validator for 64-bit floating-point values.
- Hash
Validator - Validator for hashes.
- Identity
Lockbox Validator - Validator for a
IdentityLockbox. - Identity
Validator - Validator for a cryptographic
Identity. - IntValidator
- Validator for integer values.
- List
Item - 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
checkfunction of this item. If the check fails, checking should be halted and the checklist should be discarded. - Lock
IdValidator - Validator for a cryptographic
LockId. - Lock
Lockbox Validator - Validator for a
LockLockbox. - MapValidator
- Validator for maps.
- Multi
Validator - “Multi” validator that checks with several validators at once.
- StrValidator
- Validator for UTF-8 strings.
- Stream
IdValidator - Validator for a cryptographic
StreamId. - Stream
Lockbox Validator - Validator for a
StreamLockbox. - Time
Validator - Validator for timestamps.
Enums§
- Normalize
- Unicode Normalization settings.
- Validator
- A fog-pack Validator, for verifying the form of a fog-pack Document or Entry.