# `Pasexto.Rules`
[🔗](https://github.com/alexkornitzer/pasexto/blob/v0.1.2/lib/pasexto/rules.ex#L1)

Default rules that can be used during the building and/or parsing of PASETO
tokens.

A rule is just a function that accepts a claim as its first argument and
returns `:ok` or an error reason tuple. For example, build applies the
following rules by default:

```elixir
iex> key = Pasexto.Key.new(:v4, :local)
iex> claims = %{"hello": "world"}
iex> footer = <<>>
iex> {:ok, paseto, claims} = Pasexto.build(:v4, :local, key, claims, footer)
iex> {:ok, ^claims, ^footer} = Pasexto.parse(:v4, :local, key, paseto, rules: [
...>   &Pasexto.Rules.validate_required(&1),
...>   &Pasexto.Rules.validate_exp(&1),
...>   &Pasexto.Rules.validate_iat(&1),
...>   &Pasexto.Rules.validate_nbf(&1)
...> ])
```

# `claims`

```elixir
@type claims() :: map()
```

# `validate_exp`

```elixir
@spec validate_exp(claims(), pos_integer()) ::
  :ok | {:error, {:invalid_claim, :exp, DateTime.t()}}
```

Validates that the expiry claim has not expired.

The jitter can be set in seconds for how much grace to give to the time
check, it defaults to `60`.

> #### Note {: .warning}
> This function does not enforce requirement, for that `validate_required/2`
should be used.

# `validate_iat`

```elixir
@spec validate_iat(claims(), pos_integer()) ::
  :ok | {:error, {:invalid_claim, :iat, DateTime.t()}}
```

Validates that the issued at claim has happened in the past.

The jitter can be set in seconds for how much grace to give to the time
check, it defaults to `60`.

> #### Note {: .warning}
> This function does not enforce requirement, for that `validate_required/2`
should be used.

# `validate_nbf`

```elixir
@spec validate_nbf(claims(), pos_integer()) ::
  :ok | {:error, {:invalid_claim, :nbf, DateTime.t()}}
```

Validates that the not before claim has happened in the past.

The jitter can be set in seconds for how much grace to give to the time
check, it defaults to `60`.

> #### Note {: .warning}
> This function does not enforce requirement, for that `validate_required/2`
should be used.

# `validate_required`

```elixir
@spec validate_required(claims(), list()) :: :ok | {:error, {:missing_claims, list()}}
```

Validates the the required claims are present.

By default the following claims are required: `:exp`, `:jti`, `:iat` and
`:nbf`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
