xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XKit / GrandSlam / Anisette / AnisetteDataProvider.swift
AnisetteDataProvider.swift64 lines · 2.0 KiBRaw
| 1 | // |
| 2 | // AnisetteDataProvider.swift |
| 3 | // XKit |
| 4 | // |
| 5 | // Created by Kabir Oberai on 19/11/19. |
| 6 | // Copyright © 2019 Kabir Oberai. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | import Foundation |
| 10 | import Dependencies |
| 11 | |
| 12 | public protocol AnisetteDataProvider: Sendable { |
| 13 | /// Stored alongside login data. If the provider reports a new ID, we log out. |
| 14 | /// |
| 15 | /// This is useful when switching Anisette provider implementations if the old |
| 16 | /// implementation's provisioning data won't work with the new implementation. |
| 17 | /// |
| 18 | /// The default implementation returns `nil`. |
| 19 | var providerID: String? { get } |
| 20 | |
| 21 | // This is a suggestion and not a requirement. |
| 22 | func resetProvisioning() async |
| 23 | func provisioningData() -> ProvisioningData? |
| 24 | |
| 25 | func deviceInfo() async throws -> DeviceInfo |
| 26 | |
| 27 | func fetchAnisetteData() async throws -> AnisetteData |
| 28 | } |
| 29 | |
| 30 | public struct ProvisioningData: Hashable, Codable, Sendable { |
| 31 | public var localUserUID: UUID |
| 32 | public var routingInfo: UInt64 |
| 33 | public var adiPb: Data |
| 34 | } |
| 35 | |
| 36 | extension AnisetteDataProvider { |
| 37 | public var providerID: String? { nil } |
| 38 | public func provisioningData() -> ProvisioningData? { nil } |
| 39 | public func resetProvisioning() async {} |
| 40 | } |
| 41 | |
| 42 | extension DependencyValues { |
| 43 | public var anisetteDataProvider: AnisetteDataProvider { |
| 44 | get { self[AnisetteDataProviderDependencyKey.self] } |
| 45 | set { self[AnisetteDataProviderDependencyKey.self] = newValue } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | private struct AnisetteDataProviderDependencyKey: DependencyKey { |
| 50 | static let testValue: AnisetteDataProvider = UnimplementedAnisetteDataProvider() |
| 51 | static let liveValue: AnisetteDataProvider = ADIDataProvider() |
| 52 | } |
| 53 | |
| 54 | private struct UnimplementedAnisetteDataProvider: AnisetteDataProvider { |
| 55 | func fetchAnisetteData() async throws -> AnisetteData { |
| 56 | let closure: () async throws -> AnisetteData = unimplemented() |
| 57 | return try await closure() |
| 58 | } |
| 59 | |
| 60 | func deviceInfo() async throws -> DeviceInfo { |
| 61 | let closure: () async throws -> DeviceInfo = unimplemented() |
| 62 | return try await closure() |
| 63 | } |
| 64 | } |