From c5f3ed626b0735391bc89dd2ad508b68153ff3e1 Mon Sep 17 00:00:00 2001 From: felipe stival <14948182+v0idpwn@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:40:05 -0300 Subject: [PATCH] Check whether CAStore is available in compile-time (#428) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes the cost of calling Code.ensure_loaded?/1 every time that credentials are not provided. Co-authored-by: Eric Meadows-Jönsson --- lib/mint/core/transport/ssl.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/mint/core/transport/ssl.ex b/lib/mint/core/transport/ssl.ex index 82569324..ed921908 100644 --- a/lib/mint/core/transport/ssl.ex +++ b/lib/mint/core/transport/ssl.ex @@ -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 \ @@ -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)}