File 0612-ssl-Refactor-to-avoid-confusion-of-what-is-the-API.patch of Package erlang

From 82a4931688daca20a14d6be66e7b65f35faca107 Mon Sep 17 00:00:00 2001
From: Ingela Anderton Andin <ingela@erlang.org>
Date: Thu, 15 Dec 2022 16:58:39 +0100
Subject: [PATCH] ssl: Refactor to avoid confusion of what is the API

Add reason without tag for backwards comparability even though it
was not documented!

Closes #6506
---
 lib/ssl/src/ssl.erl | 73 ++++++++++++++++++++++++++++-----------------
 1 file changed, 45 insertions(+), 28 deletions(-)

diff --git a/lib/ssl/src/ssl.erl b/lib/ssl/src/ssl.erl
index 7b42eb84c1..ad5028655d 100644
--- a/lib/ssl/src/ssl.erl
+++ b/lib/ssl/src/ssl.erl
@@ -1408,39 +1408,15 @@ clear_pem_cache() ->
     ssl_pem_cache:clear().
 
 %%---------------------------------------------------------------
--spec format_error({error, Reason}) -> string() when
+-spec format_error(Reason | {error, Reason}) -> string() when
       Reason :: any().
 %%
 %% Description: Creates error string.
 %%--------------------------------------------------------------------
 format_error({error, Reason}) ->
-    format_error(Reason);
-format_error(Reason) when is_list(Reason) ->
-    Reason;
-format_error(closed) ->
-    "TLS connection is closed";
-format_error({tls_alert, {_, Description}}) ->
-    Description;
-format_error({options,{FileType, File, Reason}}) when FileType == cacertfile;
-						      FileType == certfile;
-						      FileType == keyfile;
-						      FileType == dhfile ->
-    Error = file_error_format(Reason),
-    file_desc(FileType) ++ File ++ ": " ++ Error;
-format_error({options, {socket_options, Option, Error}}) ->
-    lists:flatten(io_lib:format("Invalid transport socket option ~p: ~s", [Option, format_error(Error)]));
-format_error({options, {socket_options, Option}}) ->
-    lists:flatten(io_lib:format("Invalid socket option: ~p", [Option]));
-format_error({options, Options}) ->
-    lists:flatten(io_lib:format("Invalid TLS option: ~p", [Options]));
-
-format_error(Error) ->
-    case inet:format_error(Error) of
-        "unknown POSIX" ++ _ ->
-            unexpected_format(Error);
-        Other ->
-            Other
-    end.
+    do_format_error(Reason);
+format_error(Reason) ->
+    do_format_error(Reason).
 
 tls_version({3, _} = Version) ->
     Version;
@@ -2712,6 +2688,47 @@ handle_supported_groups_option(Value, Version) when is_list(Value) ->
     end.
 
 
+-spec do_format_error( string()
+                     | closed
+                     | {tls_alert, {_, Description :: string()}}
+                     | {options, Options :: term()}
+                     | {options, {socket_options, Option :: term()}}
+                     | {options, {socket_options, Option :: term(), Error}}
+                     | {options, {FileType, File :: string(), Error}}
+                     | InetError
+                     | OtherReason) -> string()
+              when
+      FileType   :: cacertfile | certfile | keyfile | dhfile,
+      OtherReason     :: term(),
+      InetError :: inet:posix() | system_limit.
+
+do_format_error(Reason) when is_list(Reason) ->
+    Reason;
+do_format_error(closed) ->
+    "TLS connection is closed";
+do_format_error({tls_alert, {_, Description}}) ->
+    Description;
+do_format_error({options,{FileType, File, Reason}}) when FileType == cacertfile;
+						      FileType == certfile;
+                                                         FileType == keyfile;
+						      FileType == dhfile ->
+    Error = file_error_format(Reason),
+    file_desc(FileType) ++ File ++ ": " ++ Error;
+do_format_error ({options, {socket_options, Option, Error}}) ->
+    lists:flatten(io_lib:format("Invalid transport socket option ~p: ~s", [Option, do_format_error(Error)]));
+do_format_error({options, {socket_options, Option}}) ->
+    lists:flatten(io_lib:format("Invalid socket option: ~p", [Option]));
+do_format_error({options, Options}) ->
+    lists:flatten(io_lib:format("Invalid TLS option: ~p", [Options]));
+
+do_format_error(Error) ->
+    case inet:format_error(Error) of
+        "unknown POSIX" ++ _ ->
+            unexpected_format(Error);
+        Other ->
+            Other
+    end.
+
 unexpected_format(Error) ->
     lists:flatten(io_lib:format("Unexpected error: ~p", [Error])).
 
-- 
2.35.3

openSUSE Build Service is sponsored by