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
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(Sigaws.Ctxt.t()) :: :ok | {:error, atom(), binary()}
Given the verification context checks if the request has expired.
Returns | When |
---|---|
:ok | expires_in is not specified (nil ) |
:ok | signed_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.
Calculate lower case hex encoded SHA256 digest/hash of the given binary or stream.
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(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)