Skip to content

Commit

Permalink
Introduce ranch_transport:peercert/1 callback
Browse files Browse the repository at this point in the history
  • Loading branch information
juise committed Jan 12, 2022
1 parent 0906ab7 commit c79afa5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ranch_ssl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
-export([controlling_process/2]).
-export([peername/1]).
-export([sockname/1]).
-export([peercert/1]).
-export([shutdown/2]).
-export([close/1]).
-export([cleanup/1]).
Expand Down Expand Up @@ -296,6 +297,11 @@ peername(Socket) ->
sockname(Socket) ->
ssl:sockname(Socket).

-spec peercert(ssl:sslsocket())
-> {ok, public_key:der_encoded()} | {error, any()}.
peercert(Socket) ->
ssl:peercert(Socket).

-spec shutdown(ssl:sslsocket(), read | write | read_write)
-> ok | {error, atom()}.
shutdown(Socket, How) ->
Expand Down
5 changes: 5 additions & 0 deletions src/ranch_tcp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
-export([controlling_process/2]).
-export([peername/1]).
-export([sockname/1]).
-export([peercert/1]).
-export([shutdown/2]).
-export([close/1]).
-export([cleanup/1]).
Expand Down Expand Up @@ -265,6 +266,10 @@ peername(Socket) ->
sockname(Socket) ->
inet:sockname(Socket).

-spec peercert(inet:socket()) -> no_return().
peercert(_Socket) ->
error(not_supported).

-spec shutdown(inet:socket(), read | write | read_write)
-> ok | {error, atom()}.
shutdown(Socket, How) ->
Expand Down
1 change: 1 addition & 0 deletions src/ranch_transport.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
-> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}.
-callback sockname(socket())
-> {ok, {inet:ip_address(), inet:port_number()} | {local, binary()}} | {error, atom()}.
-callback peercert(socket()) -> {ok, public_key:der_encoded()} | {error, any()}.
-callback shutdown(socket(), read | write | read_write)
-> ok | {error, atom()}.
-callback close(socket()) -> ok.
Expand Down
6 changes: 6 additions & 0 deletions test/ranch_erlang_transport.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
-export([controlling_process/2]).
-export([peername/1]).
-export([sockname/1]).
-export([peercert/1]).
-export([shutdown/2]).
-export([close/1]).
-export([cleanup/1]).
Expand Down Expand Up @@ -160,6 +161,11 @@ peername(_Socket) ->
sockname(_Socket) ->
{ok, {{127, 0, 0, 1}, 12710}}.

-spec peercert(reference())
-> no_return().
peercert(_Socket) ->
error(not_supported).

-spec shutdown(reference(), read | write | read_write)
-> ok | {error, atom()}.
shutdown(_Socket, _How) ->
Expand Down

0 comments on commit c79afa5

Please sign in to comment.