From c51e6d9fe50c075b080a4e23a7a926ed5d39a00e Mon Sep 17 00:00:00 2001 From: Simon Bihel Date: Tue, 13 Aug 2024 08:43:32 +0100 Subject: [PATCH 1/3] Revert swiftlint config changes and fix warnings --- .gitignore | 3 ++- .swiftlint.yml | 12 ----------- Sources/MobileSdk/KeyManager.swift | 12 ++++++----- Sources/MobileSdk/PlatformContext.swift | 5 +++-- Sources/MobileSdk/StorageManager.swift | 23 +++++++++++----------- Sources/MobileSdk/ui/QRCodeScanner.swift | 3 +-- Tests/MobileSdkTests/DataConversions.swift | 2 ++ 7 files changed, 27 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 3c93ec0..42fec1c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,8 @@ Derived/ DerivedData/ .swiftpm/configuration/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.swiftpm/xcode/xcshareddata/xcschemes/SpruceIDMobileSdk.xcscheme .netrc -WalletSdk.xcodeproj +MobileSdk.xcodeproj build/ *~ diff --git a/.swiftlint.yml b/.swiftlint.yml index ae30ba5..a9eaab6 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,17 +1,5 @@ excluded: - .build disabled_rules: - - colon - cyclomatic_complexity - todo - - force_cast - -identifier_name: - min_length: 1 - -line_length: - warning: 200 - error: 250 - ignores_function_declarations: true - ignores_comments: true - ignores_urls: true \ No newline at end of file diff --git a/Sources/MobileSdk/KeyManager.swift b/Sources/MobileSdk/KeyManager.swift index d80c701..a62a687 100644 --- a/Sources/MobileSdk/KeyManager.swift +++ b/Sources/MobileSdk/KeyManager.swift @@ -49,7 +49,9 @@ public class KeyManager: NSObject { guard status == errSecSuccess else { return nil } + // swiftlint:disable force_cast let key = item as! SecKey + // swiftlint:enable force_cast return key } @@ -103,14 +105,14 @@ public class KeyManager: NSObject { let xDataRaw: Data = fullData.subdata(in: 0..<32) let yDataRaw: Data = fullData.subdata(in: 32..<64) - let x = xDataRaw.base64EncodedUrlSafe - let y = yDataRaw.base64EncodedUrlSafe + let xCoordinate = xDataRaw.base64EncodedUrlSafe + let yCoordinate = yDataRaw.base64EncodedUrlSafe let jsonObject: [String: Any] = [ "kty": "EC", "crv": "P-256", - "x": x, - "y": y + "x": xCoordinate, + "y": yCoordinate ] guard let jsonData = try? JSONSerialization.data(withJSONObject: jsonObject, options: []) else { return nil } @@ -206,7 +208,7 @@ public class KeyManager: NSObject { /** * Decrypts the provided payload by a key id and initialization vector. */ - public static func decryptPayload(id: String, iv: [UInt8], payload: [UInt8]) -> [UInt8]? { + public static func decryptPayload(id: String, payload: [UInt8]) -> [UInt8]? { guard let key = getSecretKey(id: id) else { return nil } guard let data = CFDataCreate(kCFAllocatorDefault, payload, payload.count) else { diff --git a/Sources/MobileSdk/PlatformContext.swift b/Sources/MobileSdk/PlatformContext.swift index 67c9a1d..f4d1039 100644 --- a/Sources/MobileSdk/PlatformContext.swift +++ b/Sources/MobileSdk/PlatformContext.swift @@ -1,7 +1,8 @@ // File: PlatformContext // -// Store and retrieve sensitive data. Data is stored in the Application Support directory of the app, encrypted in place -// via the .completeFileProtection option, and marked as excluded from backups so it will not be included in iCloud backps. +// Store and retrieve sensitive data. Data is stored in the Application Support directory of the app, encrypted in +// place via the .completeFileProtection option, and marked as excluded from backups so it will not be included in +// iCloud backups. // // Imports diff --git a/Sources/MobileSdk/StorageManager.swift b/Sources/MobileSdk/StorageManager.swift index 9930601..c9b8467 100644 --- a/Sources/MobileSdk/StorageManager.swift +++ b/Sources/MobileSdk/StorageManager.swift @@ -1,7 +1,8 @@ // File: Storage Manager // -// Store and retrieve sensitive data. Data is stored in the Application Support directory of the app, encrypted in place -// via the .completeFileProtection option, and marked as excluded from backups so it will not be included in iCloud backps. +// Store and retrieve sensitive data. Data is stored in the Application Support directory of the app, encrypted in +// place via the .completeFileProtection option, and marked as excluded from backups so it will not be included in +// iCloud backps. // // Imports @@ -18,8 +19,8 @@ import Foundation class StorageManager: NSObject { // Local-Method: path() - // Get the path to the application support dir, appending the given file name to it. We use the application support - // directory because its contents are not shared. + // Get the path to the application support dir, appending the given file name to it. We use the application + // support directory because its contents are not shared. // // Arguments: // file - the name of the file @@ -29,13 +30,13 @@ class StorageManager: NSObject { private func path(file: String) -> URL? { do { - // Get the applications support dir, and tack the name of the thing we're storing on the end of it. This does - // imply that `file` should be a valid filename. + // Get the applications support dir, and tack the name of the thing we're storing on the end of it. + // This does imply that `file` should be a valid filename. - let asdir = try FileManager.default.url(for: .applicationSupportDirectory, - in: .userDomainMask, + let asdir = try FileManager.default.url(for: .applicationSupportDirectory, + in: .userDomainMask, appropriateFor: nil, // Ignored - create: true) // May not exist, make if necessary. + create: true) // May not exist, make if necessary. return asdir.appendingPathComponent(file) } catch { // Did the attempt to get the application support dir fail? @@ -80,8 +81,8 @@ class StorageManager: NSObject { guard let file = path(file: key) else { return nil } do { - let d = try Data(contentsOf: file) - return d + let data = try Data(contentsOf: file) + return data } catch { print("Failed to read '\(file)'.") } diff --git a/Sources/MobileSdk/ui/QRCodeScanner.swift b/Sources/MobileSdk/ui/QRCodeScanner.swift index 2b08976..69cb744 100644 --- a/Sources/MobileSdk/ui/QRCodeScanner.swift +++ b/Sources/MobileSdk/ui/QRCodeScanner.swift @@ -131,8 +131,7 @@ public struct QRCodeScanner: View { public var body: some View { ZStack(alignment: .top) { - GeometryReader { - let viewSize = $0.size + GeometryReader {_ in let size = UIScreen.screenSize ZStack { CameraView(frameSize: CGSize(width: size.width, height: size.height), session: $session) diff --git a/Tests/MobileSdkTests/DataConversions.swift b/Tests/MobileSdkTests/DataConversions.swift index 678d8c8..5a29707 100644 --- a/Tests/MobileSdkTests/DataConversions.swift +++ b/Tests/MobileSdkTests/DataConversions.swift @@ -20,7 +20,9 @@ final class DataConversions: XCTestCase { let base64 = sampleData.base64EncodedUrlSafe // Generated independently + // swiftlint:disable line_length let expectedBase64String = "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2Nzg5Ky89K0FCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaMDEyMzQ1Njc4OSsvPQ" + // swiftlint:enable line_length XCTAssertEqual(base64, expectedBase64String) } From 20ac10959eed7c04e1865d1f6e746fd55e00179b Mon Sep 17 00:00:00 2001 From: Simon Bihel Date: Tue, 13 Aug 2024 08:45:09 +0100 Subject: [PATCH 2/3] Fix manually edited Info plist --- Info.plist | 4 ++-- project.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Info.plist b/Info.plist index bf9482a..d04f29e 100644 --- a/Info.plist +++ b/Info.plist @@ -16,9 +16,9 @@ 1.0 CFBundleVersion 1 - NSCameraUsageDescription - QR Code Scanner NSBluetoothAlwaysUsageDescription Secure transmission of mobile DL data + NSCameraUsageDescription + QR Code Scanner diff --git a/project.yml b/project.yml index 3d23582..4517209 100644 --- a/project.yml +++ b/project.yml @@ -34,6 +34,7 @@ targets: path: Info.plist properties: NSBluetoothAlwaysUsageDescription: "Secure transmission of mobile DL data" + NSCameraUsageDescription: "QR Code Scanner" buildToolPlugins: - plugin: SwiftLintPlugin package: SwiftLint From a637982b5c605a0e4bbad2282330c70b9a789a88 Mon Sep 17 00:00:00 2001 From: Simon Bihel Date: Tue, 13 Aug 2024 08:46:16 +0100 Subject: [PATCH 3/3] Remove Info.plist as it's only used for xcode tests --- .gitignore | 1 + Info.plist | 24 ------------------------ 2 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 Info.plist diff --git a/.gitignore b/.gitignore index 42fec1c..040fb11 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ DerivedData/ MobileSdk.xcodeproj build/ *~ +Info.plist diff --git a/Info.plist b/Info.plist deleted file mode 100644 index d04f29e..0000000 --- a/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - NSBluetoothAlwaysUsageDescription - Secure transmission of mobile DL data - NSCameraUsageDescription - QR Code Scanner - -