IOS-1480 Move DecryptMessageOperation. IOS-1480
authorDirk Zimmermann <dz@pep.security>
Mon, 18 Feb 2019 13:21:12 +0100
branchIOS-1480
changeset 768179a41247e650
parent 7680 40a77c0f755b
child 7682 7b526543c7b0
IOS-1480 Move DecryptMessageOperation.
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOS/Background/DecryptMessageOperation.swift
     1.1 --- a/pEpForiOS.xcodeproj/project.pbxproj	Mon Feb 18 13:21:12 2019 +0100
     1.2 +++ b/pEpForiOS.xcodeproj/project.pbxproj	Mon Feb 18 13:21:12 2019 +0100
     1.3 @@ -199,7 +199,6 @@
     1.4  		15D7D992219B154000A1A2B9 /* Attachment+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15D7D991219B154000A1A2B9 /* Attachment+Extensions.swift */; };
     1.5  		15D7D995219B2C5C00A1A2B9 /* ComposeViewModel+InitDataTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15D7D994219B2C5C00A1A2B9 /* ComposeViewModel+InitDataTest.swift */; };
     1.6  		15D7D997219C374600A1A2B9 /* ComposeViewModelStateTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15D7D996219C374600A1A2B9 /* ComposeViewModelStateTest.swift */; };
     1.7 -		15DD3F75211EC68D00A8714D /* DecryptMessageOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15DD3F74211EC68D00A8714D /* DecryptMessageOperation.swift */; };
     1.8  		15EBE43B20E5286500268859 /* unittest_ios_4_peptest_ch_66AF_5804_A879_1E01_B407_125A_CAF0_D838_1542_49C4_sec.asc in Resources */ = {isa = PBXBuildFile; fileRef = 15EBE43920E5286500268859 /* unittest_ios_4_peptest_ch_66AF_5804_A879_1E01_B407_125A_CAF0_D838_1542_49C4_sec.asc */; };
     1.9  		15EBE43E20E5296900268859 /* unittest_ios_4_peptest_ch_66AF_5804_A879_1E01_B407_125A_CAF0_D838_1542_49C4_pub.asc in Resources */ = {isa = PBXBuildFile; fileRef = 15EBE43C20E5296900268859 /* unittest_ios_4_peptest_ch_66AF_5804_A879_1E01_B407_125A_CAF0_D838_1542_49C4_pub.asc */; };
    1.10  		15EBE44220E5353E00268859 /* unittest_ios_3_peptest_ch_550A_9E62_6822_040E_57CB_151A_651C_4A5D_B15B_77A3_pub.asc in Resources */ = {isa = PBXBuildFile; fileRef = 15EBE44020E5353D00268859 /* unittest_ios_3_peptest_ch_550A_9E62_6822_040E_57CB_151A_651C_4A5D_B15B_77A3_pub.asc */; };
    1.11 @@ -748,7 +747,6 @@
    1.12  		15D7D991219B154000A1A2B9 /* Attachment+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Attachment+Extensions.swift"; sourceTree = "<group>"; };
    1.13  		15D7D994219B2C5C00A1A2B9 /* ComposeViewModel+InitDataTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ComposeViewModel+InitDataTest.swift"; sourceTree = "<group>"; };
    1.14  		15D7D996219C374600A1A2B9 /* ComposeViewModelStateTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeViewModelStateTest.swift; sourceTree = "<group>"; };
    1.15 -		15DD3F74211EC68D00A8714D /* DecryptMessageOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecryptMessageOperation.swift; sourceTree = "<group>"; };
    1.16  		15EBE43920E5286500268859 /* unittest_ios_4_peptest_ch_66AF_5804_A879_1E01_B407_125A_CAF0_D838_1542_49C4_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = unittest_ios_4_peptest_ch_66AF_5804_A879_1E01_B407_125A_CAF0_D838_1542_49C4_sec.asc; sourceTree = "<group>"; };
    1.17  		15EBE43C20E5296900268859 /* unittest_ios_4_peptest_ch_66AF_5804_A879_1E01_B407_125A_CAF0_D838_1542_49C4_pub.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = unittest_ios_4_peptest_ch_66AF_5804_A879_1E01_B407_125A_CAF0_D838_1542_49C4_pub.asc; sourceTree = "<group>"; };
    1.18  		15EBE44020E5353D00268859 /* unittest_ios_3_peptest_ch_550A_9E62_6822_040E_57CB_151A_651C_4A5D_B15B_77A3_pub.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = unittest_ios_3_peptest_ch_550A_9E62_6822_040E_57CB_151A_651C_4A5D_B15B_77A3_pub.asc; sourceTree = "<group>"; };
    1.19 @@ -1810,7 +1808,6 @@
    1.20  				43D755EA1F25D234006F933A /* MatchUidToMsnOperation.swift */,
    1.21  				154750991FE7C0B4000D8004 /* FetchNumberOfNewMailsOperation.swift */,
    1.22  				150B84C520A5DD0600D8B288 /* UIDCopyOperation.swift */,
    1.23 -				15DD3F74211EC68D00A8714D /* DecryptMessageOperation.swift */,
    1.24  			);
    1.25  			path = Background;
    1.26  			sourceTree = "<group>";
    1.27 @@ -3213,7 +3210,6 @@
    1.28  				001D366020C56524002434EB /* EmailListViewModel+MoveToFolderDelegate.swift in Sources */,
    1.29  				B722EC7A1E5C879000A2B9D5 /* FolderUiProtocols.swift in Sources */,
    1.30  				4307C4721ED826E400A276A4 /* SmtpSendError.swift in Sources */,
    1.31 -				15DD3F75211EC68D00A8714D /* DecryptMessageOperation.swift in Sources */,
    1.32  				A1B50A841CD26FF100B1A997 /* Constants.swift in Sources */,
    1.33  				15D4399C216E698E00EB3933 /* AccountPickerViewModel.swift in Sources */,
    1.34  				43985D0E204438480080FA9A /* AccountSettingsProtocol+Extension.swift in Sources */,
     2.1 --- a/pEpForiOS/Background/DecryptMessageOperation.swift	Mon Feb 18 13:21:12 2019 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,93 +0,0 @@
     2.4 -//
     2.5 -//  DecryptMessageOperation.swift
     2.6 -//  pEp
     2.7 -//
     2.8 -//  Created by Andreas Buff on 11.08.18.
     2.9 -//  Copyright © 2018 p≡p Security S.A. All rights reserved.
    2.10 -//
    2.11 -
    2.12 -import Foundation
    2.13 -
    2.14 -protocol DecryptMessageOperationDelegate: class {
    2.15 -
    2.16 -    /// Called in case a DecryptionResult can be provided.
    2.17 -    ///
    2.18 -    /// - Parameters:
    2.19 -    ///   - sender: reporting decrypt operation
    2.20 -    ///   - didDecryptMessageWithResult: all information we got from the Engine, decrypting
    2.21 -    ///                                  the message.
    2.22 -    func decryptMessageOperation(sender: DecryptMessageOperation,
    2.23 -                                  didDecryptMessageWithResult result:
    2.24 -        DecryptMessageOperation.DecryptionResult)
    2.25 -
    2.26 -    /// Called for any error cases in which no DecryptionResult can be provided.
    2.27 -    ///
    2.28 -    /// - Parameters:
    2.29 -    ///   - sender: reporting decrypt operation
    2.30 -    ///   - error: occured error
    2.31 -    func decryptMessageOperation(sender: DecryptMessageOperation, failed error: Error)
    2.32 -}
    2.33 -
    2.34 -/// Decrypts one message.
    2.35 -class DecryptMessageOperation: Operation {
    2.36 -    struct DecryptionResult {
    2.37 -        /// The original message that might have been modified by the Engine
    2.38 -        let givenMessage: NSDictionary
    2.39 -        /// The decrypted message returned by the engine
    2.40 -        let pEpDecryptedMessage: NSDictionary?
    2.41 -        /// Flags returned by the engine
    2.42 -        let flags: PEP_decrypt_flags
    2.43 -        /// Rating returned by the engine
    2.44 -        let rating: PEP_rating
    2.45 -        /// Keys returned by the Engine
    2.46 -        let keys: NSArray?
    2.47 -    }
    2.48 -
    2.49 -    weak var delegate: DecryptMessageOperationDelegate?
    2.50 -
    2.51 -    let messageToDecrypt: PEPMessageDict
    2.52 -    let flags: PEP_decrypt_flags
    2.53 -
    2.54 -    init(messageToDecrypt: PEPMessageDict, flags: PEP_decrypt_flags,
    2.55 -         delegate: DecryptMessageOperationDelegate) {
    2.56 -        self.messageToDecrypt = messageToDecrypt
    2.57 -        self.flags = flags
    2.58 -        self.delegate = delegate
    2.59 -    }
    2.60 -
    2.61 -    override func main() {
    2.62 -        if isCancelled {
    2.63 -            return
    2.64 -        }
    2.65 -        process()
    2.66 -    }
    2.67 -
    2.68 -    private func process() {
    2.69 -        let inOutMessage = messageToDecrypt.mutableDictionary()
    2.70 -        var inOutFlags = flags
    2.71 -        var keys: NSArray?
    2.72 -        var rating = PEP_rating_undefined
    2.73 -        var pEpDecryptedMessage: NSDictionary? = nil
    2.74 -
    2.75 -        do {
    2.76 -            pEpDecryptedMessage = try PEPSession().decryptMessageDict(inOutMessage,
    2.77 -                                                                      flags: &inOutFlags,
    2.78 -                                                                      rating: &rating,
    2.79 -                                                                      extraKeys: &keys,
    2.80 -                                                                      status: nil)
    2.81 -                as NSDictionary
    2.82 -
    2.83 -            let result = DecryptionResult(givenMessage: inOutMessage,
    2.84 -                                          pEpDecryptedMessage: pEpDecryptedMessage,
    2.85 -                                          flags: inOutFlags,
    2.86 -                                          rating: rating,
    2.87 -                                          keys: keys)
    2.88 -            delegate?.decryptMessageOperation(sender: self, didDecryptMessageWithResult: result)
    2.89 -
    2.90 -        } catch {
    2.91 -            Logger.backendLogger.errorAndCrash("Error decrypting: %{public}@",
    2.92 -                                               error.localizedDescription)
    2.93 -            delegate?.decryptMessageOperation(sender: self, failed: error)
    2.94 -        }
    2.95 -    }
    2.96 -}