Struct fog_pack::schema::Schema

source ·
pub struct Schema { /* private fields */ }
Expand description

A Schema, which can be used to encode/decode a document or entry, while verifying its contents.

Schema are decoded from a correctly formatted Document that describes the format of other documents and their associated entries. They also include recommended compression settings for documents & entries adhering to them, which may include compression dictionaries.

A schema must come from a Document. To create one directly, use the SchemaBuilder, then decode the resulting Document into a schema.

Implementations§

source§

impl Schema

source

pub fn from_doc(doc: &Document) -> Result<Self>

Attempt to create a schema from a given document. Fails if the document isn’t a schema.

Warnings

If working with external, untrusted schemas, it’s advisable to use Schema::from_doc_max_regex instead, as regular expressions are hands-down the easiest way to exhaust memory in a system.

source

pub fn from_doc_max_regex(doc: &Document, max_regex: u8) -> Result<Self>

Attempt to create a schema from a given document, first checking how many regular expressions would be present in the schema and failing out if it’s above the provided limit.

For a rough guide of what to set max_regex to, know that every regex has an approximate max memory size of 12 MiB, so a malicious schema can use up at least max_regex * 12 MiB bytes off the heap.

source

pub fn hash(&self) -> &Hash

Get the hash of this schema.

source

pub fn validate_new_doc(&self, doc: NewDocument) -> Result<Document>

Validate a NewDocument, turning it into a Document. Fails if the document doesn’t use this schema, or if it doesn’t meet this schema’s requirements.

source

pub fn encode_doc(&self, doc: Document) -> Result<(Hash, Vec<u8>)>

Encode a Document, returning the resulting Document’s hash and fully encoded format. Fails if the document doesn’t use this schema.

source

pub fn decode_doc(&self, doc: Vec<u8>) -> Result<Document>

Decode a document that uses this schema.

source

pub fn trusted_decode_doc(&self, doc: Vec<u8>) -> Result<Document>

Decode a Document, skipping any checks of the data. This should only be run when the raw document has definitely been passed through validation before, i.e. if it is stored in a local database after going through encode_doc.

source

pub fn validate_new_entry( &self, entry: NewEntry ) -> Result<DataChecklist<'_, Entry>>

Validate a NewEntry, turning it into a Entry. Fails if provided the wrong parent document, the parent document doesn’t use this schema, or the entry doesn’t meet the schema requirements. The resulting Entry is stored in a DataChecklist that must be iterated over in order to finish validation.

source

pub fn encode_entry( &self, entry: Entry ) -> Result<(EntryRef, Vec<u8>, Vec<Hash>)>

Encode an Entry, returning the resulting Entry’s reference, its fully encoded format, and a list of Hashes of the Documents it needs for validation. Fails if provided the wrong parent document or the parent document doesn’t use this schema.

source

pub fn decode_entry( &self, entry: Vec<u8>, key: &str, parent: &Document ) -> Result<DataChecklist<'_, Entry>>

Decode an entry, given the key and parent Hash. Result is in a DataChecklist that must be iterated over in order to finish verification and get the resulting Entry.

source

pub fn trusted_decode_entry( &self, entry: Vec<u8>, key: &str, parent: &Document, entry_hash: &Hash ) -> Result<Entry>

Decode a Entry, skipping most checks of the data. This should only be run when the raw entry has definitely been passed through validation before, i.e. if it is stored in a local database after going through encode_entry.

source

pub fn encode_query(&self, query: NewQuery) -> Result<Vec<u8>>

Encode a query into a byte sequence. Fails if the query is against an entry key that isn’t in the schema, or if the query isn’t a valid one according to the various query permissions in the schema’s validators.

Queries are encoded like fog-pack documents, but without the header containing compression and schema info.

source

pub fn decode_query(&self, query: Vec<u8>) -> Result<Query>

Attempt to decode a query from a byte sequence. Fails if the byte sequence isn’t a valid encoding, if the query is against an entry key that isn’t in the schema, or if the query isn’t a valid one according to the various query permissions in the schema’s validators.

Queries are encoded like fog-pack documents, but without the header containing compression and schema info.

Trait Implementations§

source§

impl Clone for Schema

source§

fn clone(&self) -> Schema

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Schema

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.