View Source Digester (digester v0.3.0)
This module represents a utility to calculate a digest deterministically from a set of values. If the order of the elements or their values change, the hash will change.
This module is useful to support incremental localization based on the hash of the content and the context it depends on.
Summary
Functions
Combines the given digestable with the current digester. Note that the order of the digestables is important. If the same digestables are combined but in a different order, the resulting digest will be different.
It finalizes the digester and returns the digest as a string.
Creates a new digester with the given options.
Types
@type new_opts() :: [{:algorithm, atom()}]
Functions
@spec combine( digester :: t(), digestable :: atom() | binary() | struct() | number() | tuple() | map() ) :: t()
@spec combine(digester :: t(), digestable :: binary()) :: t()
@spec combine(digester :: t(), digestable :: atom()) :: t()
@spec combine(digester :: t(), digestable :: number()) :: t()
@spec combine(digester :: t(), digestable :: list()) :: t()
@spec combine(digester :: t(), digestable :: tuple()) :: t()
@spec combine(digester :: t(), digestable :: map()) :: t()
@spec combine(digester :: t(), digestable :: map()) :: t()
@spec combine(digester :: t(), digestable :: struct()) :: t()
Combines the given digestable with the current digester. Note that the order of the digestables is important. If the same digestables are combined but in a different order, the resulting digest will be different.
It finalizes the digester and returns the digest as a string.
Examples
iex> digester = Digester.new() |> Digester.combine("Hello") |> Digester.combine("World")
%Digester{algorithm: :sha256, digestables: ["78ae647dc5544d227130a0682a51e30bc7777fbb6d8a8f17007463a3ecd1d524", "185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969"]}
iex> Digester.finalize(digester)
"c79df18bcbce0d9501007f33555ef01b9724f0a986b0dc7d872400bd33053a2e"
Creates a new digester with the given options.
Options
:algorithm
- The algorithm to use for hashing. Defaults to:sha256
.
Examples
iex> Digester.new()
%Digester{algorithm: :sha256, digestables: []}