P11ex.Flags (p11ex v0.1.1)

Handles conversion between PKCS#11 flags (CK_FLAGS) and MapSets of atoms.

Summary

Functions

Returns all possible flags for the given type.

Converts a MapSet of atoms to a flags integer for the given flag type.

Converts a flags integer to a MapSet of atoms for the given flag type.

Types

flag_name()

@type flag_name() :: atom()

flag_type()

@type flag_type() :: :slot | :token | :mechanism

flag_value()

@type flag_value() :: non_neg_integer()

Functions

available_flags(type)

@spec available_flags(flag_type()) :: [flag_name()]

Returns all possible flags for the given type.

Examples

iex> P11ex.Flags.available_flags(:slot)
[:hw_slot, :removable_device, :token_present]

from_atoms(type, flag_set)

@spec from_atoms(flag_type(), MapSet.t(flag_name())) :: flag_value()

Converts a MapSet of atoms to a flags integer for the given flag type.

Examples

iex> P11ex.Flags.from_atoms(:slot, MapSet.new([:hw_slot, :removable_device]))
0x0003

to_atoms(type, flags)

@spec to_atoms(flag_type(), flag_value()) :: MapSet.t(flag_name())

Converts a flags integer to a MapSet of atoms for the given flag type.

Examples

iex> P11ex.Flags.to_atoms(:slot, 0x0003)
#MapSet<[:hw_slot, :removable_device]>