@@ -540,47 +540,48 @@ defmodule Ockam.SecureChannel.Channel do
540
540
end
541
541
542
542
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
+
583
583
error ->
584
+ # The message couldn't be decrypted. State remains unchanged
584
585
Logger . warning ( "Failed to decrypt message, discarded: #{ inspect ( error ) } " )
585
586
{ :ok , state }
586
587
end
0 commit comments