Enable SwiftLint rule 'nesting' and fix all violations

This commit is contained in:
Danny Moesch 2020-07-05 00:40:05 +02:00 committed by Mingshen Sun
parent 2920acefbc
commit 77216abe14
4 changed files with 65 additions and 46 deletions

View file

@ -18,51 +18,6 @@ class PGPKeyArmorImportTableViewController: AutoCellHeightUITableViewController,
var armorPublicKey: String?
var armorPrivateKey: String?
class ScannedPGPKey {
enum KeyType {
case publicKey, privateKey
}
var keyType = KeyType.publicKey
var segments = [String]()
var message = ""
func reset(keytype: KeyType) {
keyType = keytype
segments.removeAll()
message = "LookingForStartingFrame.".localize()
}
func addSegment(segment: String) -> (accept: Bool, message: String) {
let keyTypeStr = keyType == .publicKey ? "Public" : "Private"
let theOtherKeyTypeStr = keyType == .publicKey ? "Private" : "Public"
// Skip duplicated segments.
guard segment != segments.last else {
return (accept: false, message: message)
}
// Check whether we have found the first block.
guard !segments.isEmpty || segment.contains("-----BEGIN PGP \(keyTypeStr.uppercased()) KEY BLOCK-----") else {
// Check whether we are scanning the wrong key type.
if segment.contains("-----BEGIN PGP \(theOtherKeyTypeStr.uppercased()) KEY BLOCK-----") {
message = "Scan\(keyTypeStr)Key.".localize()
}
return (accept: false, message: message)
}
// Update the list of scanned segment and return.
segments.append(segment)
if segment.contains("-----END PGP \(keyTypeStr.uppercased()) KEY BLOCK-----") {
message = "Done".localize()
return (accept: true, message: message)
} else {
message = "ScannedQrCodes(%d)".localize(segments.count)
return (accept: false, message: message)
}
}
}
var scanned = ScannedPGPKey()
override func viewDidLoad() {