sigaws v0.7.2 Sigaws.Util

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

Link to this section Summary

Functions

Adds given parameters to the given URL’s query string

Given the verification context checks if the request has expired

Calculate lower case hex encoded SHA256 digest/hash of the given binary or stream

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

Returns a signing key using AWS4_HMAC_SHA56 algorithm

Link to this section Functions

Link to this function 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"
Link to this function 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.

Link to this function hexdigest(data)
hexdigest(binary() | Enumerable.t()) :: binary()

Calculate lower case hex encoded SHA256 digest/hash of the given binary or stream.

Link to this function 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.

Link to this function 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)