@@ -371,16 +371,35 @@ impl Receiver<Initialized> {
371371 SessionEvent ,
372372 Receiver < UncheckedOriginalPayload > ,
373373 Receiver < Initialized > ,
374- Error ,
374+ ProtocolError ,
375375 > {
376376 let current_state = self . clone ( ) ;
377377 let proposal = match self . inner_process_res ( body, context) {
378378 Ok ( proposal) => proposal,
379- Err ( e) =>
380- return MaybeFatalTransitionWithNoResults :: fatal (
381- SessionEvent :: SessionInvalid ( e. to_string ( ) , None ) ,
382- e,
383- ) ,
379+ Err ( e) => match e {
380+ // Implementation errors should be unreachable
381+ ProtocolError :: V2 ( ref session_error) => match session_error {
382+ SessionError ( InternalSessionError :: DirectoryResponse ( directory_error) ) =>
383+ if directory_error. is_fatal ( ) {
384+ return MaybeFatalTransitionWithNoResults :: fatal (
385+ SessionEvent :: SessionInvalid ( e. to_string ( ) , None ) ,
386+ e,
387+ ) ;
388+ } else {
389+ return MaybeFatalTransitionWithNoResults :: transient ( e) ;
390+ } ,
391+ _ =>
392+ return MaybeFatalTransitionWithNoResults :: fatal (
393+ SessionEvent :: SessionInvalid ( session_error. to_string ( ) , None ) ,
394+ e,
395+ ) ,
396+ } ,
397+ _ =>
398+ return MaybeFatalTransitionWithNoResults :: fatal (
399+ SessionEvent :: SessionInvalid ( e. to_string ( ) , None ) ,
400+ e,
401+ ) ,
402+ } ,
384403 } ;
385404
386405 if let Some ( ( proposal, reply_key) ) = proposal {
@@ -403,9 +422,9 @@ impl Receiver<Initialized> {
403422 self ,
404423 body : & [ u8 ] ,
405424 context : ohttp:: ClientResponse ,
406- ) -> Result < Option < ( OriginalPayload , Option < HpkePublicKey > ) > , Error > {
425+ ) -> Result < Option < ( OriginalPayload , Option < HpkePublicKey > ) > , ProtocolError > {
407426 let body = match process_get_res ( body, context)
408- . map_err ( InternalSessionError :: DirectoryResponse ) ?
427+ . map_err ( |e| ProtocolError :: V2 ( InternalSessionError :: DirectoryResponse ( e ) . into ( ) ) ) ?
409428 {
410429 Some ( body) => body,
411430 None => return Ok ( None ) ,
@@ -442,12 +461,13 @@ impl Receiver<Initialized> {
442461 fn extract_proposal_from_v2 (
443462 self ,
444463 response : Vec < u8 > ,
445- ) -> Result < ( OriginalPayload , HpkePublicKey ) , Error > {
464+ ) -> Result < ( OriginalPayload , HpkePublicKey ) , ProtocolError > {
446465 let ( payload_bytes, reply_key) =
447- decrypt_message_a ( & response, self . session_context . receiver_key . secret_key ( ) . clone ( ) ) ?;
466+ decrypt_message_a ( & response, self . session_context . receiver_key . secret_key ( ) . clone ( ) )
467+ . map_err ( |e| ProtocolError :: V2 ( InternalSessionError :: Hpke ( e) . into ( ) ) ) ?;
448468 let payload = std:: str:: from_utf8 ( & payload_bytes)
449469 . map_err ( |e| ProtocolError :: OriginalPayload ( InternalPayloadError :: Utf8 ( e) . into ( ) ) ) ?;
450- self . unchecked_from_payload ( payload) . map_err ( Error :: Protocol ) . map ( |p| ( p, reply_key) )
470+ self . unchecked_from_payload ( payload) . map ( |p| ( p, reply_key) )
451471 }
452472
453473 fn unchecked_from_payload ( self , payload : & str ) -> Result < OriginalPayload , ProtocolError > {
@@ -1052,12 +1072,20 @@ impl Receiver<PayjoinProposal> {
10521072 res : & [ u8 ] ,
10531073 ohttp_context : ohttp:: ClientResponse ,
10541074 ) -> MaybeSuccessTransition < SessionEvent , ( ) , Error > {
1055- match process_post_res ( res, ohttp_context)
1056- . map_err ( |e| InternalSessionError :: DirectoryResponse ( e) . into ( ) )
1057- {
1075+ match process_post_res ( res, ohttp_context) {
10581076 Ok ( _) =>
10591077 MaybeSuccessTransition :: success ( SessionEvent :: Closed ( SessionOutcome :: Success ) , ( ) ) ,
1060- Err ( e) => MaybeSuccessTransition :: transient ( e) ,
1078+ Err ( e) =>
1079+ if e. is_fatal ( ) {
1080+ MaybeSuccessTransition :: fatal (
1081+ SessionEvent :: SessionInvalid ( e. to_string ( ) , None ) ,
1082+ InternalSessionError :: DirectoryResponse ( e) . into ( ) ,
1083+ )
1084+ } else {
1085+ MaybeSuccessTransition :: transient (
1086+ InternalSessionError :: DirectoryResponse ( e) . into ( ) ,
1087+ )
1088+ } ,
10611089 }
10621090 }
10631091}
0 commit comments