Enum MaybeUntrusted

Source
pub enum MaybeUntrusted<Insecure, Trusted = Insecure> {
    Ok(Trusted),
    Untrusted(UntrustedValue<Insecure>),
}
Expand description

Represents a value that might be untrusted. See UntrustedValue for more information.

Variants§

§

Ok(Trusted)

Trusted value variant

§

Untrusted(UntrustedValue<Insecure>)

Untrusted value variant

Implementations§

Source§

impl<Insecure> MaybeUntrusted<Insecure>

Source

pub fn use_untrusted_value(self) -> Insecure

Be sure that you carefully handle the returned value since it may be controllable by a malicious actor (when it is a MaybeUntrusted::Untrusted).

See the method documentation of the function returning this value

Source

pub fn wrap(value: Insecure, untrusted: bool) -> Self

Wraps the provided value as maybe untrusted, according to given boolean

Source§

impl<Insecure, Trusted> MaybeUntrusted<Insecure, Trusted>

Source

pub fn is_untrusted(&self) -> bool

Returns true if the value is untrusted

Source

pub fn is_ok(&self) -> bool

Returns true if the value is not untrusted

Source

pub fn wrap_untrusted(value: Insecure) -> Self

Wraps the provided values as Untrusted

Source

pub fn wrap_ok(value: Trusted) -> Self

Wraps the provided values as Ok

Trait Implementations§

Source§

impl<Insecure: Clone, Trusted: Clone> Clone for MaybeUntrusted<Insecure, Trusted>

Source§

fn clone(&self) -> Self

Clones the value

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Insecure, Trusted> From<UntrustedValue<Insecure>> for MaybeUntrusted<Insecure, Trusted>

Source§

fn from(value: UntrustedValue<Insecure>) -> Self

Converts an UntrustedValue to a MaybeUntrusted value

Source§

impl<E, Insecure: SanitizeValue<Insecure, Error = E>> SanitizeValue<Insecure> for MaybeUntrusted<Insecure>

Source§

type Error = E

The error type that is returned in case of a sanitization failure.
Source§

fn sanitize_value(self) -> Result<Insecure, Self::Error>

Sanitizes the value. Read more
Source§

impl<Insecure, Trusted> SanitizeWith<Insecure, Trusted> for MaybeUntrusted<Insecure, Trusted>

Source§

fn sanitize_with<Sanitizer, Error>( self, sanitizer: Sanitizer, ) -> Result<Trusted, Error>
where Sanitizer: FnOnce(Insecure) -> Result<Trusted, Error>,

Sanitizes the value using the provided sanitizer if the value is untrusted.

The sanitizer may transmute the value to a different type. If sanitization fails, an error must be returned.

Source§

impl<Insecure: Copy, Trusted: Copy> Copy for MaybeUntrusted<Insecure, Trusted>

Auto Trait Implementations§

§

impl<Insecure, Trusted> Freeze for MaybeUntrusted<Insecure, Trusted>
where Trusted: Freeze, Insecure: Freeze,

§

impl<Insecure, Trusted> RefUnwindSafe for MaybeUntrusted<Insecure, Trusted>
where Trusted: RefUnwindSafe, Insecure: RefUnwindSafe,

§

impl<Insecure, Trusted> Send for MaybeUntrusted<Insecure, Trusted>
where Trusted: Send, Insecure: Send,

§

impl<Insecure, Trusted> Sync for MaybeUntrusted<Insecure, Trusted>
where Trusted: Sync, Insecure: Sync,

§

impl<Insecure, Trusted> Unpin for MaybeUntrusted<Insecure, Trusted>
where Trusted: Unpin, Insecure: Unpin,

§

impl<Insecure, Trusted> UnwindSafe for MaybeUntrusted<Insecure, Trusted>
where Trusted: UnwindSafe, Insecure: UnwindSafe,

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<Insecure, OtherInsecure> FromTrustedVariant<OtherInsecure> for Insecure
where OtherInsecure: IntoUntrustedVariant<Insecure>,

Source§

fn from_untrusted_variant(other: OtherInsecure) -> Insecure

Converts the provided type to an equivalent untrusted type.

No sanitization is done here, only the conversion to an untrusted type.

This function MUST guarantee the following properties:

  1. The conversion result MUST NOT contain untainted data that was tainted in the input.
  2. The conversion MUST NOT do any sanitization.
  3. If the input is not tainted, all parts of the output MUST be tainted.

This method is auto-implemented since the other type implements the IntoUntrustedVariant trait.

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 = 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 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.