Skip to content

Commit 270c9b1

Browse files
committed
linting
1 parent f208251 commit 270c9b1

File tree

4 files changed

+60
-53
lines changed

4 files changed

+60
-53
lines changed

implementations/elixir/ockam/ockam/lib/ockam/secure_channel/channel.ex

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -540,47 +540,48 @@ defmodule Ockam.SecureChannel.Channel do
540540
end
541541

542542
defp handle_inner_message_impl(message, %Channel{channel_state: channel_state} = state) do
543-
with {:ok, plaintext, decrypt_st} <-
544-
Decryptor.decrypt("", message.payload, channel_state.decrypt_st) do
545-
case Messages.decode(plaintext) do
546-
{:ok, %Messages.Payload{} = payload} ->
547-
message = struct(Ockam.Message, Map.from_struct(payload))
548-
549-
handle_decrypted_message(message, %Channel{
550-
state
551-
| channel_state: %{channel_state | decrypt_st: decrypt_st}
552-
})
553-
554-
{:ok, :close} ->
555-
Logger.debug("Peer closed secure channel, terminating #{inspect(state.address)}")
556-
{:stop, :normal, channel_state}
557-
558-
## TODO: add tests
559-
{:ok, %Messages.RefreshCredentials{contact: contact, credentials: credentials}} ->
560-
with {:ok, peer_identity, peer_identity_id} <- Identity.validate_contact_data(contact),
561-
true <- peer_identity_id == channel_state.peer_identity_id,
562-
:ok <- process_credentials(credentials, peer_identity_id, state.authorities) do
563-
{:ok,
564-
%Channel{
565-
state
566-
| channel_state: %{
567-
channel_state
568-
| peer_identity: peer_identity,
569-
decrypt_st: decrypt_st
570-
}
571-
}}
572-
else
573-
error ->
574-
Logger.warning("Invalid credential refresh: #{inspect(error)}")
575-
{:stop, {:error, :invalid_credential_refresh}, state}
576-
end
577-
578-
{:error, reason} ->
579-
{:error, reason}
580-
end
581-
else
582-
# The message couldn't be decrypted. State remains unchanged
543+
case Decryptor.decrypt("", message.payload, channel_state.decrypt_st) do
544+
{:ok, plaintext, decrypt_st} ->
545+
case Messages.decode(plaintext) do
546+
{:ok, %Messages.Payload{} = payload} ->
547+
message = struct(Ockam.Message, Map.from_struct(payload))
548+
549+
handle_decrypted_message(message, %Channel{
550+
state
551+
| channel_state: %{channel_state | decrypt_st: decrypt_st}
552+
})
553+
554+
{:ok, :close} ->
555+
Logger.debug("Peer closed secure channel, terminating #{inspect(state.address)}")
556+
{:stop, :normal, channel_state}
557+
558+
## TODO: add tests
559+
{:ok, %Messages.RefreshCredentials{contact: contact, credentials: credentials}} ->
560+
with {:ok, peer_identity, peer_identity_id} <-
561+
Identity.validate_contact_data(contact),
562+
true <- peer_identity_id == channel_state.peer_identity_id,
563+
:ok <- process_credentials(credentials, peer_identity_id, state.authorities) do
564+
{:ok,
565+
%Channel{
566+
state
567+
| channel_state: %{
568+
channel_state
569+
| peer_identity: peer_identity,
570+
decrypt_st: decrypt_st
571+
}
572+
}}
573+
else
574+
error ->
575+
Logger.warning("Invalid credential refresh: #{inspect(error)}")
576+
{:stop, {:error, :invalid_credential_refresh}, state}
577+
end
578+
579+
{:error, reason} ->
580+
{:error, reason}
581+
end
582+
583583
error ->
584+
# The message couldn't be decrypted. State remains unchanged
584585
Logger.warning("Failed to decrypt message, discarded: #{inspect(error)}")
585586
{:ok, state}
586587
end

implementations/elixir/ockam/ockam/lib/ockam/secure_channel/messages.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ defmodule Ockam.SecureChannel.Messages do
7171
end
7272

7373
defmodule PaddedMessage do
74+
@moduledoc """
75+
Top-level secure channel message, with padding support.
76+
"""
7477
use TypedStruct
7578

7679
@enum_schema {:variant_enum,

implementations/elixir/ockam/ockam/lib/ockam/transport/tcp/client.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ defmodule Ockam.Transport.TCP.Client do
166166

167167
@impl true
168168
def handle_message(%{payload: _payload} = message, state) do
169-
Logger.info("Attempting to send #{inspect(message)}")
170-
171169
with :ok <- encode_and_send_over_tcp(message, state) do
172170
{:ok, state}
173171
end

implementations/elixir/ockam/ockam/lib/ockam/transport/tcp/transport_message.ex

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,22 @@ defmodule Ockam.Transport.TCP.TransportMessage do
4646

4747
@spec decode(binary()) :: {:ok, Message.t()} | {:error, any()}
4848
def decode(data) do
49-
with {:ok, msg} <- TCPMessage.decode_strict(data) do
50-
{:ok,
51-
%Message{
52-
onward_route: msg.onward_route,
53-
return_route: msg.return_route,
54-
payload: msg.payload,
55-
local_metadata: %{source: :channel, channel: :tcp, tracing_context: msg.tracing_context}
56-
}}
57-
else
58-
x -> {:error, {:error_decoding_msg, x}}
49+
case TCPMessage.decode_strict(data) do
50+
{:ok, msg} ->
51+
{:ok,
52+
%Message{
53+
onward_route: msg.onward_route,
54+
return_route: msg.return_route,
55+
payload: msg.payload,
56+
local_metadata: %{
57+
source: :channel,
58+
channel: :tcp,
59+
tracing_context: msg.tracing_context
60+
}
61+
}}
62+
63+
error ->
64+
{:error, {:error_decoding_msg, error}}
5965
end
6066
end
6167

@@ -65,7 +71,6 @@ defmodule Ockam.Transport.TCP.TransportMessage do
6571
onward_route: o,
6672
return_route: r,
6773
payload: p,
68-
# payload: :bare.encode(p, :data),
6974
tracing_context: Map.get(l, :tracing_context, nil)
7075
})
7176
end

0 commit comments

Comments
 (0)