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 section Functions
Link to this function
calculate(alg \\ :sha, key, payload)
Calculates a signature for the given payload.
Parameters
algorithm
: The algorithm to use for the hmac the default is:sha
, this should be aSiftsciex.HookSig.alg/0
value.key
: The signature keypayload
: 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
: Thekey
andpayload
to be checked against the signature, this should be in the form of{key, payload}
algorithm
: The hmac algorithm in the form ofSiftsciex.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