Module validator

Module validator 

Source
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:

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 through MapValidator, 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§

ArrayValidator
Validator for arrays.
BinValidator
Validator for byte sequences.
BoolValidator
Validator for boolean values.
DataChecklist
A Checklist of documents that must be verified before the contained data is yielded.
DataLockboxValidator
Validator for a DataLockbox.
EnumValidator
“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.
HashValidator
Validator for hashes.
IdentityLockboxValidator
Validator for a IdentityLockbox.
IdentityValidator
Validator for a cryptographic Identity.
IntValidator
Validator for integer values.
ListItem
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.
LockIdValidator
Validator for a cryptographic LockId.
LockLockboxValidator
Validator for a LockLockbox.
MapValidator
Validator for maps.
MultiValidator
“Multi” validator that checks with several validators at once.
StrValidator
Validator for UTF-8 strings.
StreamIdValidator
Validator for a cryptographic StreamId.
StreamLockboxValidator
Validator for a StreamLockbox.
TimeValidator
Validator for timestamps.

Enums§

Normalize
Unicode Normalization settings.
Validator
A fog-pack Validator, for verifying the form of a fog-pack Document or Entry.