From 009f4c54dc756313e08691469a479f137f89f23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20Smedsga=CC=8Ard?= Date: Mon, 1 Jul 2024 15:07:09 +0200 Subject: [PATCH 1/2] Make hmac crypto calls compatible with OTP23 and later --- src/ejwt.erl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ejwt.erl b/src/ejwt.erl index e4918ac..b559cb9 100644 --- a/src/ejwt.erl +++ b/src/ejwt.erl @@ -6,6 +6,13 @@ -module(ejwt). +-define(OLD_CRYPTO_API, true). +-ifdef(OTP_RELEASE). + -if(?OTP_RELEASE >= 23). + -undef(OLD_CRYPTO_API). + -endif. + -endif. + -define(HS256, <<"HS256">>). -define(HS384, <<"HS384">>). -define(HS512, <<"HS512">>). @@ -37,12 +44,21 @@ encode(Payload, Key, Algorithm) -> -spec get_mac(Key :: key(), Data :: binary(), Method :: binary()) -> binary(). +-ifdef(OLD_CRYPTO_API). get_mac(Key, Data, ?HS256) -> crypto:hmac(sha256, Key, Data); get_mac(Key, Data, ?HS384) -> crypto:hmac(sha384, Key, Data); get_mac(Key, Data, ?HS512) -> crypto:hmac(sha512, Key, Data). +-else. +get_mac(Key, Data, ?HS256) -> + crypto:mac(hmac, sha256, Key, Data); +get_mac(Key, Data, ?HS384) -> + crypto:mac(hmac, sha384, Key, Data); +get_mac(Key, Data, ?HS512) -> + crypto:mac(hmac, sha512, Key, Data). +-endif. -spec decode(JWT :: binary()) -> list() | error. From 3b502ab5296f91f354ddd1a7fdcd721abf3eff75 Mon Sep 17 00:00:00 2001 From: jonatansmedsgard <104216809+jonatansmedsgard@users.noreply.github.com> Date: Mon, 1 Jul 2024 15:15:08 +0200 Subject: [PATCH 2/2] Create erlang.yml --- .github/workflows/erlang.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/erlang.yml diff --git a/.github/workflows/erlang.yml b/.github/workflows/erlang.yml new file mode 100644 index 0000000..4a800c0 --- /dev/null +++ b/.github/workflows/erlang.yml @@ -0,0 +1,26 @@ +name: Erlang CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + + build: + + runs-on: ubuntu-latest + + container: + image: erlang:27 + + steps: + - uses: actions/checkout@v4 + - name: Compile + run: rebar3 compile + - name: Run tests + run: rebar3 do eunit, ct