apoc v1.0.0-rc1 Apoc.Adapter.MAC behaviour View Source

Defines a Message Authenticated Code adapter.

defmodule MyMac do
  use Apoc.Adapter.MAC

  @impl Apoc.Adapter.MAC
  def sign(message, key, opts \ []) do
    tag = signing_algo(message, key)
    {:ok, tag}
  end

  # ...
end

Link to this section Summary

Callbacks

Signs a message by generating a tag with the given key. Will return a type of the form {:ok, tag} if successful or :error otherwise.

Similar to sign/3 except that is returns the tag directly and raises Apoc.Error in the case of an error.

Verifies a message based on a tag generated by sign/3 (or sign!/3). Returns true or false.

Link to this section Types

Link to this section Callbacks

Link to this callback

sign(message, key, opts)

View Source

Specs

sign(message :: iodata(), key :: key(), opts :: Keyword.t()) ::
  {:ok, tag()} | :error

Signs a message by generating a tag with the given key. Will return a type of the form {:ok, tag} if successful or :error otherwise.

Link to this callback

sign!(message, key, opts)

View Source

Specs

sign!(message :: iodata(), key :: key(), opts :: Keyword.t()) :: tag()

Similar to sign/3 except that is returns the tag directly and raises Apoc.Error in the case of an error.

Link to this callback

verify(tag, message, key, opts)

View Source

Specs

verify(tag :: tag(), message :: iodata(), key :: key(), opts :: list()) ::
  true | false

Verifies a message based on a tag generated by sign/3 (or sign!/3). Returns true or false.

Example

if MyMac.verify(tag, message, key) do
  do_something(message)
end