resx_dropbox v0.1.0 ResxDropbox.Utility
General helpers.
Dropbox Content Hash
This module provides an implementation of the Dropbox Content Hash. For use externally or with Resx.Resource
.
Link to this section Summary
Functions
Hash the content following the dropbox content hashing algorithm
Finalizes the hash operation referenced by state returned from a previous call to hash_update/2
. The digest will be encoded as a lowercase hexadecimal string as required by the dropbox content hashing algorithm
Initializes the context for streaming hash operations following the dropbox content hashing algorithm
Updates the digest represented by state using the given data. State must have been generated using hash_init/1
or a previous call to this function. Data can be any length. New state must be passed into the next call to hash_update/2
or hash_final/1
A resx resource hasher for the dropbox content hashing algorithm
A resx resource streamable hasher for the dropbox content hashing algorithm
Link to this section Types
algos() :: :crypto.sha1() | :crypto.sha2() | :crypto.sha3() | :crypto.compatibility_only_hash() | :ripemd160
Link to this section Functions
Hash the content following the dropbox content hashing algorithm.
By default the algorithm used is :sha256
as this is the current one used by dropbox, this however can be overridden.
iex> ResxDropbox.Utility.hash("foobar")
"3f2c7ccae98af81e44c0ec419659f50d8b7d48c681e5d57fc747d0461e42dda1"
iex> ResxDropbox.Utility.hash("")
"5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456"
iex> ResxDropbox.Utility.hash(:sha, "foobar")
"9b500343bc52e2911172eb52ae5cf4847604c6e5"
iex> ResxDropbox.Utility.hash(["f", "", [[[[["oo"], [["b"]]], ""], ""], "a"], [[],[]], ["r"]])
ResxDropbox.Utility.hash("foobar")
iex> ResxDropbox.Utility.hash([])
ResxDropbox.Utility.hash("")
Finalizes the hash operation referenced by state returned from a previous call to hash_update/2
. The digest will be encoded as a lowercase hexadecimal string as required by the dropbox content hashing algorithm.
Initializes the context for streaming hash operations following the dropbox content hashing algorithm.
By default the algorithm used is :sha256
as this is the current one used by dropbox, this however can be overridden.
The state can then be passed to hash_update/2
and hash_final/1
.
iex> ResxDropbox.Utility.hash_init |> ResxDropbox.Utility.hash_update("foo") |> ResxDropbox.Utility.hash_update("bar") |> ResxDropbox.Utility.hash_final
"3f2c7ccae98af81e44c0ec419659f50d8b7d48c681e5d57fc747d0461e42dda1"
iex> ResxDropbox.Utility.hash_init |> ResxDropbox.Utility.hash_final
"5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456"
Updates the digest represented by state using the given data. State must have been generated using hash_init/1
or a previous call to this function. Data can be any length. New state must be passed into the next call to hash_update/2
or hash_final/1
.
A resx resource hasher for the dropbox content hashing algorithm.
Generally you'll want to use the streamable_hasher/1
instead.
This can be applied globally as follows:
config :resx,
hash: ResxDropbox.Utility.hasher
Or on individual resources:
iex> Resx.Resource.open!("data:,foobar") |> Resx.Resource.hash(ResxDropbox.Utility.hasher)
{ :dropbox, ResxDropbox.Utility.hash("foobar") }
iex> Resx.Resource.open!("data:,foobar") |> Resx.Resource.hash(ResxDropbox.Utility.hasher(:sha))
{ :dropbox, ResxDropbox.Utility.hash(:sha, "foobar") }
streamable_hasher(algos()) :: Resx.Resource.streamable_hasher()
A resx resource streamable hasher for the dropbox content hashing algorithm.
This can be applied globally as follows:
config :resx,
hash: ResxDropbox.Utility.streamable_hasher
Or on individual resources:
iex> Resx.Resource.open!("data:,foobar") |> Resx.Resource.hash(ResxDropbox.Utility.streamable_hasher)
{ :dropbox, ResxDropbox.Utility.hash("foobar") }
iex> Resx.Resource.open!("data:,foobar") |> Resx.Resource.hash(ResxDropbox.Utility.streamable_hasher(:sha))
{ :dropbox, ResxDropbox.Utility.hash(:sha, "foobar") }