# `PKCS12.Error`
[🔗](https://github.com/openspb/pkcs12/blob/v0.1.1/lib/pkcs12/error.ex#L1)

Why a PKCS#12 file could not be read or written.

`PKCS12.decode/3` and `PKCS12.encode/3` return it as
`{:error, %PKCS12.Error{}}`, and `PKCS12.decode!/3` and `PKCS12.encode!/3`
raise it. Match on `:reason`:

  * `:malformed` - not a valid PKCS#12 structure.
  * `:invalid_password` - the MAC does not match, or, in a file without a
    MAC, the content does not decrypt.
  * `{:unsupported_version, version}` - the PFX version is not 3.
  * `{:unsupported_algorithm, oid}` - an algorithm the library does not
    implement, with its OID in dotted form.
  * `{:unsupported, :public_key_integrity | :public_key_privacy}` - the
    file is signed with, or encrypted to, a public key instead of a
    password. Such files are very rare.
  * `{:not_available, algorithm}` - the library knows the algorithm, but
    the `:crypto` application of this system (its OpenSSL) refuses it. For
    example, RC4 when the OpenSSL "legacy" provider is missing, or
    parameters that a FIPS provider rejects.
  * `{:too_many_iterations, count}` - one key derivation asks for more
    iterations than the `:max_iterations` option allows.
  * `{:too_many_total_iterations, count}` - the work of all derivations
    together goes beyond the `:max_total_iterations` option; `count` is
    the work done or due when the limit was reached.
  * `{:unsupported_mac_key_size, bytes}` - a PBMAC1 key size outside
    20..64 bytes.
  * `{:invalid_input, field}` - when writing, `field` (`:private_key`,
    `:certificate` or `:ca_certificates`) is not a key or certificates in
    a form that `PKCS12.encode/3` takes.

The error never carries the password or any key material.

# `reason`

```elixir
@type reason() ::
  :malformed
  | :invalid_password
  | {:unsupported_version, non_neg_integer()}
  | {:unsupported_algorithm, String.t()}
  | {:unsupported, :public_key_integrity | :public_key_privacy}
  | {:not_available, atom()}
  | {:too_many_iterations, pos_integer()}
  | {:too_many_total_iterations, pos_integer()}
  | {:unsupported_mac_key_size, non_neg_integer()}
  | {:invalid_input, :private_key | :certificate | :ca_certificates}
```

# `t`

```elixir
@type t() :: %PKCS12.Error{__exception__: true, reason: reason()}
```

---

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