pub struct UntrustedValue<Insecure> { /* private fields */ }Expand description
Represents an untrusted/untrustworthy value. The data contained inside this type is called tainted.
An attacker might be able to control (part) of the returned value. Take special care processing this data.
Taint can be cleared by using one of the traits SanitizeWith or SanitizeValue.
Effectively, sanitizing the data.
This type does explicitly not implement common traits like Debug, Display, etc. since the data contained is considered untrusted. If desired you COULD implement these traits in for your custom types.
For naming purposes an untrusted value mapped inside this type is considered safe/trusted since it can not be accessed without sanitization.
Implementations§
Source§impl<Insecure> UntrustedValue<Insecure>
Implementation of the UntrustedValue type.
impl<Insecure> UntrustedValue<Insecure>
Implementation of the UntrustedValue type.
Sourcepub fn use_untrusted_value(self) -> Insecure
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.
Does not perform any sanitization on the returned value.
Sourcepub fn wrap(value: Insecure) -> Self
pub fn wrap(value: Insecure) -> Self
Wraps the provided value as UntrustedValue
Trait Implementations§
Source§impl<Insecure: Clone> Clone for UntrustedValue<Insecure>
A tainted value may be cloned if the underlying value is cloneable. This is considered safe
since the taint is also cloned.
impl<Insecure: Clone> Clone for UntrustedValue<Insecure>
A tainted value may be cloned if the underlying value is cloneable. This is considered safe since the taint is also cloned.
impl<Insecure: Copy> Copy for UntrustedValue<Insecure>
Source§impl<Insecure> From<Insecure> for UntrustedValue<Insecure>
Provide easy conversion from some value to an UntrustedValue.
impl<Insecure> From<Insecure> for UntrustedValue<Insecure>
Provide easy conversion from some value to an UntrustedValue.
Source§fn from(value: Insecure) -> Self
fn from(value: Insecure) -> Self
Wraps the provided value as UntrustedValue
Source§impl<Insecure, Trusted> From<UntrustedValue<Insecure>> for MaybeUntrusted<Insecure, Trusted>
impl<Insecure, Trusted> From<UntrustedValue<Insecure>> for MaybeUntrusted<Insecure, Trusted>
Source§fn from(value: UntrustedValue<Insecure>) -> Self
fn from(value: UntrustedValue<Insecure>) -> Self
Converts an UntrustedValue to a MaybeUntrusted value
Source§impl<Sanitized, E, Insecure: SanitizeValue<Sanitized, Error = E>> SanitizeValue<Sanitized> for UntrustedValue<Insecure>
If the tainted data type can be sanitized using the SanitizeValue trait, implement also
the SanitizeValue trait for this UntrustedValue type.
impl<Sanitized, E, Insecure: SanitizeValue<Sanitized, Error = E>> SanitizeValue<Sanitized> for UntrustedValue<Insecure>
If the tainted data type can be sanitized using the SanitizeValue trait, implement also
the SanitizeValue trait for this UntrustedValue type.
Source§type Error = E
type Error = E
The error type will be propagated from the underlying SanitizeValue implementation.
Source§fn sanitize_value(self) -> Result<Sanitized, Self::Error>
fn sanitize_value(self) -> Result<Sanitized, Self::Error>
Sanitizes the value.
The returned value is sanitized and can be safely used. If the value cannot be sanitized, an error must be returned.
Source§impl<Insecure, Trusted> SanitizeWith<Insecure, Trusted> for UntrustedValue<Insecure>
Taint can be cleared from the value by using a sanitizer.
Effectively unpacking the value; passing it to the sanitizer and returning the result.
impl<Insecure, Trusted> SanitizeWith<Insecure, Trusted> for UntrustedValue<Insecure>
Taint can be cleared from the value by using a sanitizer. Effectively unpacking the value; passing it to the sanitizer and returning the result.
Source§fn sanitize_with<Sanitizer, Error>(
self,
sanitizer: Sanitizer,
) -> Result<Trusted, Error>
fn sanitize_with<Sanitizer, Error>( self, sanitizer: Sanitizer, ) -> Result<Trusted, Error>
Sanitizes the value using the provided sanitizer.
The sanitizer may transmute the value to a different type. If sanitization fails, an error must be returned.
Auto Trait Implementations§
impl<Insecure> Freeze for UntrustedValue<Insecure>where
Insecure: Freeze,
impl<Insecure> RefUnwindSafe for UntrustedValue<Insecure>where
Insecure: RefUnwindSafe,
impl<Insecure> Send for UntrustedValue<Insecure>where
Insecure: Send,
impl<Insecure> Sync for UntrustedValue<Insecure>where
Insecure: Sync,
impl<Insecure> Unpin for UntrustedValue<Insecure>where
Insecure: Unpin,
impl<Insecure> UnsafeUnpin for UntrustedValue<Insecure>where
Insecure: UnsafeUnpin,
impl<Insecure> UnwindSafe for UntrustedValue<Insecure>where
Insecure: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Insecure, OtherInsecure> FromTrustedVariant<OtherInsecure> for Insecurewhere
OtherInsecure: IntoUntrustedVariant<Insecure>,
impl<Insecure, OtherInsecure> FromTrustedVariant<OtherInsecure> for Insecurewhere
OtherInsecure: IntoUntrustedVariant<Insecure>,
Source§fn from_untrusted_variant(other: OtherInsecure) -> Insecure
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:
- The conversion result MUST NOT contain untainted data that was tainted in the input.
- The conversion MUST NOT do any sanitization.
- 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.