Client-side HMAC signing for URLs emitted by Image.Components.URL.
Functionally equivalent to Image.Plug.Signing on the back-end:
HMAC-SHA256 over the path-and-query (with the sig parameter
removed), hex-encoded, appended as ?sig=<hex>. Sign-only — the
back-end verifies. Use this when your Image.Plug deployment is
configured with :signing and you need the component to emit
authentic URLs.
Self-contained — does not depend on image_plug. Both packages
share the wire format, not the code.
Examples
iex> path = "/cdn-cgi/image/width=200/photo.jpg"
iex> signed = Image.Components.Signing.sign(path, ["secret"])
iex> String.starts_with?(signed, path <> "?sig=")
true
Summary
Functions
Signs path with the first key in keys.
Functions
Signs path with the first key in keys.
Arguments
pathis the request path (with or without an existing query string).keysis a non-empty list of secret-key strings. The first key is used.
Options
:expires_at—DateTimeor unix-seconds integer. When set, appends?exp=<unix-seconds>and signs the result.
Returns
- The path with
?sig=<hex>(and optional?exp=…) appended.
Examples
iex> Image.Components.Signing.sign("/foo.jpg", ["secret"])
...> |> String.starts_with?("/foo.jpg?sig=")
true
iex> Image.Components.Signing.sign("/foo.jpg?other=1", ["secret"])
...> =~ "?other=1&sig="
true