fix XCode config, add icons

This commit is contained in:
0xturboblitz
2023-10-14 14:46:20 +02:00
parent 815fd9434b
commit cc5ed77dae
133 changed files with 95298 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
//
// PassportUtils.swift
// NFCPassportReaderApp
//
// Created by Andy Qua on 30/06/2019.
// Copyright © 2019 Andy Qua. All rights reserved.
//
import UIKit
import NFCPassportReader
class PassportUtils {
func getMRZKey(passportNumber: String, dateOfBirth: String, dateOfExpiry: String ) -> String {
// Pad fields if necessary
let pptNr = pad( passportNumber, fieldLength:9)
let dob = pad( dateOfBirth, fieldLength:6)
let exp = pad( dateOfExpiry, fieldLength:6)
// Calculate checksums
let passportNrChksum = calcCheckSum(pptNr)
let dateOfBirthChksum = calcCheckSum(dob)
let expiryDateChksum = calcCheckSum(exp)
let mrzKey = "\(pptNr)\(passportNrChksum)\(dob)\(dateOfBirthChksum)\(exp)\(expiryDateChksum)"
return mrzKey
}
func pad( _ value : String, fieldLength:Int ) -> String {
// Pad out field lengths with < if they are too short
let paddedValue = (value + String(repeating: "<", count: fieldLength)).prefix(fieldLength)
return String(paddedValue)
}
func calcCheckSum( _ checkString : String ) -> Int {
let characterDict = ["0" : "0", "1" : "1", "2" : "2", "3" : "3", "4" : "4", "5" : "5", "6" : "6", "7" : "7", "8" : "8", "9" : "9", "<" : "0", " " : "0", "A" : "10", "B" : "11", "C" : "12", "D" : "13", "E" : "14", "F" : "15", "G" : "16", "H" : "17", "I" : "18", "J" : "19", "K" : "20", "L" : "21", "M" : "22", "N" : "23", "O" : "24", "P" : "25", "Q" : "26", "R" : "27", "S" : "28","T" : "29", "U" : "30", "V" : "31", "W" : "32", "X" : "33", "Y" : "34", "Z" : "35"]
var sum = 0
var m = 0
let multipliers : [Int] = [7, 3, 1]
for c in checkString {
guard let lookup = characterDict["\(c)"],
let number = Int(lookup) else { return 0 }
let product = number * multipliers[m]
sum += product
m = (m+1) % 3
}
return (sum % 10)
}
static func shareLogs() {
do {
let arr = Log.logData
let data = try JSONSerialization.data(withJSONObject: arr, options: .prettyPrinted)
let temporaryURL = URL(fileURLWithPath: NSTemporaryDirectory() + "passportreader.log")
try data.write(to: temporaryURL)
let av = UIActivityViewController(activityItems: [temporaryURL], applicationActivities: nil)
let keyWindow = UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.map({$0 as? UIWindowScene})
.compactMap({$0})
.first?.windows
.filter({$0.isKeyWindow}).first
keyWindow?.rootViewController?.present(av, animated: true, completion: nil)
} catch {
print( "ERROR - \(error)" )
}
}
}

View File

@@ -0,0 +1,107 @@
//
// SettingsStore.swift
// NFCPassportReaderApp
//
// Created by Andy Qua on 10/02/2021.
// Copyright © 2021 Andy Qua. All rights reserved.
//
import SwiftUI
import Combine
import NFCPassportReader
final class SettingsStore: ObservableObject {
private enum Keys {
static let captureLog = "captureLog"
static let logLevel = "logLevel"
static let useNewVerification = "useNewVerification"
static let savePassportOnScan = "savePassportOnScan"
static let passportNumber = "passportNumber"
static let dateOfBirth = "dateOfBirth"
static let dateOfExpiry = "dateOfExpiry"
static let allVals = [captureLog, logLevel, useNewVerification, passportNumber, dateOfBirth, dateOfExpiry]
}
private let cancellable: Cancellable
private let defaults: UserDefaults
let objectWillChange = PassthroughSubject<Void, Never>()
init(defaults: UserDefaults = .standard) {
self.defaults = defaults
defaults.register(defaults: [
Keys.captureLog: true,
Keys.logLevel: 1,
Keys.useNewVerification: true,
Keys.savePassportOnScan: false,
Keys.passportNumber: "",
Keys.dateOfBirth: Date().timeIntervalSince1970,
Keys.dateOfExpiry: Date().timeIntervalSince1970,
])
cancellable = NotificationCenter.default
.publisher(for: UserDefaults.didChangeNotification)
.map { _ in () }
.subscribe(objectWillChange)
}
func reset() {
if let bundleID = Bundle.main.bundleIdentifier {
UserDefaults.standard.removePersistentDomain(forName: bundleID)
}
}
var shouldCaptureLogs: Bool {
set { defaults.set(newValue, forKey: Keys.captureLog) }
get { defaults.bool(forKey: Keys.captureLog) }
}
var logLevel: LogLevel {
get {
return LogLevel(rawValue:defaults.integer(forKey: Keys.logLevel)) ?? .info
}
set {
defaults.set(newValue.rawValue, forKey: Keys.logLevel)
}
}
var useNewVerificationMethod: Bool {
set { defaults.set(newValue, forKey: Keys.useNewVerification) }
get { defaults.bool(forKey: Keys.useNewVerification) }
}
var savePassportOnScan: Bool {
set { defaults.set(newValue, forKey: Keys.savePassportOnScan) }
get { defaults.bool(forKey: Keys.savePassportOnScan) }
}
var passportNumber: String {
set { defaults.set(newValue, forKey: Keys.passportNumber) }
get { defaults.string(forKey: Keys.passportNumber) ?? "" }
}
var dateOfBirth: Date {
set {
defaults.set(newValue.timeIntervalSince1970, forKey: Keys.dateOfBirth)
}
get {
let d = Date(timeIntervalSince1970: defaults.double(forKey: Keys.dateOfBirth))
return d
}
}
var dateOfExpiry: Date {
set {
defaults.set(newValue.timeIntervalSince1970, forKey: Keys.dateOfExpiry) }
get {
let d = Date(timeIntervalSince1970: defaults.double(forKey: Keys.dateOfExpiry))
return d
}
}
@Published var passport : NFCPassportModel?
}