11use core:: fmt;
22
3- use super :: ResponseError ;
43use crate :: ohttp:: DirectoryResponseError ;
54use crate :: uri:: url_ext:: ParseReceiverPubkeyParamError ;
65
@@ -75,25 +74,19 @@ pub struct EncapsulationError(InternalEncapsulationError);
7574
7675#[ derive( Debug ) ]
7776pub ( crate ) enum InternalEncapsulationError {
78- /// The response size is not the expected size.
79- InvalidSize ( usize ) ,
80- /// The status code is not the expected status code.
81- UnexpectedStatusCode ( http:: StatusCode ) ,
8277 /// The HPKE failed.
8378 Hpke ( crate :: hpke:: HpkeError ) ,
84- /// The encapsulation failed.
85- Ohttp ( crate :: ohttp :: OhttpEncapsulationError ) ,
79+ /// The directory returned a bad response
80+ DirectoryResponse ( DirectoryResponseError ) ,
8681}
8782
8883impl fmt:: Display for EncapsulationError {
8984 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
9085 use InternalEncapsulationError :: * ;
9186
9287 match & self . 0 {
93- InvalidSize ( size) => write ! ( f, "invalid size: {size}" ) ,
94- UnexpectedStatusCode ( status) => write ! ( f, "unexpected status code: {status}" ) ,
95- Ohttp ( error) => write ! ( f, "OHTTP encapsulation error: {error}" ) ,
9688 Hpke ( error) => write ! ( f, "HPKE error: {error}" ) ,
89+ DirectoryResponse ( e) => write ! ( f, "Directory response error: {e}" ) ,
9790 }
9891 }
9992}
@@ -103,10 +96,8 @@ impl std::error::Error for EncapsulationError {
10396 use InternalEncapsulationError :: * ;
10497
10598 match & self . 0 {
106- InvalidSize ( _) => None ,
107- UnexpectedStatusCode ( _) => None ,
108- Ohttp ( error) => Some ( error) ,
10999 Hpke ( error) => Some ( error) ,
100+ DirectoryResponse ( e) => Some ( e) ,
110101 }
111102 }
112103}
@@ -117,28 +108,6 @@ impl From<InternalEncapsulationError> for EncapsulationError {
117108
118109impl From < InternalEncapsulationError > for super :: ResponseError {
119110 fn from ( value : InternalEncapsulationError ) -> Self {
120- super :: ResponseError :: Validation (
121- super :: InternalValidationError :: V2Encapsulation ( value. into ( ) ) . into ( ) ,
122- )
123- }
124- }
125-
126- impl From < DirectoryResponseError > for EncapsulationError {
127- fn from ( value : DirectoryResponseError ) -> Self {
128- match value {
129- DirectoryResponseError :: InvalidSize ( e) => InternalEncapsulationError :: InvalidSize ( e) ,
130- DirectoryResponseError :: OhttpDecapsulation ( e) => InternalEncapsulationError :: Ohttp ( e) ,
131- DirectoryResponseError :: UnexpectedStatusCode ( e) =>
132- InternalEncapsulationError :: UnexpectedStatusCode ( e) ,
133- }
134- . into ( )
135- }
136- }
137-
138- impl From < DirectoryResponseError > for ResponseError {
139- fn from ( value : DirectoryResponseError ) -> Self {
140- ResponseError :: Validation (
141- super :: InternalValidationError :: V2Encapsulation ( value. into ( ) ) . into ( ) ,
142- )
111+ super :: InternalValidationError :: V2Encapsulation ( value. into ( ) ) . into ( )
143112 }
144113}
0 commit comments