@@ -88,7 +88,32 @@ pub fn check_email_size(raw_email: &[u8]) -> Result<(), EmailError> {
8888
8989impl From < EmailError > for crate :: error:: JacsError {
9090 fn from ( e : EmailError ) -> Self {
91- crate :: error:: JacsError :: CryptoError ( e. to_string ( ) )
91+ use crate :: error:: JacsError ;
92+ match & e {
93+ // Crypto-related errors
94+ EmailError :: SignatureVerificationFailed ( _)
95+ | EmailError :: AlgorithmMismatch ( _) => JacsError :: CryptoError ( e. to_string ( ) ) ,
96+
97+ // Validation / malformed-input errors
98+ EmailError :: InvalidEmailFormat ( _)
99+ | EmailError :: CanonicalizationFailed ( _)
100+ | EmailError :: MissingJacsSignature
101+ | EmailError :: InvalidJacsDocument ( _)
102+ | EmailError :: ContentTampered ( _)
103+ | EmailError :: EmailTooLarge { .. }
104+ | EmailError :: UnsupportedFeature ( _) => JacsError :: ValidationError ( e. to_string ( ) ) ,
105+
106+ // Document / structural errors
107+ EmailError :: ChainVerificationFailed ( _) => JacsError :: DocumentError ( e. to_string ( ) ) ,
108+
109+ // Network / registry errors
110+ EmailError :: SignerKeyNotFound ( _)
111+ | EmailError :: DNSVerificationFailed ( _) => JacsError :: NetworkError ( e. to_string ( ) ) ,
112+
113+ // Identity / trust errors
114+ EmailError :: IdentityMismatch ( _)
115+ | EmailError :: ReplayDetected ( _) => JacsError :: TrustError ( e. to_string ( ) ) ,
116+ }
92117 }
93118}
94119
@@ -219,9 +244,33 @@ mod tests {
219244
220245 #[ test]
221246 fn email_error_converts_to_jacs_error ( ) {
222- let email_err = EmailError :: MissingJacsSignature ;
223- let jacs_err: crate :: error:: JacsError = email_err. into ( ) ;
224- let msg = format ! ( "{}" , jacs_err) ;
225- assert ! ( msg. contains( "Missing jacs-signature.json" ) ) ;
247+ // Validation errors
248+ let jacs_err: crate :: error:: JacsError = EmailError :: MissingJacsSignature . into ( ) ;
249+ assert ! (
250+ matches!( jacs_err, crate :: error:: JacsError :: ValidationError ( _) ) ,
251+ "MissingJacsSignature should map to ValidationError, got: {:?}" ,
252+ jacs_err
253+ ) ;
254+ assert ! ( format!( "{}" , jacs_err) . contains( "Missing jacs-signature.json" ) ) ;
255+
256+ // Crypto errors
257+ let jacs_err: crate :: error:: JacsError =
258+ EmailError :: SignatureVerificationFailed ( "bad sig" . into ( ) ) . into ( ) ;
259+ assert ! ( matches!( jacs_err, crate :: error:: JacsError :: CryptoError ( _) ) ) ;
260+
261+ // Network errors
262+ let jacs_err: crate :: error:: JacsError =
263+ EmailError :: DNSVerificationFailed ( "timeout" . into ( ) ) . into ( ) ;
264+ assert ! ( matches!( jacs_err, crate :: error:: JacsError :: NetworkError ( _) ) ) ;
265+
266+ // Trust errors
267+ let jacs_err: crate :: error:: JacsError =
268+ EmailError :: IdentityMismatch ( "wrong issuer" . into ( ) ) . into ( ) ;
269+ assert ! ( matches!( jacs_err, crate :: error:: JacsError :: TrustError ( _) ) ) ;
270+
271+ // Document errors
272+ let jacs_err: crate :: error:: JacsError =
273+ EmailError :: ChainVerificationFailed ( "broken link" . into ( ) ) . into ( ) ;
274+ assert ! ( matches!( jacs_err, crate :: error:: JacsError :: DocumentError ( _) ) ) ;
226275 }
227276}
0 commit comments