VulnCheck.ErlTerm (VulnCheck v1.0.1)

Copy Markdown View Source

Atom-safe reader for Erlang term files such as .app, .app.src, rebar.lock and rebar.config.

:file.consult/1 would intern every atom found in third-party files. This reader instead produces the same neutral representation as VulnCheck.Literal:

  • atoms become {:atom, "name"}
  • tuples become {:tuple, [elements]}
  • maps become {:map, [{key, value}]}
  • strings ("...") and binaries (<<"...">>) become Elixir binaries
  • numbers and lists are kept as they are

Only data terms are supported; funs, records with expressions and macros are rejected with {:error, reason}.

Summary

Functions

Extracts atom names from a list of atom terms, ignoring other terms.

Parses all dot-terminated terms contained in source.

Reads and parses a file of dot-terminated Erlang terms.

Looks up key in a proplist of {:tuple, [{:atom, key}, value]} entries.

Types

term_t()

@type term_t() ::
  {:atom, String.t()}
  | {:tuple, [term_t()]}
  | {:map, [{term_t(), term_t()}]}
  | [term_t()]
  | binary()
  | number()

Functions

atom_names(list)

@spec atom_names(term()) :: [String.t()]

Extracts atom names from a list of atom terms, ignoring other terms.

parse(source)

@spec parse(binary()) :: {:ok, [term_t()]} | {:error, String.t()}

Parses all dot-terminated terms contained in source.

parse_file(path)

@spec parse_file(Path.t()) :: {:ok, [term_t()]} | {:error, String.t()}

Reads and parses a file of dot-terminated Erlang terms.

proplist_get(list, key, default \\ nil)

@spec proplist_get([term_t()] | term_t(), String.t(), term()) :: term()

Looks up key in a proplist of {:tuple, [{:atom, key}, value]} entries.