Skip to content

Commit c5f3ed6

Browse files
v0idpwnericmj
andauthored
Check whether CAStore is available in compile-time (#428)
Removes the cost of calling Code.ensure_loaded?/1 every time that credentials are not provided. Co-authored-by: Eric Meadows-Jönsson <[email protected]>
1 parent 530ba27 commit c5f3ed6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/mint/core/transport/ssl.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,12 @@ defmodule Mint.Core.Transport.SSL do
702702
defp blocked_cipher?({kex, cipher, _mac, prf}), do: blocked_cipher?({kex, cipher, prf})
703703
defp blocked_cipher?({_kex, _cipher, _prf} = suite), do: suite in @blocked_ciphers
704704

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

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

0 commit comments

Comments
 (0)