sigaws v0.1.0 Sigaws.Util

A varied collection of functions useful in request signing and verification.

Summary

Functions

Adds given parameters to the given URL’s query string

Given the verification context checks if the request has expired

Converts X-Amz-Date format “YYYMMDDTHHMMSSZ” to Elixir DateTime in UTC

Returns a signing key using AWS4_HMAC_SHA56 algorithm

Functions

add_params_to_url(url, p)

Adds given parameters to the given URL’s query string.

iex> "http://a.net/doit?a=10" |> Sigaws.Util.add_params_to_url(%{"b" => "20"})
"http://a.net/doit?a=10&b=20"
check_expiration(ctxt)
check_expiration(Sigaws.Ctxt.t) :: :ok | {:error, atom, binary}

Given the verification context checks if the request has expired.

ReturnsWhen
:okexpires_in is not specified (nil)
:oksigned_at + expires_in <= utc_now
{:error, :expired, ""}Otherwise
{:error, :invalid_data, "timestamp"}timestamp is incorrect

This can be called from pre_verification callback implementation of the Sigaws.Provider behavior.

If you need a more nuanced expiration check with clock skew considerations, use this implementation as a starting point and have your own expiration check called from your pre_verification callback implementation.

parse_amz_dt(arg1)
parse_amz_dt(binary) ::
  {:ok, DateTime.t} |
  {:error, atom, binary}

Converts X-Amz-Date format “YYYMMDDTHHMMSSZ” to Elixir DateTime in UTC.

{:ok, %DateTime{time_zone: "Etc/UTC"}} = parse_amz_dt("20171010T010203Z")

Returns {:error, :invalid_data, "timestamp"} upon error.

signing_key(signed_on, region, service, secret)
signing_key(Date.t, binary, binary, binary) :: {:ok, binary}

Returns a signing key using AWS4_HMAC_SHA56 algorithm.

The verification process relies on the Sigaws.Provider behavior to get the signing key. This function can be called from this behavior implementation to generate the signing key. (AWS examples)