# `ASDF.Limits`
[🔗](https://github.com/baoulo/asdf-elixir/blob/v0.1.0/lib/asdf/limits.ex#L1)

Bounds for untrusted ASDF input.

Every field is a positive integer. A file that crosses a bound returns
`{:error, %ASDF.Error{}}`. The defaults are:

  * `max_tree_bytes` — 16_777_216
  * `max_block_bytes` — 1_073_741_824
  * `max_depth` — 64
  * `max_scalar_bytes` — 1_048_576
  * `max_aliases` — 1_000
  * `max_nodes` — 100_000
  * `max_blocks` — 100_000
  * `max_comment_lines` — 128
  * `max_header_line_bytes` — 256

`max_comment_lines` counts comment lines after the `#ASDF` line. The next
comment after that many is `reason: :too_many_comments`.

# `t`

```elixir
@type t() :: %ASDF.Limits{
  max_aliases: pos_integer(),
  max_block_bytes: pos_integer(),
  max_blocks: pos_integer(),
  max_comment_lines: pos_integer(),
  max_depth: pos_integer(),
  max_header_line_bytes: pos_integer(),
  max_nodes: pos_integer(),
  max_scalar_bytes: pos_integer(),
  max_tree_bytes: pos_integer()
}
```

One set of bounds. Each field is a positive integer.

  * `:max_tree_bytes` — most bytes read while looking for the YAML `...` line
  * `:max_block_bytes` — largest `used_size` or `data_size` accepted
  * `:max_depth` — deepest nested YAML collection
  * `:max_scalar_bytes` — longest YAML scalar
  * `:max_aliases` — most alias nodes in one tree
  * `:max_nodes` — most YAML nodes in one tree
  * `:max_blocks` — most binary blocks in one file
  * `:max_comment_lines` — most `#` lines after the format header
  * `:max_header_line_bytes` — longest header or comment line, including `#`

# `default`

```elixir
@spec default() :: t()
```

Returns the default bounds.

## Examples

    iex> limits = ASDF.Limits.default()
    ...> {limits.max_depth, limits.max_comment_lines, limits.max_header_line_bytes}
    {64, 128, 256}

# `new`

```elixir
@spec new(keyword()) :: {:ok, t()} | {:error, ASDF.Error.t()}
```

Builds limits from `opts`.

`opts` is a keyword list of the struct fields. Omitted fields keep the
defaults. Returns `{:ok, limits}`. An unknown key is
`{:error, %ASDF.Error{reason: :unknown_limit}}`. A non-positive integer
is `reason: :invalid_limit`. Does not raise.

## Examples

    iex> {:ok, limits} = ASDF.Limits.new(max_depth: 4)
    ...> limits.max_depth
    4

    iex> {:error, error} = ASDF.Limits.new(max_depth: 0)
    ...> error.reason
    :invalid_limit

    iex> {:error, error} = ASDF.Limits.new(nope: 1)
    ...> error.reason
    :unknown_limit

# `new!`

```elixir
@spec new!(keyword()) :: t()
```

Builds limits from `opts` and returns the struct.

`opts` is the same keyword list as `new/1`. Returns the `%ASDF.Limits{}`.
Raises `ASDF.Error` for an unknown key or a non-positive integer.

## Examples

    iex> ASDF.Limits.new!(max_depth: 4).max_depth
    4

    iex> ASDF.Limits.new!(max_depth: 0)
    ** (ASDF.Error) limit max_depth must be a positive integer, got 0

---

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