Scenic.Cache.Support.Hash (Scenic v0.10.3) View Source

Helper functions to work with hash signatures.

Both the Cache.File and Cache.Term modules use cryptographic hash signatures to verify that files are valid before using the data they contain.

This modules provides a collection of helper functions that make it easy to use, generate and validate these hashes.

Any time one of these functions asks for a type of hash, the supported types are: :sha, :sha224, :sha256, :sha384, :sha512, and :ripemd160

Link to this section Summary

Functions

Calculate the hash of binary data

Calculate the hash of binary data

Compute hash for the given file

Verify that the given data conforms to the given hash.

Verify that the given data conforms to the given hash.

Verify that the data in a file conforms to the given hash.

Verify that the data in a file conforms to the given hash.

Link to this section Types

Specs

hash_type() :: :sha | :sha224 | :sha256 | :sha384 | :sha512 | :ripemd160

Link to this section Functions

Specs

binary(data :: binary(), type :: hash_type()) ::
  {:ok, bitstring()} | {:error, :invalid_hash_type}

Calculate the hash of binary data

Returns the hash wrapped in a {:ok, hash} tuple.

Specs

binary!(data :: binary(), type :: hash_type()) :: bitstring()

Calculate the hash of binary data

Returns the hash directly.

Link to this function

compute_file(path, hash_type)

View Source

Compute hash for the given file

Specs

file(path :: bitstring(), type :: hash_type()) ::
  {:ok, bitstring()} | {:error, :invalid_hash_type}
file(path :: bitstring(), type :: hash_type()) ::
  {:ok, bitstring()} | {:error, :invalid_hash_type}

Specs

file!(path :: bitstring(), type :: hash_type()) :: bitstring()
Link to this function

verify(data, hash, hash_type)

View Source

Specs

verify(data :: binary(), hash :: bitstring(), type :: hash_type()) ::
  {:ok, binary()} | {:error, :hash_failure}

Verify that the given data conforms to the given hash.

If the verification passes, returns {:ok, data} If it fails, returns {:error, :hash_failure}

Link to this function

verify!(data, hash, hash_type)

View Source

Specs

verify!(data :: binary(), hash :: bitstring(), type :: hash_type()) ::
  binary() | no_return()

Verify that the given data conforms to the given hash.

If the verification passes, returns the data unchanged. If it fails, raises an error

Link to this function

verify_file(path, hash, hash_type)

View Source

Specs

verify_file(path :: bitstring(), hash :: bitstring(), type :: hash_type()) ::
  {:ok, binary()} | {:error, :hash_failure}

Verify that the data in a file conforms to the given hash.

If the verification passes, returns {:ok, hash} If it fails, returns {:error, :hash_failure}

Link to this function

verify_file!(path, hash, hash_type)

View Source

Specs

verify_file!(path :: bitstring(), hash :: bitstring(), type :: hash_type()) ::
  binary() | no_return()

Verify that the data in a file conforms to the given hash.

If the verification passes, returns the hash unchanged. If it fails, raises an error