Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
224 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use Mix.Config | ||
|
||
import_config "#{Mix.env}.exs" |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use Mix.Config | ||
|
||
config :cipher, keyphrase: "testiekeyphraseforcipher", | ||
ivphrase: "testieivphraseforcipher", | ||
magic_token: "magictoken" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
use Mix.Config |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use Mix.Config | ||
|
||
config :cipher, keyphrase: "testiekeyphraseforcipher", | ||
ivphrase: "testieivphraseforcipher", | ||
magic_token: "magictoken" |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule Cipher.Digest do | ||
|
||
@moduledoc """ | ||
Some digesting helpers | ||
""" | ||
|
||
@doc "Generates a suitable key for encryption based on given `phrase`" | ||
def generate_key(phrase), do: :crypto.hash(:sha, phrase) |> hexdigest |> String.slice(0,16) | ||
|
||
@doc "Generates a suitable iv for encryption based on given `phrase`" | ||
def generate_iv(phrase), do: phrase |> String.slice(0,16) | ||
|
||
@doc "Gets an usable string from a binary crypto hash" | ||
def hexdigest(binary) do | ||
:lists.flatten(for b <- :erlang.binary_to_list(binary), do: :io_lib.format("~2.16.0B", [b])) | ||
|> :string.to_lower | ||
|> List.to_string | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
defmodule Cipher.Helpers do | ||
|
||
@moduledoc """ | ||
require Cipher.Helpers, as: H # the cool way | ||
""" | ||
@doc """ | ||
Convenience to get environment bits. Avoid all that repetitive | ||
`Application.get_env( :myapp, :blah, :blah)` noise. | ||
""" | ||
def env(key, default \\ nil), do: env(Mix.Project.get!.project[:app], key, default) | ||
def env(app, key, default), do: Application.get_env(app, key, default) | ||
|
||
@doc """ | ||
Spit to output any passed variable, with location information. | ||
""" | ||
defmacro spit(obj \\ "", inspect_opts \\ []) do | ||
quote do | ||
%{file: file, line: line} = __ENV__ | ||
name = Process.info(self)[:registered_name] | ||
chain = [ :bright, :red, "\n\n#{file}:#{line}", | ||
:normal, "\n #{inspect self}", :green," #{name}"] | ||
|
||
msg = inspect(unquote(obj),unquote(inspect_opts)) | ||
if String.length(msg) > 2, do: chain = chain ++ [:red, "\n\n#{msg}"] | ||
|
||
# chain = chain ++ [:yellow, "\n\n#{inspect Process.info(self)}"] | ||
|
||
(chain ++ ["\n\n", :reset]) |> IO.ANSI.format(true) |> IO.puts | ||
|
||
unquote(obj) | ||
end | ||
end | ||
|
||
@doc """ | ||
Print to stdout a _TODO_ message, with location information. | ||
""" | ||
defmacro todo(msg \\ "") do | ||
quote do | ||
%{file: file, line: line} = __ENV__ | ||
[ :yellow, "\nTODO: #{file}:#{line} #{unquote(msg)}\n", :reset] | ||
|> IO.ANSI.format(true) | ||
|> IO.puts | ||
:todo | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ defmodule Cipher.Mixfile do | |
end | ||
|
||
defp deps do | ||
[{:poison, "~> 2.0", only: :test}] | ||
[{:poison, "~> 2.0"}] | ||
end | ||
|
||
end |
Oops, something went wrong.