Skip to content

Commit

Permalink
Check whether CAStore is available in compile-time (#428)
Browse files Browse the repository at this point in the history
Removes the cost of calling Code.ensure_loaded?/1 every time that
credentials are not provided.

Co-authored-by: Eric Meadows-J枚nsson <eric.meadows.jonsson@gmail.com>
  • Loading branch information
v0idpwn and ericmj committed Apr 17, 2024
1 parent 530ba27 commit c5f3ed6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/mint/core/transport/ssl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,12 @@ defmodule Mint.Core.Transport.SSL do
defp blocked_cipher?({kex, cipher, _mac, prf}), do: blocked_cipher?({kex, cipher, prf})
defp blocked_cipher?({_kex, _cipher, _prf} = suite), do: suite in @blocked_ciphers

defp raise_on_missing_castore! do
Code.ensure_loaded?(CAStore) ||
if Code.ensure_loaded?(CAStore) do
defp raise_on_missing_castore! do
:ok
end
else
defp raise_on_missing_castore! do
raise """
default CA trust store not available; please add `:castore` to your project's \
dependencies or specify the trust store using the :cacertfile/:cacerts option \
Expand All @@ -714,6 +718,7 @@ defmodule Mint.Core.Transport.SSL do
See: https://www.erlang.org/blog/my-otp-25-highlights/#ca-certificates-can-be-fetched-from-the-os-standard-place
"""
end
end

defp wrap_err({:error, reason}), do: {:error, wrap_error(reason)}
Expand Down

0 comments on commit c5f3ed6

Please sign in to comment.