Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widen platform support for iOS 12 and tvOS 12 #61

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import PackageDescription
let package = Package(
name: "UID2",
defaultLocalization: "en",
// NB: The UID2 framework code only runs on iOS 13 & tvOS 13, however this allows
// integration in apps supporting iOS 12.
platforms: [
.iOS(.v13),
.tvOS(.v13)
.iOS(.v12),
.tvOS(.v12)
],
products: [
.library(
Expand Down
2 changes: 2 additions & 0 deletions Sources/UID2/CryptoUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CryptoKit
import Foundation
import SwiftASN1

@available(iOS 13, tvOS 13, *)
struct CryptoUtil: Sendable {
// Parses a server's public key and returns a newly generated public key and symmetric key.
var parseKey: @Sendable (_ string: String) throws -> (SymmetricKey, P256.KeyAgreement.PublicKey)
Expand All @@ -17,6 +18,7 @@ struct CryptoUtil: Sendable {
var encrypt: @Sendable (_ data: Data, _ key: SymmetricKey, _ authenticatedData: Data) throws -> AES.GCM.SealedBox
}

@available(iOS 13, tvOS 13, *)
extension CryptoUtil {
private static let serverPublicKeyPrefixLength = 9

Expand Down
1 change: 1 addition & 0 deletions Sources/UID2/Extensions/PublicKey+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CryptoKit
import Foundation
import SwiftASN1

@available(iOS 13, tvOS 13, *)
extension P256.KeyAgreement.PublicKey {
// CryptoKit's implementation is only available in iOS 14
var derRepresentation: Data {
Expand Down
1 change: 1 addition & 0 deletions Sources/UID2/Extensions/URLSession+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation

@available(iOS 13, tvOS 13, *)
extension URLSession: NetworkSession {

func loadData(for request: URLRequest) async throws -> (Data, HTTPURLResponse) {
Expand Down
1 change: 1 addition & 0 deletions Sources/UID2/Internal/Broadcaster.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation

/// Send a value to multiple observers
@available(iOS 13, tvOS 13, *)
actor Broadcaster<Element: Sendable> {
typealias Identifier = UUID
private var continuations: [Identifier: AsyncStream<Element>.Continuation] = [:]
Expand Down
1 change: 1 addition & 0 deletions Sources/UID2/Internal/Queue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation
/// When bridging from a sync to async context using multiple `Task`s, order of execution is not guaranteed.
/// Using an `AsyncStream` we can bridge enqueued work to an async context within a single `Task`.
/// https://forums.swift.org/t/a-pitfall-when-using-didset-and-task-together-order-cant-be-guaranteed/71311/6
@available(iOS 13, tvOS 13, *)
final class Queue {
typealias Operation = @Sendable () async -> Void
private let continuation: AsyncStream<Operation>.Continuation
Expand Down
2 changes: 2 additions & 0 deletions Sources/UID2/KeychainManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Foundation
import Security

@available(iOS 13, tvOS 13, *)
extension Storage {
static func keychainStorage() -> Storage {
let storage = KeychainManager()
Expand All @@ -17,6 +18,7 @@ extension Storage {
}

/// Securely manages data in the Keychain
@available(iOS 13, tvOS 13, *)
actor KeychainManager {

private let attrAccount = "uid2"
Expand Down
4 changes: 4 additions & 0 deletions Sources/UID2/Networking/ClientGenerate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import CryptoKit
import Foundation

extension Request {

@available(iOS 13, tvOS 13, *)
static func clientGenerate(
payload: Data,
initializationVector: Data,
Expand Down Expand Up @@ -54,6 +56,7 @@ struct ClientGeneratePayload: Encodable {
}
}

@available(iOS 13, tvOS 13, *)
extension ClientGeneratePayload {
init(_ identity: IdentityType) {
switch identity {
Expand Down Expand Up @@ -87,6 +90,7 @@ struct ClientGenerateRequestBody: Encodable {
}
}

@available(iOS 13, tvOS 13, *)
fileprivate extension String {
func sha256hash() -> Data {
let digest = SHA256.hash(data: Data(self.utf8))
Expand Down
1 change: 1 addition & 0 deletions Sources/UID2/Networking/DataEnvelope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import CryptoKit
import Foundation

@available(iOS 13, tvOS 13, *)
internal enum DataEnvelope {

/// Decrypts raw response envelope data, which is expected to be a base64 encoded string.
Expand Down Expand Up @@ -44,7 +45,7 @@
extension Data {
/// A convenience initializer for converting from a Data representation of a base64 encoded string to its decoded Data.
init?(base64EncodedData: Data, options: Data.Base64DecodingOptions = []) {
guard let base64String = String(data: base64EncodedData, encoding: .utf8) else {

Check warning on line 48 in Sources/UID2/Networking/DataEnvelope.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Prefer using UTF-8 encoded strings when converting between `String` and `Data` (non_optional_string_data_conversion)
return nil
}
self.init(base64Encoded: base64String, options: options)
Expand Down
1 change: 1 addition & 0 deletions Sources/UID2/Networking/NetworkSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

/// Common interface for networking and unit testing
@available(iOS 13, tvOS 13, *)
protocol NetworkSession: Sendable {

func loadData(for request: URLRequest) async throws -> (Data, HTTPURLResponse)
Expand Down
1 change: 1 addition & 0 deletions Sources/UID2/UID2Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#endif
@preconcurrency import OSLog

@available(iOS 13, tvOS 13, *)
internal final class UID2Client: Sendable {
private let clientVersion: String
private let environment: Environment
Expand Down Expand Up @@ -120,7 +121,7 @@
let decoder = JSONDecoder.apiDecoder()
guard response.statusCode == 200 else {
let statusCode = response.statusCode
let responseText = String(data: data, encoding: .utf8) ?? "<none>"

Check warning on line 124 in Sources/UID2/UID2Client.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Prefer using UTF-8 encoded strings when converting between `String` and `Data` (non_optional_string_data_conversion)
os_log("Request failure (%d) %@", log: log, type: .error, statusCode, responseText)
if environment != .production {
os_log("Failed request is using non-production API endpoint %@, is this intentional?", log: log, type: .error, baseURL.description)
Expand Down
3 changes: 3 additions & 0 deletions Sources/UID2/UID2Manager.State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import Foundation

@available(iOS 13, tvOS 13, *)
extension UID2Manager {
public enum State: Hashable, Sendable, Codable {
case optout
Expand All @@ -15,6 +16,7 @@ extension UID2Manager {
}
}

@available(iOS 13, tvOS 13, *)
extension UID2Manager.State {
/// A 'case path' returning the current `IdentityStatus`.
public var identityStatus: IdentityStatus {
Expand Down Expand Up @@ -49,6 +51,7 @@ extension UID2Manager.State {
}
}

@available(iOS 13, tvOS 13, *)
extension UID2Manager.State {
init?(_ package: IdentityPackage) {
switch package.status {
Expand Down
1 change: 1 addition & 0 deletions Sources/UID2/UID2Manager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import OSLog

// swiftlint:disable:next type_body_length
@available(iOS 13, tvOS 13, *)

Check warning on line 13 in Sources/UID2/UID2Manager.swift

View workflow job for this annotation

GitHub Actions / Code Tests

SwiftLint rule 'type_body_length' did not trigger a violation in the disabled region; remove the disable command (superfluous_disable_command)
public final actor UID2Manager {

Check warning on line 14 in Sources/UID2/UID2Manager.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Type body should span 250 lines or less excluding comments and whitespace: currently spans 296 lines (type_body_length)
private enum InitializationState {
case pending
case complete
Expand Down Expand Up @@ -453,4 +454,4 @@
generate = { newValue }
}
}
}

Check warning on line 457 in Sources/UID2/UID2Manager.swift

View workflow job for this annotation

GitHub Actions / Code Tests

File should contain 400 lines or less: currently contains 457 (file_length)
1 change: 1 addition & 0 deletions Tests/TestHelpers/TestCryptoUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private final class Atomic<Value: Sendable>: @unchecked Sendable {

/// A test convenience which exposes the Symmetric Key it generates for the client.
/// This key can then be used to encrypt stub responses for the client.
@available(iOS 13, tvOS 13, *)
public final class TestCryptoUtil {
private let atomicSymmetricKey: Atomic<SymmetricKey?>

Expand Down
1 change: 1 addition & 0 deletions Tests/TestHelpers/XCTest+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import XCTest

/// `XCTAssertThrowsError` doesn't support async expressions.
@available(iOS 13, tvOS 13, *)
public func assertThrowsError<T>(
_ expression: @escaping @autoclosure () async throws -> T,
_ message: @autoclosure () -> String = "",
Expand Down
4 changes: 2 additions & 2 deletions UID2.podspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"tag": "v1.5.0"
},
"platforms": {
"ios": "13.0",
"tvos": "13.0"
"ios": "12.0",
"tvos": "12.0"
},
"swift_versions": [
"5"
Expand Down
Loading