Skip to content

📦 An Elixir utility to calculate the digest for any primitive type

License

Notifications You must be signed in to change notification settings

glossia/digester

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Digester

Digester Hex.pm Hex.pm Hex.pm Hex.pm License: MIT

Digester provides a set of utilities for obtaining digests from Elixir primitives. Digests are useful to determine if a value has changed, for example, in a cache.

Installation

The package can be installed by adding digester to your list of dependencies in mix.exs:

def deps do
  [
    {:digester, "~> 0.2.0"}
  ]
end

Usage

To obtain a digest from a value or a set of values, you'll have to first create an instance of Digester:

digester = Digester.new() # Defaults to the SHA256 algorithm

# You can specify the algorithm to use
digester = Digester.new(:sha256)

Then, you can use Digester.combine/2 for every value you'd like to include in the digest:

digester = digester
  |> Digester.combine("foo")
  |> Digester.combine(%{bar: "baz"})

Remember that the order in which you combine values matters, so the following will produce a different digest:

digester = digester
  |> Digester.combine(%{bar: "baz"})
  |> Digester.combine("foo")

Finally, you can obtain the digest by calling Digester.finalize/1:

digest = Digester.finalize(digester)

digest will be a String containing the digest of the values you combined.