# Trust transitions
The `trust` module distinguishes external input from values that have passed
through an application policy.
## Mark input at the boundary
```rust
use requisite::prelude::*;
let raw = Tainted::<_, Untrusted>::from_input(" customer-42 ".to_owned());
```
`as_ref` borrows the value for logging, measurement, or validation while
retaining its trust tag:
```rust
println!("received {} bytes", raw.as_ref().len());
```
## Apply an infallible policy
Use `sanitize` when the transformation always produces a usable value:
```rust
use requisite::prelude::*;
let raw = Tainted::<_, Untrusted>::from_input(" CUSTOMER-42 ".to_owned());
assert_eq!(normalized.into_inner(), "customer-42");
```
The output type may differ from the input type:
```rust
let raw = Tainted::<_, Untrusted>::from_input(vec![1_u8, 2, 3]);
## Apply a fallible policy
Use `try_sanitize` for parsing and validation:
```rust
use requisite::prelude::*;
fn parse_customer_id(
input: Tainted<String, Untrusted>,
) -> Result<Tainted<u64, Trusted>, std::num::ParseIntError> {
try_sanitize(input, |value| value.parse())
}
```
The successful branch contains `Tainted<_, Trusted>`, so ordinary `Result`
handling composes with the trust transition:
```rust
let id = parse_customer_id(raw)?;
load_customer(id);
```
## Design trusted sinks
Put the requirement in the receiving function:
```rust
fn load_customer(id: Tainted<u64, Trusted>) -> Customer {
database_lookup(id.into_inner())
}
```
Callers now have one explicit route from external input to the sink. The policy
closure is the review point for parsing, normalization, escaping, or validation
required by that sink.
Different sinks can use different trusted representations. A database query may
require a parsed numeric ID, while an HTML renderer may require an escaped
string.
## Lower a trust requirement
An API that accepts untrusted data can also receive a trusted value through
`widen`:
```rust
fn measure(input: Tainted<String, Untrusted>) -> usize {
input.as_ref().len()
}
```
`widen` is defined on `Tainted<T, Trusted>` and returns
`Tainted<T, Untrusted>`. Promotion to `Trusted` remains attached to
`sanitize` and `try_sanitize`.