siftsciex_plug v0.3.0 Siftsciex.HookSig

Logic for calculating the signature for verifying a hook.

Link to this section Summary

Functions

Calculates a signature for the given payload

Extracts the signature from the request

Verifies a signature for a {key, payload} pair

Link to this section Types

Link to this type alg()
alg() :: :md5 | :sha | :sha224 | :sha256 | :sha384 | :sha512
Link to this type t()
t() :: %Siftsciex.HookSig{alg: nil | alg(), value: nil | String.t()}

Link to this section Functions

Link to this function calculate(alg \\ :sha, key, payload)
calculate(alg(), String.t(), String.t()) :: String.t()

Calculates a signature for the given payload.

Parameters

  • algorithm: The algorithm to use for the hmac the default is :sha, this should be a Siftsciex.HookSig.alg/0 value.
  • key: The signature key
  • payload: The payload for the signature

Examples

iex> HookSig.calculate(:sha, "key", "payload")
"2f3902cd1626fa7fdfb67e93109f50412ad71531"
Link to this function from(value)
from(String.t()) :: {:ok, Siftsciex.HookSig.t()} | {:error, String.t()}

Extracts the signature from the request.

Parameters

  • value: The value from the signature header

Examples

iex> HookSig.from("sha1=2f3902cd1626fa7fdfb67e93109f50412ad71531")
{:ok, %HookSig{alg: :sha, value: "2f3902cd1626fa7fdfb67e93109f50412ad71531"}}

iex> HookSig.from("super=__*__")
{:error, "unknown_alg", "super=__*__"}
Link to this function valid?(sig, arg)
valid?(Siftsciex.HookSig.t(), {String.t(), String.t()}) :: boolean()

Verifies a signature for a {key, payload} pair.

Parameters

  • sig: The signature to be verified (Siftsciex.HookSig.t/0)
  • parts: The key and payload to be checked against the signature, this should be in the form of {key, payload}
  • algorithm: The hmac algorithm in the form of Siftsciex.HookSig.alg/0, the default is :sha

Examples

iex> HookSig.valid?(%HookSig{alg: :sha, value: "2f3902cd1626fa7fdfb67e93109f50412ad71531"}, {"key", "payload"})
true

iex> HookSig.valid?(%HookSig{alg: :sha, value: "bullshit"}, {"key", "payload"})
false