diff --git a/enzevalos_iphone/CryptoObject.swift b/enzevalos_iphone/CryptoObject.swift index 9a2a0cad36324382d16bbb1135f0ce166c3d215d..a3761a328ea58d008eeeab861deac9ba4655ed96 100644 --- a/enzevalos_iphone/CryptoObject.swift +++ b/enzevalos_iphone/CryptoObject.swift @@ -6,226 +6,6 @@ // import Foundation -import SwiftUI - -struct SecurityState <M: DisplayMail> { - enum CryptoState { - case UnableToDecrypt, InvalidSignature, NoCrypto, PlainMissingPublicKeyToVerify, PlainButValidSignature, EncValidSign, EncNoSignature, EncButMissingPublicKeyToVerify - } - - let mail: M - - /* TODO: MORE DIALOGS - //else if (mail.isNewPubKey) && !(mail.deleteWhileTravel){} - // message contained new public key - } - - */ - - var title: String { - get { - var key = "" - switch evaluateSecurity() { - case (_,.NoCrypto): key = "Security.Dialog.Title.No.Crypto" - case (_, .UnableToDecrypt): key = "Security.Dialog.Title.UnableToDecrypt" - case (_, .InvalidSignature): key = "Security.Dialog.Title.InvalidSignature" - case (_, .PlainMissingPublicKeyToVerify): key = "Security.Dialog.Title.PlainMissingPublicKeyToVerify" - case (_, .PlainButValidSignature): key = "Security.Dialog.Title.Plain+Sig" - case (_, .EncValidSign): key = "Security.Dialog.Title.Enc+Sign" - case (_, .EncNoSignature): key = "Security.Dialog.Title.Enc+NoSign" - case (_, .EncButMissingPublicKeyToVerify): key = "Security.Dialog.Title.EncMissingPublicKeyToVerify" - } - return NSLocalizedString(key, comment: "") - } - } - - var icon: Image { - get { - switch evaluateSecurity() { - case (_, .EncValidSign): - return StudySettings.securityIndicator.imageOfSecureIndicatorSwiftUI() - case (_, .UnableToDecrypt), (_, .InvalidSignature): - return StudySettings.securityIndicator.imageOfCorruptedIndicatorSwiftUI() - case (_, .NoCrypto), (_, .PlainMissingPublicKeyToVerify), (_, .PlainButValidSignature), (_, .EncNoSignature), (_, .EncButMissingPublicKeyToVerify): - return StudySettings.securityIndicator.imageOfInsecureIndicatorSwiftUI() - } - } - } - - var titleIcon: UIImage { - get { - switch evaluateSecurity() { - case (_, .EncValidSign): - return StudySettings.securityIndicator.imageOfSecureIndicator() - case (_, .UnableToDecrypt), (_, .InvalidSignature): - return StudySettings.securityIndicator.imageOfCorruptedIndicator() - case (_, .NoCrypto), (_, .PlainMissingPublicKeyToVerify), (_, .PlainButValidSignature), (_, .EncNoSignature), (_, .EncButMissingPublicKeyToVerify): - return StudySettings.securityIndicator.imageOfInsecureIndicator() - } - } - } - - var dialog: DialogStruct { - get { - // TODO: Do we add new public key stuff? - var color: UIColor - var bodyKey: String - let infoTitle = NSLocalizedString("Security.Dialog.Button.Title.MoreInfo", comment: "") - - var ctaButtonTitleKey: String = "Security.Dialog.Button.Title.OK" - var ctaButtonAction: ButtonAction = .OK - - var moreButtons: [ButtonStruct] = [] - - var dismissButtonTitleKey: String? - var dismissButtonAction: ButtonAction? - - switch evaluateSecurity() { - case (_, .EncValidSign): - color = ThemeManager.encryptedMessageColor() - bodyKey = "OnboardingIntroSection.Confidential.description" - // ctaButton -> Ok - - case (_, .UnableToDecrypt): - color = ThemeManager.troubleMessageColor() - bodyKey = "ReceiveInsecureInfoDecryptionFailed" - // cta Button -> OK - // add -> Import Key - var btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.Import.SK", action: .AskUserToImportSK) - moreButtons.append(btn) - // add -> Ask to resend for differnet PK - btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.Ask.Resend.ForPK", action: .AskSenderToResendForPK) - moreButtons.append(btn) - - case (_, .InvalidSignature): - color = ThemeManager.troubleMessageColor() - bodyKey = "ReceiveDamagedInfo" - // cta Button -> Ignore Mail - ctaButtonTitleKey = "Security.Dialog.Button.Title.Ignore.Mail" - ctaButtonAction = .IgnoreMail - // add -> ask sender - let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.Confirmation", action: .AskSenderToConfirm) - moreButtons.append(btn) - // dismiss -> Ignore Warning - dismissButtonTitleKey = "Security.Dialog.Button.Title.OK" - dismissButtonAction = .IgnoreWarning - - case (_, .NoCrypto): - color = ThemeManager.unencryptedMessageColor() - bodyKey = "ReceiveInsecureInfo" - // cta Button -> Invite user - ctaButtonTitleKey = "Security.Dialog.Button.Title.Invite" - ctaButtonAction = .InvitePerson - // add -> OK - let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) - moreButtons.append(btn) - - case (_, .PlainMissingPublicKeyToVerify): - color = ThemeManager.unencryptedMessageColor() - bodyKey = "Security.Dialog.Body.PlainMissingPublicKeyToVerify" - // cta Button -> Ask to send PK - ctaButtonTitleKey = "Security.Dialog.Button.Title.Ask.ForPK" - ctaButtonAction = .AskSenderToSendPK - // add -> OK - let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) - moreButtons.append(btn) - - case (_, .PlainButValidSignature): - color = ThemeManager.unencryptedMessageColor() - bodyKey = "ReceiveInsecureInfoVerified" - // cta Button -> send PK - ctaButtonTitleKey = "Security.Dialog.Button.Title.Send.PK" - ctaButtonAction = .SendPK - // add -> OK - let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) - moreButtons.append(btn) - - case (_, .EncNoSignature): - color = ThemeManager.unencryptedMessageColor() - bodyKey = "Information.General.OnlyEncryted" - // cta button -> Ask to confirm - // add -> OK - let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) - moreButtons.append(btn) - - case (_, .EncButMissingPublicKeyToVerify): - color = ThemeManager.unencryptedMessageColor() - bodyKey = "Security.Dialog.Body.EncButMissingPublicKeyToVerify" - // cta Button -> Ask to send PK - ctaButtonTitleKey = "Security.Dialog.Button.Title.Ask.ForPK" - ctaButtonAction = .AskSenderToSendPK - // add -> OK - let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) - moreButtons.append(btn) - } - - let body = NSLocalizedString(bodyKey, comment: "") - let ctaButtonTitle = NSLocalizedString(ctaButtonTitleKey, comment: "") - var dismissButtonTitle: String? - if let key = dismissButtonTitleKey { - dismissButtonTitle = NSLocalizedString(key, comment: "") - } - - return DialogStruct(dialogColor: Color(color), title: title, body: body, img: icon, messageImage: nil, ctaButtonTitle: ctaButtonTitle, ctaButtonAction: ctaButtonAction, infoButtonTitle: infoTitle, moreButtons: moreButtons, dismissButtonTitle: dismissButtonTitle, dismissButtonAction: dismissButtonAction) - } - } - - var warnings: [DialogStruct] { - get { - var result = [DialogStruct] () - switch evaluateSecurity() { - case (_, .EncValidSign), (_, .NoCrypto), (_, .PlainButValidSignature), (_, .EncNoSignature): - break // No warning required - case (_, .UnableToDecrypt), (_, .InvalidSignature) , (_, .PlainMissingPublicKeyToVerify), (_, .EncButMissingPublicKeyToVerify): - result.append(dialog) // warning required - } - if mail.sender.keys.count > 0 && mail.signedState == .NoSignature { - let icon = Image(systemName: "exclamationmark.triangl.fill") - let missingSignature = DialogStruct(dialogColor: Color(ThemeManager.unencryptedMessageColor()), - title: NSLocalizedString("encryptedBeforeHeadline", - comment: "encrypted by sender before"), - body: NSLocalizedString("encryptedBeforeText", comment: "encrypted by sender before"), - img: icon, messageImage: icon, - ctaButtonTitle: NSLocalizedString("Security.Dialog.Button.Title.Confirmation", comment: ""), - ctaButtonAction: .AskSenderToConfirm, - infoButtonTitle: NSLocalizedString("Security.Dialog.Button.Title.MoreInfo", comment: ""), - moreButtons: [], - dismissButtonTitle: NSLocalizedString("Security.Dialog.Button.Title.OK", comment: ""), - dismissButtonAction: .IgnoreWarning) - result.append(missingSignature) - } - return result - } - } - - private func evaluateSecurity() -> (isPhish: Bool, cryptoState: CryptoState) { - // TODO Phishing handling - let isPhish = false - let cryptoState = evaluateCryptoState() - - return (isPhish, cryptoState) - } - - private func evaluateCryptoState() -> CryptoState { - switch (mail.encState, mail.signedState) { - // General error cases -> cast other states - case (.UnableToDecrypt, _): return .UnableToDecrypt - case (_, .InvalidSignature): return .InvalidSignature - case (.NoEncryption, .NoSignature): return .NoCrypto - case (.NoEncryption, .NoPublicKey): return .PlainMissingPublicKeyToVerify - case (.NoEncryption, .ValidSignature): return .PlainButValidSignature - case (.ValidEncryptedWithOldKey, .ValidSignature): return .EncValidSign - case (.ValidedEncryptedWithCurrentKey, .ValidSignature): return .EncValidSign - case (.ValidEncryptedWithOldKey, .NoSignature): return .EncNoSignature - case (.ValidEncryptedWithOldKey, .NoPublicKey): return .EncButMissingPublicKeyToVerify - case (.ValidedEncryptedWithCurrentKey, .NoSignature): return .EncNoSignature - case (.ValidedEncryptedWithCurrentKey, .NoPublicKey): return .EncButMissingPublicKeyToVerify - } - - } - - -} diff --git a/enzevalos_iphone/PersistentMail +CoreDataProperties.swift b/enzevalos_iphone/PersistentMail +CoreDataProperties.swift index a6863a354dd0243149b4bc03207372b942436861..9151291c0637eaf0e9db46be1c51cbeaa091a7d4 100644 --- a/enzevalos_iphone/PersistentMail +CoreDataProperties.swift +++ b/enzevalos_iphone/PersistentMail +CoreDataProperties.swift @@ -466,17 +466,6 @@ extension PersistentMail: DisplayMail { return .Other // TODO FIX } - var warnings: [DialogOption] { - var result = [DialogOption]() - if self.unableToDecrypt { - result.append(.couldNotDecrypt) - } - else if self.trouble { - result.append(.corrupted) - } - - return result - } func markAsRead(isRead: Bool) { self.isRead = isRead } diff --git a/enzevalos_iphone/SwiftUI/Read/ReadMainView.swift b/enzevalos_iphone/SwiftUI/Read/ReadMainView.swift index c4b5aefc441abb6b0ffd46398e354294126d2b54..fc206b1984c33712a17fb936169d1a11a14553df 100644 --- a/enzevalos_iphone/SwiftUI/Read/ReadMainView.swift +++ b/enzevalos_iphone/SwiftUI/Read/ReadMainView.swift @@ -40,6 +40,11 @@ struct ReadMainView <M: DisplayMail>: View { var Tabs:[Tab] { get { return [ + Tab( + image: Image(systemName: "shield"), + description: "security", + content:AnyView(AttachmentsViewMain(attachments: mail.displayAttachments, dlAll: true)) + ), Tab( image: Image(systemName: "person.fill"), description: "sender", @@ -54,7 +59,7 @@ struct ReadMainView <M: DisplayMail>: View { image: Image(systemName: "rectangle.and.paperclip"), description: "attachments", content: AnyView(AttachmentsViewMain(attachments: mail.displayAttachments, dlAll: true)) - ) + ) ] } } @@ -72,7 +77,7 @@ struct ReadMainView <M: DisplayMail>: View { } var detailInfo: some View { - let dialog = SecurityState(mail: mail).dialog + let dialog = mail.dialog return DialogView(option: dialog, ctaAction: { self.isSecIndExpanded = false }, additionalAction: nil, dismissAction: nil, extend: false) @@ -91,8 +96,16 @@ struct Tab { #if DEBUG struct Layout_Previews: PreviewProvider { - static var previews: some View { - ReadMainView(mail: mail) + static let deviceNames: [String] = [ + "iPhone SE", + "iPhone 11 Pro Max" + ] + static var previews: some View { + ForEach(Layout_Previews.deviceNames, id: \.self) {deviceName in + ReadMainView<PseuoMail>(mail: mail) + .previewDisplayName(deviceName) + .previewDevice(.init(rawValue: deviceName)) + } } } #endif diff --git a/enzevalos_iphone/SwiftUI/Read/ReadViewCoordinator.swift b/enzevalos_iphone/SwiftUI/Read/ReadViewCoordinator.swift index 4a350010da7d8707288d4321ab301d5d4ba9137f..cc9441a139e0044ee79e801fc91215006f5a0867 100644 --- a/enzevalos_iphone/SwiftUI/Read/ReadViewCoordinator.swift +++ b/enzevalos_iphone/SwiftUI/Read/ReadViewCoordinator.swift @@ -43,8 +43,7 @@ class ReadViewCoordinator { try? AppDelegate.getAppDelegate().mailHandler.startIMAPIdleIfSupported() AppDelegate.getAppDelegate().mailHandler.updateFolder(folder: Folder.inbox, completionCallback: {_ in }) - let secState = SecurityState.init(mail: mail) - let icon = secState.titleIcon + let icon = mail.titleIcon let view = UIImageView(image: icon) let vc = UIHostingController(rootView: ReadMainView(mail: mail)) readView = vc diff --git a/enzevalos_iphone/SwiftUI/Read/ReadViewModel.swift b/enzevalos_iphone/SwiftUI/Read/ReadViewModel.swift index 6053b8ab73a9a71e215317fdaeda42f640f258fb..77e391306c1dc22e3b900e3bb0c6a9712c0c6d03 100644 --- a/enzevalos_iphone/SwiftUI/Read/ReadViewModel.swift +++ b/enzevalos_iphone/SwiftUI/Read/ReadViewModel.swift @@ -65,7 +65,6 @@ protocol DisplayContact { protocol DisplayMail { associatedtype C: DisplayContact - associatedtype D: Dialog var subject: String? { get } var sender: C { get } @@ -83,15 +82,235 @@ protocol DisplayMail { // Crypto var signedState: SignatureState { get } var encState: EncryptionState { get } - - var warnings: [D] { get } - + var persistentMail: PersistentMail? { get } func markAsRead(isRead: Bool) } + +enum CryptoState { + case UnableToDecrypt, InvalidSignature, NoCrypto, PlainMissingPublicKeyToVerify, PlainButValidSignature, EncValidSign, EncNoSignature, EncButMissingPublicKeyToVerify +} + +extension DisplayMail { + + + //let mail: M + + /* TODO: MORE DIALOGS + //else if (mail.isNewPubKey) && !(mail.deleteWhileTravel){} + // message contained new public key + } + + */ + + var title: String { + get { + var key = "" + switch evaluateSecurity() { + case (_,.NoCrypto): key = "Security.Dialog.Title.No.Crypto" + case (_, .UnableToDecrypt): key = "Security.Dialog.Title.UnableToDecrypt" + case (_, .InvalidSignature): key = "Security.Dialog.Title.InvalidSignature" + case (_, .PlainMissingPublicKeyToVerify): key = "Security.Dialog.Title.PlainMissingPublicKeyToVerify" + case (_, .PlainButValidSignature): key = "Security.Dialog.Title.Plain+Sig" + case (_, .EncValidSign): key = "Security.Dialog.Title.Enc+Sign" + case (_, .EncNoSignature): key = "Security.Dialog.Title.Enc+NoSign" + case (_, .EncButMissingPublicKeyToVerify): key = "Security.Dialog.Title.EncMissingPublicKeyToVerify" + } + return NSLocalizedString(key, comment: "") + } + } + + var icon: Image { + get { + switch evaluateSecurity() { + case (_, .EncValidSign): + return StudySettings.securityIndicator.imageOfSecureIndicatorSwiftUI() + case (_, .UnableToDecrypt), (_, .InvalidSignature): + return StudySettings.securityIndicator.imageOfCorruptedIndicatorSwiftUI() + case (_, .NoCrypto), (_, .PlainMissingPublicKeyToVerify), (_, .PlainButValidSignature), (_, .EncNoSignature), (_, .EncButMissingPublicKeyToVerify): + return StudySettings.securityIndicator.imageOfInsecureIndicatorSwiftUI() + } + } + } + + var titleIcon: UIImage { + get { + switch evaluateSecurity() { + case (_, .EncValidSign): + return StudySettings.securityIndicator.imageOfSecureIndicator() + case (_, .UnableToDecrypt), (_, .InvalidSignature): + return StudySettings.securityIndicator.imageOfCorruptedIndicator() + case (_, .NoCrypto), (_, .PlainMissingPublicKeyToVerify), (_, .PlainButValidSignature), (_, .EncNoSignature), (_, .EncButMissingPublicKeyToVerify): + return StudySettings.securityIndicator.imageOfInsecureIndicator() + } + } + } + + var dialog: DialogStruct { + get { + // TODO: Do we add new public key stuff? + var color: UIColor + var bodyKey: String + let infoTitle = NSLocalizedString("Security.Dialog.Button.Title.MoreInfo", comment: "") + + var ctaButtonTitleKey: String = "Security.Dialog.Button.Title.OK" + var ctaButtonAction: ButtonAction = .OK + + var moreButtons: [ButtonStruct] = [] + + var dismissButtonTitleKey: String? + var dismissButtonAction: ButtonAction? + + switch evaluateSecurity() { + case (_, .EncValidSign): + color = ThemeManager.encryptedMessageColor() + bodyKey = "OnboardingIntroSection.Confidential.description" + // ctaButton -> Ok + + case (_, .UnableToDecrypt): + color = ThemeManager.troubleMessageColor() + bodyKey = "ReceiveInsecureInfoDecryptionFailed" + // cta Button -> OK + // add -> Import Key + var btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.Import.SK", action: .AskUserToImportSK) + moreButtons.append(btn) + // add -> Ask to resend for differnet PK + btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.Ask.Resend.ForPK", action: .AskSenderToResendForPK) + moreButtons.append(btn) + + case (_, .InvalidSignature): + color = ThemeManager.troubleMessageColor() + bodyKey = "ReceiveDamagedInfo" + // cta Button -> Ignore Mail + ctaButtonTitleKey = "Security.Dialog.Button.Title.Ignore.Mail" + ctaButtonAction = .IgnoreMail + // add -> ask sender + let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.Confirmation", action: .AskSenderToConfirm) + moreButtons.append(btn) + // dismiss -> Ignore Warning + dismissButtonTitleKey = "Security.Dialog.Button.Title.OK" + dismissButtonAction = .IgnoreWarning + + case (_, .NoCrypto): + color = ThemeManager.unencryptedMessageColor() + bodyKey = "ReceiveInsecureInfo" + // cta Button -> Invite user + ctaButtonTitleKey = "Security.Dialog.Button.Title.Invite" + ctaButtonAction = .InvitePerson + // add -> OK + let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) + moreButtons.append(btn) + + case (_, .PlainMissingPublicKeyToVerify): + color = ThemeManager.unencryptedMessageColor() + bodyKey = "Security.Dialog.Body.PlainMissingPublicKeyToVerify" + // cta Button -> Ask to send PK + ctaButtonTitleKey = "Security.Dialog.Button.Title.Ask.ForPK" + ctaButtonAction = .AskSenderToSendPK + // add -> OK + let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) + moreButtons.append(btn) + + case (_, .PlainButValidSignature): + color = ThemeManager.unencryptedMessageColor() + bodyKey = "ReceiveInsecureInfoVerified" + // cta Button -> send PK + ctaButtonTitleKey = "Security.Dialog.Button.Title.Send.PK" + ctaButtonAction = .SendPK + // add -> OK + let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) + moreButtons.append(btn) + + case (_, .EncNoSignature): + color = ThemeManager.unencryptedMessageColor() + bodyKey = "Information.General.OnlyEncryted" + // cta button -> Ask to confirm + // add -> OK + let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) + moreButtons.append(btn) + + case (_, .EncButMissingPublicKeyToVerify): + color = ThemeManager.unencryptedMessageColor() + bodyKey = "Security.Dialog.Body.EncButMissingPublicKeyToVerify" + // cta Button -> Ask to send PK + ctaButtonTitleKey = "Security.Dialog.Button.Title.Ask.ForPK" + ctaButtonAction = .AskSenderToSendPK + // add -> OK + let btn = ButtonStruct(titleKey: "Security.Dialog.Button.Title.OK", action: .OK) + moreButtons.append(btn) + } + + let body = NSLocalizedString(bodyKey, comment: "") + let ctaButtonTitle = NSLocalizedString(ctaButtonTitleKey, comment: "") + var dismissButtonTitle: String? + if let key = dismissButtonTitleKey { + dismissButtonTitle = NSLocalizedString(key, comment: "") + } + + return DialogStruct(dialogColor: Color(color), title: title, body: body, img: icon, messageImage: nil, ctaButtonTitle: ctaButtonTitle, ctaButtonAction: ctaButtonAction, infoButtonTitle: infoTitle, moreButtons: moreButtons, dismissButtonTitle: dismissButtonTitle, dismissButtonAction: dismissButtonAction) + } + } + + var warnings: [DialogStruct] { + get { + var result = [DialogStruct] () + switch evaluateSecurity() { + case (_, .EncValidSign), (_, .NoCrypto), (_, .PlainButValidSignature), (_, .EncNoSignature): + break // No warning required + case (_, .UnableToDecrypt), (_, .InvalidSignature) , (_, .PlainMissingPublicKeyToVerify), (_, .EncButMissingPublicKeyToVerify): + result.append(dialog) // warning required + } + if self.sender.keys.count > 0 && self.signedState == .NoSignature { + let icon = Image(systemName: "exclamationmark.triangl.fill") + let missingSignature = DialogStruct(dialogColor: Color(ThemeManager.unencryptedMessageColor()), + title: NSLocalizedString("encryptedBeforeHeadline", + comment: "encrypted by sender before"), + body: NSLocalizedString("encryptedBeforeText", comment: "encrypted by sender before"), + img: icon, messageImage: icon, + ctaButtonTitle: NSLocalizedString("Security.Dialog.Button.Title.Confirmation", comment: ""), + ctaButtonAction: .AskSenderToConfirm, + infoButtonTitle: NSLocalizedString("Security.Dialog.Button.Title.MoreInfo", comment: ""), + moreButtons: [], + dismissButtonTitle: NSLocalizedString("Security.Dialog.Button.Title.OK", comment: ""), + dismissButtonAction: .IgnoreWarning) + result.append(missingSignature) + } + return result + } + } + + private func evaluateSecurity() -> (isPhish: Bool, cryptoState: CryptoState) { + // TODO Phishing handling + let isPhish = false + let cryptoState = evaluateCryptoState() + + return (isPhish, cryptoState) + } + + private func evaluateCryptoState() -> CryptoState { + switch (self.encState, self.signedState) { + // General error cases -> cast other states + case (.UnableToDecrypt, _): return .UnableToDecrypt + case (_, .InvalidSignature): return .InvalidSignature + case (.NoEncryption, .NoSignature): return .NoCrypto + case (.NoEncryption, .NoPublicKey): return .PlainMissingPublicKeyToVerify + case (.NoEncryption, .ValidSignature): return .PlainButValidSignature + case (.ValidEncryptedWithOldKey, .ValidSignature): return .EncValidSign + case (.ValidedEncryptedWithCurrentKey, .ValidSignature): return .EncValidSign + case (.ValidEncryptedWithOldKey, .NoSignature): return .EncNoSignature + case (.ValidEncryptedWithOldKey, .NoPublicKey): return .EncButMissingPublicKeyToVerify + case (.ValidedEncryptedWithCurrentKey, .NoSignature): return .EncNoSignature + case (.ValidedEncryptedWithCurrentKey, .NoPublicKey): return .EncButMissingPublicKeyToVerify + } + + } + + +} + class ReadViewModel: ObservableObject { // Meta data @@ -203,14 +422,6 @@ struct PseuoMail: DisplayMail { var isRead: Bool = false - - var warnings: [D] { - get { - return SecurityState.init(mail: self).warnings - } - } - - var subject: String? = "Hello World" var body: String? = "This is my message." diff --git a/enzevalos_iphone/SwiftUI/Read/Tabbed Views/SenderViewMain.swift b/enzevalos_iphone/SwiftUI/Read/Tabbed Views/SenderViewMain.swift index f88d70bcca3c7fcb3ae3128e67fdd6729daaee58..09888d5d79f17cb97cb0686017a1a3fc50d05786 100644 --- a/enzevalos_iphone/SwiftUI/Read/Tabbed Views/SenderViewMain.swift +++ b/enzevalos_iphone/SwiftUI/Read/Tabbed Views/SenderViewMain.swift @@ -25,22 +25,20 @@ import CoreLocation struct SenderViewMain <M: DisplayMail>: View { let mail: M - let secState: SecurityState<M> @State var selectedLandmark: Landmark? = nil @State var showingLandmarkDetails = false init(mail: M) { self.mail = mail - secState = SecurityState(mail: mail) } var body: some View { ScrollView { - if secState.warnings.count > 0 { - ForEach(0..<secState.warnings.count) { index in - DialogView(option: self.secState.warnings[index], ctaAction: {print("Hello")}, additionalAction: {print("Hello")}, dismissAction: {print("Hello")}, extend: (index == (self.secState.warnings.count - 1))) + if mail.warnings.count > 0 { + ForEach(0..<mail.warnings.count) { index in + DialogView(option: self.mail.warnings[index], ctaAction: {print("Hello")}, additionalAction: {print("Hello")}, dismissAction: {print("Hello")}, extend: (index == (self.mail.warnings.count - 1))) } } else { @@ -188,6 +186,5 @@ struct SenderView_Previews: PreviewProvider { .previewDisplayName(deviceName) .previewDevice(.init(rawValue: deviceName)) } - } } diff --git a/enzevalos_iphone/SwiftUI/SupportingViews/DialogView.swift b/enzevalos_iphone/SwiftUI/SupportingViews/DialogView.swift index 5679176d17878b1716601c5ed5a32439c9f2ccdc..e50ea727a63a1336e62b172b98e90c07d6d276c8 100644 --- a/enzevalos_iphone/SwiftUI/SupportingViews/DialogView.swift +++ b/enzevalos_iphone/SwiftUI/SupportingViews/DialogView.swift @@ -80,10 +80,10 @@ struct DialogView <D: Dialog> : View { } struct DialogView_Previews: PreviewProvider { - static let options = SecurityState.init(mail: mail) + static let options = mail.dialog static var previews: some View { ScrollView{ - DialogView(option: options.dialog, ctaAction: action, additionalAction: action, dismissAction: action, extend: false) + DialogView(option: options, ctaAction: action, additionalAction: action, dismissAction: action, extend: false) DialogView(option: DialogOption.corrupted, ctaAction: action, additionalAction: action, dismissAction: action, extend: false) DialogView(option: DialogOption.couldNotDecrypt, ctaAction: action, additionalAction: action, dismissAction: action, extend: false) }