Skip to main content

Policy

Struct Policy 

Source
pub struct Policy { /* private fields */ }
Expand description

What a host will run.

The default runs decoders embedded in the container and nothing else. That is the case the format is designed around: the dataset carries the code that reads it, so there is nothing to fetch and nothing to decide. A decoder named by a URI is a different proposition, because a dataset that names one can cause a host to go and get something and then execute it, and this crate will not do that unless a host has said so with a resolver of its own.

There is no boolean here on purpose. Turning external decoders on means writing the thing that goes and finds them, which is not something anybody does by accident.

Implementations§

Source§

impl Policy

Source

pub const fn embedded_only() -> Self

Embedded decoders and nothing else, which is the default.

Source

pub fn with_external_decoders_resolved_by( resolver: impl Resolve + 'static, ) -> Self

Also runs decoders that live outside the container, using this resolver to find them.

The bytes the resolver returns are hashed and compared to the digest in the container in exactly the same way an embedded module is. A resolver that returns the wrong module, or a registry that has been tampered with, fails here rather than at the compiler.

Source

pub fn resolver(&self) -> Option<&dyn Resolve>

The resolver this policy will use for a decoder that is not in the container, if any.

Source§

impl Policy

Source

pub fn decoder<'a>( &self, container: &Container<'a>, ) -> Result<Verified<'a>, Untrusted>

Finds the decoder this container names and hands it over only if it hashes to what the container says.

This is the whole of the trust boundary for a decoder, and hashing is not a step it can be asked to skip. There is no flag here, and there is nowhere else to get the bytes.

The hash is over the module alone. The container’s root digest covers the header and the footer, which is what makes a container cheap to open, so a byte changed inside the decoder section parses perfectly well and is caught here instead. That is the case this exists for.

A decoder that lives outside the container is refused unless this policy was built with a resolver. Whatever the resolver returns is hashed exactly like an embedded module, so a registry that hands back the wrong thing fails here rather than at the compiler.

§Errors

Returns Untrusted::Missing if the container names no decoder, Untrusted::External if the module lives outside the container and this policy has no resolver, Untrusted::Unresolved if it has one and the resolver found nothing, Untrusted::Lost if an embedded module names a section that is not in the file, and Untrusted::Digest, carrying both digests, if the bytes are not the module the container names.

Trait Implementations§

Source§

impl Clone for Policy

Source§

fn clone(&self) -> Policy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Policy

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Policy

Source§

fn default() -> Policy

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.