-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/2017.04.11_add-token-helpers (#8)
* style * add helpers for symmetric crypto tokens - add module - add test * set log level to debug for tests * use binary patters in tokens rather than string separator * add some debug logging * add more specific debug logging messages for timestamp validation * add tests for tokens that are too old or in the future * add initialization vector * clean up tests * add doc tests and update module docs * add update/4 and update docs * add test for update/4 * add universal_time helper * remove Timex * update deps * update dialyxir * fix dialyzer errors * clean up code and fix dialyzer errors * add applications so dialyzer can find them * fix specs to make dialyzer happy * fix compiler warnings * update version to 0.4.0 * fix compiler warnings * fix compiler warnings * remove Pipe * remove pipe * remove pipe * update changelog
- Loading branch information
Showing
14 changed files
with
509 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
defmodule ExCrypto.Hash do | ||
def sha256(data) do | ||
{:ok, :crypto.hash(:sha256, data)} | ||
try do | ||
{:ok, :crypto.hash(:sha256, data)} | ||
rescue | ||
e in ArgumentError -> {:error, e} | ||
end | ||
end | ||
|
||
def sha256!(data) do | ||
case sha256(data) do | ||
{:ok, digest} -> digest | ||
{:error, reason} -> raise "sha256 error" | ||
{:error, reason} -> raise "sha256 error: #{inspect reason}" | ||
end | ||
end | ||
|
||
def sha512(data) do | ||
{:ok, :crypto.hash(:sha512, data)} | ||
try do | ||
{:ok, :crypto.hash(:sha512, data)} | ||
rescue | ||
e in ArgumentError -> {:error, e} | ||
end | ||
end | ||
|
||
def sha512!(data) do | ||
case sha512(data) do | ||
{:ok, digest} -> digest | ||
{:error, reason} -> raise "sha512 error" | ||
{:error, reason} -> raise "sha512 error: #{inspect reason}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.