Skip to content

Commit

Permalink
Widen platform support for iOS 12 and tvOS 12
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaunt committed Aug 15, 2024
1 parent aeb4a40 commit 5ff81fa
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 4 deletions.
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
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 @@ import Foundation
#endif
@preconcurrency import OSLog

@available(iOS 13, tvOS 13, *)
internal final class UID2Client: Sendable {
private let clientVersion: String
private let environment: Environment
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,6 +10,7 @@ import Foundation
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
Expand Down
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

0 comments on commit 5ff81fa

Please sign in to comment.