diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..efed5f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +ebin/* +.erlang.mk/ +utools.d diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..388a6a7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2022 Umgeher Torgersen + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/src/utools.erl b/src/utools.erl new file mode 100644 index 0000000..822cf7c --- /dev/null +++ b/src/utools.erl @@ -0,0 +1,105 @@ +-module(utools). + +-export([b32_decode/1]). +-export([b32_encode/1]). +-export([hotp/2]). +-export([rand_bytes/0, rand_bytes/1]). +-export([rand_chars/1]). +-export([rand_hash/0]). +-export([totp/1, totp/2]). +-export([totp_generate/0]). + +b32_decode({<>, Bits}) -> + <>; +b32_decode({<>, Bits}) -> + <>; +b32_decode({<>, Bits}) -> + <>; +b32_decode({<>}). + +rand_hash() -> + {ok, R} = rand_chars(64), + {ok, binary:encode_hex(crypto:hash(sha256, <<"utools:rand_hash(", R/binary, ")">>))}. + +totp_generate() -> + rand_chars(16). + +totp(<>) -> + totp(Token, erlang:timestamp()). + +totp(<>, {M, S, _}) -> + T = (M * 1000000 + S) / 30, + Time = trunc(T), + hotp(Token, Time).