Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Erlang 24 by using mac/3 #9

Merged
merged 2 commits into from
Aug 4, 2021
Merged

Support Erlang 24 by using mac/3 #9

merged 2 commits into from
Aug 4, 2021

Conversation

lucas-nelson
Copy link
Contributor

In Erlang 24, the hmac/4 function has been removed. mac/3 replaces
it, but mac/3 is only available in Erlang >= 22. Support both
depending on what the :crypto module exports.

Also fix a meck-related compile error by updating to the latest
version:

$ mix deps.compile
==> meck (compile)
src/meck_code_gen.erl:182:42: erlang:get_stacktrace/0 is removed; use the new try/catch syntax for retrieving the stack backtrace
Compiling src/meck_code_gen.erl failed:
ERROR: compile failed while processing signaturex/deps/meck: rebar_abort
** (Mix) Could not compile dependency :meck, "elixir/1.12.2/.mix/rebar compile skip_deps=true deps_dir="signaturex/_build/test/lib"" command failed. You can recompile this dependency with "mix deps.compile meck", update it with "mix deps.update meck" or clean it with "mix deps.clean meck"

Also fix a compile warning about the application setup and crypto by
adding extra_applications to the mix.exs file:

warning: :crypto.hash/2 defined in application :crypto is used by the current application but the current application does not depend on :crypto. To fix this, you must do one of:

  1. If :crypto is part of Erlang/Elixir, you must include it under :extra_applications inside "def application" in your mix.exs

  2. If :crypto is a dependency, make sure it is listed under "def deps" in your mix.exs

  3. In case you don't want to add a requirement to :crypto, you may optionally skip this warning by adding [xref: [exclude: [:crypto]]] to your "def project" in mix.exs

  lib/signaturex/crypto_helper.ex:37: Signaturex.CryptoHelper.md5/1

Fixes #8.

In Erlang 24, the `hmac/4` function has been removed. `mac/3` replaces
it, but `mac/3` is only available in Erlang >= 22. Support both
depending on what the `:crypto` module exports.

Also fix a `meck`-related compile error by updating to the latest
version:

```
$ mix deps.compile
==> meck (compile)
src/meck_code_gen.erl:182:42: erlang:get_stacktrace/0 is removed; use the new try/catch syntax for retrieving the stack backtrace
Compiling src/meck_code_gen.erl failed:
ERROR: compile failed while processing signaturex/deps/meck: rebar_abort
** (Mix) Could not compile dependency :meck, "elixir/1.12.2/.mix/rebar compile skip_deps=true deps_dir="signaturex/_build/test/lib"" command failed. You can recompile this dependency with "mix deps.compile meck", update it with "mix deps.update meck" or clean it with "mix deps.clean meck"
```

Also fix a compile warning about the application setup and `crypto` by
adding `extra_applications` to the `mix.exs` file:

```
warning: :crypto.hash/2 defined in application :crypto is used by the current application but the current application does not depend on :crypto. To fix this, you must do one of:

  1. If :crypto is part of Erlang/Elixir, you must include it under :extra_applications inside "def application" in your mix.exs

  2. If :crypto is a dependency, make sure it is listed under "def deps" in your mix.exs

  3. In case you don't want to add a requirement to :crypto, you may optionally skip this warning by adding [xref: [exclude: [:crypto]]] to your "def project" in mix.exs

  lib/signaturex/crypto_helper.ex:37: Signaturex.CryptoHelper.md5/1
```

Fixes #8.
@lucas-nelson
Copy link
Contributor Author

@edgurgel before I bother making a new version in our private hex org, any chance you still monitor this package, are happy with this PR, and are interested in publishing a new official version?

@edgurgel
Copy link
Owner

edgurgel commented Aug 3, 2021

@lucas-nelson yes happy to update and publish a new version!

@edgurgel
Copy link
Owner

edgurgel commented Aug 3, 2021

Thanks!! Will check it out later today!

@edgurgel edgurgel merged commit c99efe6 into edgurgel:master Aug 4, 2021
@edgurgel
Copy link
Owner

edgurgel commented Aug 4, 2021

1.4.0 should be good to go! Thanks for the update! One day I will sort out CI again 🤣

@lucas-nelson lucas-nelson deleted the support-erlang-24-hmac-mac branch August 4, 2021 05:19
lucas-nelson added a commit to blake-education/pusher that referenced this pull request Aug 4, 2021
Related to edgurgel/signaturex#9

This change avoids errors in Erlang 24 like:

```
** (UndefinedFunctionError) function :crypto.hmac/3 is undefined or private
    (crypto 5.0.2) :crypto.hmac(:sha256, "secret", "POST\n/apps/app_id/events\nauth_key=app_key&auth_timestamp=1628030250&auth_version=1.0&body_md5=271e594983d1c002b6a158cc5f9c7d5a")
    (signaturex 1.3.0) lib/signaturex/crypto_helper.ex:7: Signaturex.CryptoHelper.hmac256_to_string/2
    (signaturex 1.3.0) lib/signaturex.ex:88: Signaturex.sign/5
    (pusher 2.2.0) lib/pusher/request_signer.ex:17: Pusher.RequestSigner.sign/5
    (pusher 2.2.0) lib/pusher/http_client.ex:21: Pusher.HttpClient.request/5
    (pusher 2.2.0) lib/pusher.ex:16: Pusher.trigger/5
```

The `crypto` library changed and removed the `hmac` function. The
`1.4.0` version of signaturex contains the workaround. The existing
semver in mix.exs (`1.3.0`) prevents the upgrade (well, you can manually
`override: true` but that's not ideal).
edgurgel pushed a commit to edgurgel/pusher that referenced this pull request Aug 6, 2021
Related to edgurgel/signaturex#9

This change avoids errors in Erlang 24 like:

```
** (UndefinedFunctionError) function :crypto.hmac/3 is undefined or private
    (crypto 5.0.2) :crypto.hmac(:sha256, "secret", "POST\n/apps/app_id/events\nauth_key=app_key&auth_timestamp=1628030250&auth_version=1.0&body_md5=271e594983d1c002b6a158cc5f9c7d5a")
    (signaturex 1.3.0) lib/signaturex/crypto_helper.ex:7: Signaturex.CryptoHelper.hmac256_to_string/2
    (signaturex 1.3.0) lib/signaturex.ex:88: Signaturex.sign/5
    (pusher 2.2.0) lib/pusher/request_signer.ex:17: Pusher.RequestSigner.sign/5
    (pusher 2.2.0) lib/pusher/http_client.ex:21: Pusher.HttpClient.request/5
    (pusher 2.2.0) lib/pusher.ex:16: Pusher.trigger/5
```

The `crypto` library changed and removed the `hmac` function. The
`1.4.0` version of signaturex contains the workaround. The existing
semver in mix.exs (`1.3.0`) prevents the upgrade (well, you can manually
`override: true` but that's not ideal).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Erlang 24 / crypto 5.0 - function :crypto.hmac/3 is undefined or private
2 participants