diff --git a/enzevalos_iphone/mail/IncomingMail.swift b/enzevalos_iphone/mail/IncomingMail.swift index 160e0710db711e96c426a0a010e7cc1c94016984..51c93f2839eeb5f485dccda1df1b83d09a760bde 100644 --- a/enzevalos_iphone/mail/IncomingMail.swift +++ b/enzevalos_iphone/mail/IncomingMail.swift @@ -555,18 +555,23 @@ class IncomingMail { return newKey } - private static func findSecretKeys(attachment: MCOAttachment) -> [String] { - if let content = attachment.decodedString() { - return PGPPart.SECRETKEY.findPGPPartInString(content: content) + private static func findKeys(attachment: MCOAttachment, type: PGPPart) -> [String]{ + var keys: [String] = [] + if let content = String(data: attachment.data, encoding: .utf8) { + keys.append(contentsOf: type.findPGPPartInString(content: content)) } - return [] + else if let content = attachment.decodedString() { + keys.append(contentsOf: type.findPGPPartInString(content: content)) + } + return keys + } + + private static func findSecretKeys(attachment: MCOAttachment) -> [String] { + return findKeys(attachment: attachment, type: PGPPart.SECRETKEY) } private static func findPublicKeys(attachment: MCOAttachment) -> [String] { - if let content = attachment.decodedString() { - return PGPPart.PUBLICKEY.findPGPPartInString(content: content) - } - return [] + return findKeys(attachment: attachment, type: PGPPart.PUBLICKEY) } private static func extractPublicKeys(text: String) -> [String] { diff --git a/enzevalos_iphoneTests/StudyTest.swift b/enzevalos_iphoneTests/StudyTest.swift index adff51574a4674096dca56ae7747003437628676..dfaef31c8ff6721fd964cfa23150a71acfca2940 100644 --- a/enzevalos_iphoneTests/StudyTest.swift +++ b/enzevalos_iphoneTests/StudyTest.swift @@ -26,6 +26,13 @@ class StudyTest: XCTestCase { _ = p.reset() } } + + func testMultipleSecurityIndicator() { + for _ in 0...100 { + testSecurityIndicator() + } + } + func testSecurityIndicator(){ testOneParameter(parameter: SecurityIndicator.self) let secIndicator: SecurityIndicator = SecurityIndicator.load() as! SecurityIndicator @@ -83,7 +90,7 @@ class StudyTest: XCTestCase { var values: [Int] = Array(repeating: 0, count: Int(parameter.numberOfTreatments)) let n = 100 let mean = Double(n) / Double(parameter.numberOfTreatments) - let threshold = mean * 0.1 + let threshold = mean * 0.2 self.reset() for _ in 0...n { @@ -93,7 +100,7 @@ class StudyTest: XCTestCase { self.reset() } for v in values { - XCTAssertLessThan(v, Int(mean + threshold)) + XCTAssertLessThan(v, Int(mean + threshold), "n: \(n) | values: \(values)") XCTAssertGreaterThan(v, Int(mean - threshold)) } }