Pasexto.Key (pasexto v0.1.1)

Copy Markdown View Source

Keys are used to build and parse tokens, which are always scoped to a specific PASETO version and purpose.

A Key can be created like so:

iex> key = Pasexto.Key.new(:v4, :local)

If the key material has been created elsewhere it can be provided to Pasexto.Key.new/3:

iex> material = <<201, 3, 44, 87, 98, 136, 53, 5, 211, 173, 138, 220, 3, 167, 157,
  215, 185, 137, 185, 48, 48, 162, 235, 83, 44, 168, 166, 118, 59, 241, 154,
  117>>
iex> key = Pasexto.Key.new(:v4, :local, material)

Summary

Types

The key material.

The protocol purpose for the key.

t()

The protocol version for the key.

Functions

Extracts the key material for a given protocol version and purpose.

Returns key matrial from the provided PEM.

Returns a key for use with the given protocol version and purpose.

Types

material()

@type material() :: term()

The key material.

purpose()

@type purpose() :: :local | :public

The protocol purpose for the key.

t()

@type t() :: %Pasexto.Key{
  material: material(),
  purpose: purpose(),
  version: version()
}

version()

@type version() :: :v1 | :v2 | :v3 | :v4

The protocol version for the key.

Functions

extract(key, version, purpose)

@spec extract(t(), version(), purpose()) ::
  {:ok, material()} | {:error, :invalid_purpose | :invalid_version}

Extracts the key material for a given protocol version and purpose.

Returns an error if the version or purpose do not match that of the key.

material_from_pem(pem, opts \\ [])

@spec material_from_pem(
  binary(),
  keyword()
) :: material()

Returns key matrial from the provided PEM.

Options

  • password - The password for use with encrypted PEMs.

Raises an argument error if the PEM does not contain material that is valid for PASETO protocols.

new(version, purpose, material \\ nil)

@spec new(version(), purpose(), material() | nil) :: t()

Returns a key for use with the given protocol version and purpose.

If the key material is not provided then new material will be made for the selected protocol.

Raises an argument error if invalid key material is provided for a given protocol.