# `Countersign.Seal.Cert`
[🔗](https://github.com/mkreyman/countersign/blob/v0.1.0/lib/countersign/seal/cert.ex#L1)

The seal's certificates and keys: a self-signed X.509 certificate for an
Ed25519 or SLH-DSA key, what the seal reads from one, and their PEM form.

A private key's PEM is PKCS #8 (`PRIVATE KEY`): for Ed25519 the private key
is wrapped as RFC 8410 7 says (an OCTET STRING holding the 32-byte key),
for SLH-DSA it is the raw key in the OCTET STRING (RFC 9909 6). The
certificate's subject public key and signature carry the same algorithm's
OID, with parameters absent.

# `info`

```elixir
@type info() :: %{
  alg: Countersign.Seal.alg(),
  public_key: binary(),
  subject: String.t(),
  issuer_der: binary(),
  serial_der: binary(),
  der: binary()
}
```

What `parse/1` reads from a certificate.

# `cert_pem`

```elixir
@spec cert_pem(binary()) :: String.t()
```

A certificate's PEM.

# `from_pem`

```elixir
@spec from_pem(String.t(), String.t()) ::
  {:ok, {Countersign.Seal.alg(), {binary(), binary()}}}
  | {:error, :bad_certificate | :bad_key | :alg_mismatch}
```

The `{cert_der, private_key}` pair a certificate PEM and a PKCS #8 key PEM
hold, as `Countersign.Seal.seal/3` takes it, checked to be of the same
algorithm: `{:error, :bad_certificate | :bad_key | :alg_mismatch}`
otherwise. Whether the key matches the certificate is `seal/3`'s check.

# `key_pem`

```elixir
@spec key_pem(Countersign.Seal.alg(), binary()) :: String.t()
```

A private key's PKCS #8 PEM.

# `parse`

```elixir
@spec parse(binary()) :: {:ok, info()} | :error
```

What the seal needs from a certificate, or `:error` for one it cannot read.

# `self_signed`

```elixir
@spec self_signed(Countersign.Seal.alg(), String.t(), keyword()) ::
  {binary(), binary()}
```

A self-signed certificate for a fresh key of `alg`, valid for `years` from
now: `{cert_der, private_key}`. `subject` is the common name; `:org` adds
an organization.

---

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