@@ -31,11 +31,11 @@ pub fn try_decrypt(
31
31
return Ok ( None ) ;
32
32
} ;
33
33
34
- decrypt_part (
35
- encrypted_data_part ,
36
- private_keyring ,
37
- public_keyring_for_validate ,
38
- )
34
+ let data = encrypted_data_part . get_body_raw ( ) ? ;
35
+
36
+ let ( plain , ret_valid_signatures ) =
37
+ pgp :: pk_decrypt ( data , private_keyring , public_keyring_for_validate ) ? ;
38
+ Ok ( Some ( ( plain , ret_valid_signatures ) ) )
39
39
}
40
40
41
41
pub ( crate ) async fn prepare_decryption (
@@ -204,37 +204,6 @@ fn get_autocrypt_mime<'a, 'b>(mail: &'a ParsedMail<'b>) -> Option<&'a ParsedMail
204
204
}
205
205
}
206
206
207
- /// Returns Ok(None) if nothing encrypted was found.
208
- fn decrypt_part (
209
- mail : & ParsedMail < ' _ > ,
210
- private_keyring : & [ SignedSecretKey ] ,
211
- public_keyring_for_validate : & [ SignedPublicKey ] ,
212
- ) -> Result < Option < ( Vec < u8 > , HashSet < Fingerprint > ) > > {
213
- let data = mail. get_body_raw ( ) ?;
214
-
215
- if has_decrypted_pgp_armor ( & data) {
216
- let ( plain, ret_valid_signatures) =
217
- pgp:: pk_decrypt ( data, private_keyring, public_keyring_for_validate) ?;
218
- return Ok ( Some ( ( plain, ret_valid_signatures) ) ) ;
219
- }
220
-
221
- Ok ( None )
222
- }
223
-
224
- #[ allow( clippy:: indexing_slicing) ]
225
- fn has_decrypted_pgp_armor ( input : & [ u8 ] ) -> bool {
226
- if let Some ( index) = input. iter ( ) . position ( |b| * b > b' ' ) {
227
- if input. len ( ) - index > 26 {
228
- let start = index;
229
- let end = start + 27 ;
230
-
231
- return & input[ start..end] == b"-----BEGIN PGP MESSAGE-----" ;
232
- }
233
- }
234
-
235
- false
236
- }
237
-
238
207
/// Validates signatures of Multipart/Signed message part, as defined in RFC 1847.
239
208
///
240
209
/// Returns the signed part and the set of key
@@ -346,24 +315,6 @@ mod tests {
346
315
use crate :: receive_imf:: receive_imf;
347
316
use crate :: test_utils:: TestContext ;
348
317
349
- #[ test]
350
- fn test_has_decrypted_pgp_armor ( ) {
351
- let data = b" -----BEGIN PGP MESSAGE-----" ;
352
- assert_eq ! ( has_decrypted_pgp_armor( data) , true ) ;
353
-
354
- let data = b" \n -----BEGIN PGP MESSAGE-----" ;
355
- assert_eq ! ( has_decrypted_pgp_armor( data) , true ) ;
356
-
357
- let data = b" -----BEGIN PGP MESSAGE---" ;
358
- assert_eq ! ( has_decrypted_pgp_armor( data) , false ) ;
359
-
360
- let data = b" -----BEGIN PGP MESSAGE-----" ;
361
- assert_eq ! ( has_decrypted_pgp_armor( data) , true ) ;
362
-
363
- let data = b"blas" ;
364
- assert_eq ! ( has_decrypted_pgp_armor( data) , false ) ;
365
- }
366
-
367
318
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
368
319
async fn test_mixed_up_mime ( ) -> Result < ( ) > {
369
320
// "Mixed Up" mail as received when sending an encrypted
0 commit comments