Scenic v0.10.2 Scenic.Cache.Support.Hash 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

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

Link to this type

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

Link to this section Functions

Link to this function

binary(data, type) View Source
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.

Link to this function

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

Calculate the hash of binary data

Returns the hash directly.

Link to this function

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

Link to this function

file!(path, hash_type) View Source
file!(path :: bitstring(), type :: hash_type()) :: bitstring()

Link to this function

verify(data, hash, hash_type) View Source
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
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
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
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