# `Alternera.Plugins.Sqs.SigV4`
[🔗](https://github.com/10e-ab/alternera-sqs/blob/v0.9.0/lib/alternera/plugins/sqs/sig_v4.ex#L1)

AWS Signature Version 4 for one request, signed in the `Authorization`
header (`AWS4-HMAC-SHA256`), for `Alternera.Plugins.Sqs`.

It is generic over the method, path, query, headers, body, region and
service: it signs exactly the headers it is given (each name lowercased,
each value trimmed, inner runs of spaces folded to one), which must
include `host` and `x-amz-date`. The path is signed as given, already
URI-encoded once, as every service but S3 expects; the query is sorted by
name and then value and each part encoded as RFC 3986 unreserved.

The tests check it against the AWS SigV4 test suite's `get-vanilla`,
`post-vanilla` and `get-vanilla-query` signatures, and against a request
signed by an independent implementation.

# `request`

```elixir
@type request() :: %{
  method: String.t(),
  path: String.t(),
  query: [{String.t(), String.t()}],
  headers: [{String.t(), String.t()}],
  body: iodata()
}
```

A request to sign: `path` encoded, `query` a list of `{name, value}`.

# `signer`

```elixir
@type signer() :: %{
  access_key_id: String.t(),
  secret_access_key: String.t(),
  region: String.t(),
  service: String.t(),
  amz_date: String.t()
}
```

Who signs and for what: the key pair, the region and service, and the time.

# `amz_date`

```elixir
@spec amz_date(DateTime.t()) :: String.t()
```

The time as SigV4 writes it, `YYYYMMDDTHHMMSSZ`, in UTC.

# `authorization`

```elixir
@spec authorization(request(), signer()) :: String.t()
```

The `Authorization` header's value for `request`, signed by `signer`.
`request`'s headers must hold the `x-amz-date` that `signer.amz_date`
names.

# `canonical_request`

```elixir
@spec canonical_request(request()) :: {String.t(), String.t()}
```

The canonical request, as `{signed_headers, text}`: the method, path,
canonical query, the headers as `name:value` lines, the signed header
names joined by `;`, and the hex SHA-256 of the body.

# `scope`

```elixir
@spec scope(signer()) :: String.t()
```

The credential scope: `<date>/<region>/<service>/aws4_request`.

# `string_to_sign`

```elixir
@spec string_to_sign(String.t(), signer()) :: String.t()
```

The string to sign for a canonical request.

---

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