Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.
Create Supersign
kabiroberai8a7ad9a0414f
diff --git a/Supercharge.xcodeproj/xcshareddata/xcschemes/Supersign.xcscheme b/Supercharge.xcodeproj/xcshareddata/xcschemes/Supersign.xcschemenew file mode 100644index 0000000..3f7cd64--- /dev/null+++ b/Supercharge.xcodeproj/xcshareddata/xcschemes/Supersign.xcscheme@@ -0,0 +1,67 @@+<?xml version="1.0" encoding="UTF-8"?>+<Scheme+ LastUpgradeVersion = "1100"+ version = "1.3">+ <BuildAction+ parallelizeBuildables = "YES"+ buildImplicitDependencies = "YES">+ <BuildActionEntries>+ <BuildActionEntry+ buildForTesting = "YES"+ buildForRunning = "YES"+ buildForProfiling = "YES"+ buildForArchiving = "YES"+ buildForAnalyzing = "YES">+ <BuildableReference+ BuildableIdentifier = "primary"+ BlueprintIdentifier = "56C6048E234E3EA70008BBB9"+ BuildableName = "Supersign.framework"+ BlueprintName = "Supersign"+ ReferencedContainer = "container:Supercharge.xcodeproj">+ </BuildableReference>+ </BuildActionEntry>+ </BuildActionEntries>+ </BuildAction>+ <TestAction+ buildConfiguration = "Debug"+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"+ shouldUseLaunchSchemeArgsEnv = "YES">+ <Testables>+ </Testables>+ </TestAction>+ <LaunchAction+ buildConfiguration = "Debug"+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"+ launchStyle = "0"+ useCustomWorkingDirectory = "NO"+ ignoresPersistentStateOnLaunch = "NO"+ debugDocumentVersioning = "YES"+ debugServiceExtension = "internal"+ allowLocationSimulation = "YES">+ </LaunchAction>+ <ProfileAction+ buildConfiguration = "Release"+ shouldUseLaunchSchemeArgsEnv = "YES"+ savedToolIdentifier = ""+ useCustomWorkingDirectory = "NO"+ debugDocumentVersioning = "YES">+ <MacroExpansion>+ <BuildableReference+ BuildableIdentifier = "primary"+ BlueprintIdentifier = "56C6048E234E3EA70008BBB9"+ BuildableName = "Supersign.framework"+ BlueprintName = "Supersign"+ ReferencedContainer = "container:Supercharge.xcodeproj">+ </BuildableReference>+ </MacroExpansion>+ </ProfileAction>+ <AnalyzeAction+ buildConfiguration = "Debug">+ </AnalyzeAction>+ <ArchiveAction+ buildConfiguration = "Release"+ revealArchiveInOrganizer = "YES">+ </ArchiveAction>+</Scheme>diff --git a/Supercharge/Master/Network/DeveloperServices/DeveloperServicesPlatformRequest.swift b/Supersign/DeveloperServices/DeveloperServicesPlatformRequest.swiftsimilarity index 80%rename from Supercharge/Master/Network/DeveloperServices/DeveloperServicesPlatformRequest.swiftrename to Supersign/DeveloperServices/DeveloperServicesPlatformRequest.swiftindex 2279d61..e202b30 100644--- a/Supercharge/Master/Network/DeveloperServices/DeveloperServicesPlatformRequest.swift+++ b/Supersign/DeveloperServices/DeveloperServicesPlatformRequest.swift@@ -8,19 +8,19 @@import Foundation-enum DeveloperServicesPlatform: String, Decodable {+public enum DeveloperServicesPlatform: String, Decodable {case iOS = "ios"case watchOS = "watchos"case tvOS = "tvos"- fileprivate var os: String {+ var os: String {switch self {case .iOS, .watchOS: return "ios"case .tvOS: return "tvos"}}- fileprivate var subPlatform: String? {+ var subPlatform: String? {switch self {case .iOS, .watchOS: return nilcase .tvOS: return "tvOS"@@ -37,9 +37,9 @@ protocol DeveloperServicesPlatformRequest: DeveloperServicesRequest {extension DeveloperServicesPlatformRequest {- var action: String { return "\(platform.os)/\(subAction)" }+ public var action: String { return "\(platform.os)/\(subAction)" }- var parameters: [String: Any] {+ public var parameters: [String: Any] {var parameters = subParametersparameters["DTDK_Platform"] = platform.rawValueparameters["subPlatform"] = platform.subPlatformdiff --git a/Supercharge/Master/Network/DeveloperServices/DeveloperServicesRequest.swift b/Supersign/DeveloperServices/DeveloperServicesRequest.swiftsimilarity index 80%rename from Supercharge/Master/Network/DeveloperServices/DeveloperServicesRequest.swiftrename to Supersign/DeveloperServices/DeveloperServicesRequest.swiftindex ee98f9d..96b3793 100644--- a/Supercharge/Master/Network/DeveloperServices/DeveloperServicesRequest.swift+++ b/Supersign/DeveloperServices/DeveloperServicesRequest.swift@@ -8,7 +8,7 @@import Foundation-protocol DeveloperServicesRequest {+public protocol DeveloperServicesRequest {associatedtype Response: Decodableassociatedtype Value@@ -21,11 +21,11 @@ protocol DeveloperServicesRequest {func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void)}-extension DeveloperServicesRequest {+public extension DeveloperServicesRequest {func configure(urlRequest: inout URLRequest) {}}-extension DeveloperServicesRequest where Response == Value {+public extension DeveloperServicesRequest where Response == Value {func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {completion(.success(response))}diff --git a/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesAddAppGroupRequest.swift b/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesAddAppGroupRequest.swiftnew file mode 100644index 0000000..ad14360--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesAddAppGroupRequest.swift@@ -0,0 +1,48 @@+//+// DeveloperServicesAddAppGroupRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesAddAppGroupRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ let applicationGroup: DeveloperServicesAppGroup+ }+ public typealias Value = DeveloperServicesAppGroup++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let name: String+ public let groupID: DeveloperServicesAppGroup.GroupID++ var subAction: String { return "addApplicationGroup" }+ var subParameters: [String: Any] {+ return [+ "teamId": teamID.rawValue,+ "name": name,+ "identifier": groupID.rawValue+ ]+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.applicationGroup))+ }++ public init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ name: String,+ groupID: DeveloperServicesAppGroup.GroupID+ ) {+ self.platform = platform+ self.teamID = teamID+ self.name = name+ self.groupID = groupID+ }++}diff --git a/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesAppGroup.swift b/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesAppGroup.swiftnew file mode 100644index 0000000..7e0aedf--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesAppGroup.swift@@ -0,0 +1,31 @@+//+// DeveloperServiceAppGroup.swift+// Supercharge+//+// Created by Kabir Oberai on 29/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesAppGroup: Decodable {+ public struct ID: RawRepresentable, Decodable {+ public let rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+ }+ public let id: ID++ public let name: String++ public struct GroupID: RawRepresentable, Hashable, Codable {+ public let rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+ }+ public let groupID: GroupID++ private enum CodingKeys: String, CodingKey {+ case id = "applicationGroup"+ case name+ case groupID = "identifier"+ }+}diff --git a/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesAssignAppGroupRequest.swift b/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesAssignAppGroupRequest.swiftnew file mode 100644index 0000000..f93de5a--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesAssignAppGroupRequest.swift@@ -0,0 +1,42 @@+//+// DeveloperServicesAssignAppGroupRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public class DeveloperServicesAssignAppGroupRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {}+ public typealias Value = Response++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let appIDID: DeveloperServicesAppID.ID+ public let groupID: DeveloperServicesAppGroup.ID++ var subAction: String { return "assignApplicationGroupToAppId" }+ var subParameters: [String: Any] {+ return [+ "teamId": teamID.rawValue,+ "appIdId": appIDID.rawValue,+ "applicationGroups": groupID.rawValue+ ]+ }++ public init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ appIDID: DeveloperServicesAppID.ID,+ groupID: DeveloperServicesAppGroup.ID+ ) {+ self.platform = platform+ self.teamID = teamID+ self.appIDID = appIDID+ self.groupID = groupID+ }++}diff --git a/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesListAppGroupsRequest.swift b/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesListAppGroupsRequest.swiftnew file mode 100644index 0000000..4bf05f6--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App Groups/DeveloperServicesListAppGroupsRequest.swift@@ -0,0 +1,35 @@+//+// DeveloperServicesListAppGroupsRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesListAppGroupsRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ public let applicationGroupList: [DeveloperServicesAppGroup]+ }+ public typealias Value = [DeveloperServicesAppGroup]++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID++ var subAction: String { return "listApplicationGroups" }+ var subParameters: [String: Any] {+ return ["teamId": teamID.rawValue]+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.applicationGroupList))+ }++ public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {+ self.platform = platform+ self.teamID = teamID+ }++}diff --git a/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesAddAppIDRequest.swift b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesAddAppIDRequest.swiftnew file mode 100644index 0000000..b1a6017--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesAddAppIDRequest.swift@@ -0,0 +1,66 @@+//+// DeveloperServicesAddAppIDRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesAddAppIDRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ let appId: DeveloperServicesAppID+ }+ public typealias Value = DeveloperServicesAppID++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let bundleID: String+ public let appName: String+ public let entitlements: Entitlements+ public let additionalFeatures: [DeveloperServicesFeature]+ public let isFree: Bool++ var subAction: String { return "addAppId" }+ var subParameters: [String: Any] {+ var parameters: [String: Any] = [+ "teamId": teamID.rawValue,+ "identifier": bundleID,+ "name": appName+ ]++ DeveloperServicesAppIDRequestApplier.apply(+ entitlements: entitlements,+ additionalFeatures: additionalFeatures,+ to: ¶meters,+ isFree: isFree+ )++ return parameters+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.appId))+ }++ public init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ bundleID: String,+ appName: String,+ entitlements: Entitlements,+ additionalFeatures: [DeveloperServicesFeature],+ isFree: Bool+ ) {+ self.platform = platform+ self.teamID = teamID+ self.bundleID = bundleID+ self.appName = appName+ self.entitlements = entitlements+ self.additionalFeatures = additionalFeatures+ self.isFree = isFree+ }++}diff --git a/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesAppID.swift b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesAppID.swiftnew file mode 100644index 0000000..e70f1b5--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesAppID.swift@@ -0,0 +1,47 @@+//+// DeveloperServiceAppID.swift+// Supercharge+//+// Created by Kabir Oberai on 29/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation+import ProtoCodable++public struct DeveloperServicesAppID: Decodable {+ public struct ID: RawRepresentable, Decodable {+ public let rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+ }++ public let id: ID+ public let name: String+ public let platform: DeveloperServicesPlatform+ public let bundleID: String+ public let isWildCard: Bool++ private let _features: DeveloperServicesFeatures+ public var features: [DeveloperServicesFeature] { return _features.values }++ private let _enabledFeatures: [String]?+ public var enabledFeatures: [DeveloperServicesFeature.Type] {+ guard let enabledFeatures = _enabledFeatures else { return [] }+ return enabledFeatures.compactMap { identifier in+ let type = ProtoCodableIdentifierMapper.shared.type(+ for: identifier, in: DeveloperServicesFeatureContainer.self+ )+ return type as? DeveloperServicesFeature.Type+ }+ }++ private enum CodingKeys: String, CodingKey {+ case id = "appIdId"+ case name+ case platform = "appIdPlatform"+ case bundleID = "identifier"+ case isWildCard+ case _features = "features"+ case _enabledFeatures = "enabledFeatures"+ }+}diff --git a/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesAppIDRequestApplier.swift b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesAppIDRequestApplier.swiftnew file mode 100644index 0000000..6edb688--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesAppIDRequestApplier.swift@@ -0,0 +1,31 @@+//+// DeveloperServicesAppIDRequestApplier.swift+// Supersign+//+// Created by Kabir Oberai on 11/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++enum DeveloperServicesAppIDRequestApplier {+ static func apply(+ entitlements: Entitlements, additionalFeatures: [DeveloperServicesFeature],+ to dict: inout [String: Any], isFree: Bool+ ) {+ var entitlements = entitlements+ try? entitlements.updateEntitlements {+ $0.removeAll {+ let type = Swift.type(of: $0)+ return !type.canList || (isFree && !type.isFree)+ }+ }+ dict["entitlements"] = try? entitlements.plistValue()++ let entFeatures = (try? entitlements.entitlements().compactMap { $0.feature() }) ?? []+ let allFeatures = entFeatures + additionalFeatures+ guard let features = try? DeveloperServicesFeatures(values: allFeatures).plistValue() as? [String: Any]+ else { return }+ dict.merge(features) { a, _ in a }+ }+}diff --git a/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesDeleteAppIDRequest.swift b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesDeleteAppIDRequest.swiftnew file mode 100644index 0000000..0874ea3--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesDeleteAppIDRequest.swift@@ -0,0 +1,35 @@+//+// DeveloperServicesDeleteAppIDRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesDeleteAppIDRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {}+ public typealias Value = Response++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let appIDID: DeveloperServicesAppID.ID++ var subAction: String { return "deleteAppId" }+ var subParameters: [String: Any] {+ return ["teamId": teamID.rawValue, "appIdId": appIDID.rawValue]+ }++ public init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ appIDID: DeveloperServicesAppID.ID+ ) {+ self.platform = platform+ self.teamID = teamID+ self.appIDID = appIDID+ }++}diff --git a/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesListAppIDsRequest.swift b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesListAppIDsRequest.swiftnew file mode 100644index 0000000..f1fa0e5--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesListAppIDsRequest.swift@@ -0,0 +1,35 @@+//+// DeveloperServicesListAppIDsRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesListAppIDsRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ public let appIds: [DeveloperServicesAppID]+ }+ public typealias Value = [DeveloperServicesAppID]++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID++ var subAction: String { return "listAppIds" }+ var subParameters: [String: Any] {+ return ["teamId": teamID.rawValue]+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.appIds))+ }++ public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {+ self.platform = platform+ self.teamID = teamID+ }++}diff --git a/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesUpdateAppIDRequest.swift b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesUpdateAppIDRequest.swiftnew file mode 100644index 0000000..f4706a7--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/DeveloperServicesUpdateAppIDRequest.swift@@ -0,0 +1,62 @@+//+// DeveloperServicesUpdateAppIDRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesUpdateAppIDRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ let appId: DeveloperServicesAppID+ }+ public typealias Value = DeveloperServicesAppID++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let appIDID: DeveloperServicesAppID.ID+ public let entitlements: Entitlements+ public let additionalFeatures: [DeveloperServicesFeature]+ public let isFree: Bool++ var subAction: String { return "updateAppId" }+ var subParameters: [String: Any] {+ var parameters: [String: Any] = [+ "teamId": teamID.rawValue,+ "appIdId": appIDID.rawValue+ ]++ DeveloperServicesAppIDRequestApplier.apply(+ entitlements: entitlements,+ additionalFeatures: additionalFeatures,+ to: ¶meters,+ isFree: isFree+ )++ return parameters+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.appId))+ }++ public init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ appIDID: DeveloperServicesAppID.ID,+ entitlements: Entitlements,+ additionalFeatures: [DeveloperServicesFeature],+ isFree: Bool+ ) {+ self.platform = platform+ self.teamID = teamID+ self.appIDID = appIDID+ self.entitlements = entitlements+ self.additionalFeatures = additionalFeatures+ self.isFree = isFree+ }++}diff --git a/Supersign/DeveloperServices/Requests/App IDs/Entitlements/Entitlement+DeveloperServicesFeature.swift b/Supersign/DeveloperServices/Requests/App IDs/Entitlements/Entitlement+DeveloperServicesFeature.swiftnew file mode 100644index 0000000..c2341a7--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/Entitlements/Entitlement+DeveloperServicesFeature.swift@@ -0,0 +1,38 @@+//+// Entitlement+DeveloperServicesFeature.swift+// Supersign+//+// Created by Kabir Oberai on 09/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++protocol BaseEntitlementWithFeature: Entitlement {+ func baseFeature() -> DeveloperServicesFeature+}++protocol EntitlementWithFeature: BaseEntitlementWithFeature {+ associatedtype Feature: DeveloperServicesFeature+ func typedFeature() -> Feature+}+extension EntitlementWithFeature {+ func baseFeature() -> DeveloperServicesFeature {+ return typedFeature()+ }+}++extension EntitlementWithFeature+ where Self: RawRepresentable,+ Feature: RawRepresentable,+ RawValue == Feature.RawValue {+ func typedFeature() -> Feature {+ return Feature(rawValue: rawValue)!+ }+}++public extension Entitlement {+ func feature() -> DeveloperServicesFeature? {+ return (self as? BaseEntitlementWithFeature)?.baseFeature()+ }+}diff --git a/Supersign/DeveloperServices/Requests/App IDs/Entitlements/EntitlementWithTeamOrBundleID.swift b/Supersign/DeveloperServices/Requests/App IDs/Entitlements/EntitlementWithTeamOrBundleID.swiftnew file mode 100644index 0000000..cb361a9--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/Entitlements/EntitlementWithTeamOrBundleID.swift@@ -0,0 +1,46 @@+//+// EntitlementWithTeamOrBundleID.swift+// Supersign+//+// Created by Kabir Oberai on 12/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++protocol EntitlementWithTeamOrBundleID: Entitlement {+ init(teamID: DeveloperServicesTeam.ID, bundleID: String)+}++extension ApplicationIdentifierEntitlement: EntitlementWithTeamOrBundleID {+ init(teamID: DeveloperServicesTeam.ID, bundleID: String) {+ self.rawValue = "\(teamID.rawValue).\(bundleID)"+ }+}++extension TeamIdentifierEntitlement: EntitlementWithTeamOrBundleID {+ init(teamID: DeveloperServicesTeam.ID, bundleID: String) {+ self.rawValue = teamID.rawValue+ }+}++extension KeychainAccessGroupsEntitlement: EntitlementWithTeamOrBundleID {+ init(teamID: DeveloperServicesTeam.ID, bundleID: String) {+ rawValue = ["\(teamID.rawValue).*"]+ }+}++extension Entitlements {++ public mutating func update(teamID: DeveloperServicesTeam.ID, bundleID: String) throws {+ let teamOrBundleIDTypes = EntitlementContainer.supportedTypes+ .compactMap { $0 as? EntitlementWithTeamOrBundleID.Type }+ let teamOrBundleIDSet = Set(teamOrBundleIDTypes.map(ObjectIdentifier.init))++ try updateEntitlements { entitlements in+ entitlements.removeAll { teamOrBundleIDSet.contains(ObjectIdentifier(type(of: $0))) }+ entitlements += teamOrBundleIDTypes.map { $0.init(teamID: teamID, bundleID: bundleID) }+ }+ }++}diff --git a/Supersign/DeveloperServices/Requests/App IDs/Features/DeveloperServicesFeature.swift b/Supersign/DeveloperServices/Requests/App IDs/Features/DeveloperServicesFeature.swiftnew file mode 100644index 0000000..79fb4fc--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/Features/DeveloperServicesFeature.swift@@ -0,0 +1,14 @@+//+// DeveloperServicesFeature.swift+// Supercharge+//+// Created by Kabir Oberai on 29/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation+import ProtoCodable++public protocol DeveloperServicesFeature: ProtoCodable {+ static var identifier: String { get }+}diff --git a/Supersign/DeveloperServices/Requests/App IDs/Features/DeveloperServicesFeatureTypes.swift b/Supersign/DeveloperServices/Requests/App IDs/Features/DeveloperServicesFeatureTypes.swiftnew file mode 100644index 0000000..d8e0c76--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/Features/DeveloperServicesFeatureTypes.swift@@ -0,0 +1,263 @@+//+// DeveloperServicesFeatureTypes.swift+// Supercharge+//+// Created by Kabir Oberai on 29/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation+import ProtoCodable++// swiftlint:disable type_name++extension DeveloperServicesFeatureContainer {+ static let supportedTypes: [ProtoCodable.Type] = [+ DeveloperServicesCloudKitFeature.self,+ DeveloperServicesDataProtectionFeature.self,+ DeveloperServicesAccessWifiFeature.self,+ DeveloperServicesAppGroupFeature.self,+ DeveloperServicesApplePayFeature.self,+ DeveloperServicesAssociatedDomainsFeature.self,+ DeveloperServicesClassKitFeature.self,+ DeveloperServicesAutoFillCredentialFeature.self,+ DeveloperServicesGameCenterFeature.self,+ DeveloperServicesHealthKitFeature.self,+ DeveloperServicesHomeKitFeature.self,+ DeveloperServicesHotspotFeature.self,+ DeveloperServicesCloudFeature.self,+ DeveloperServicesInAppPurchaseFeature.self,+ DeveloperServicesInterAppAudioFeature.self,+ DeveloperServicesMultipathFeature.self,+ DeveloperServicesNetworkExtensionFeature.self,+ DeveloperServicesNFCTagReadingFeature.self,+ DeveloperServicesPersonalVPNFeature.self,+ DeveloperServicesPassbookFeature.self,+ DeveloperServicesPushNotificationFeature.self,+ DeveloperServicesSiriKitFeature.self,+ DeveloperServicesVPNConfigurationFeature.self,+ DeveloperServicesWalletFeature.self,+ DeveloperServicesWirelessAccessoryFeature.self,+ ]+}++// MARK: - Special Features++public enum DeveloperServicesCloudKitFeature: Int, DeveloperServicesFeature {+ public static let identifier = "cloudKitVersion"++ case xcode5Compatible = 1+ case cloudKit = 2+}++public enum DeveloperServicesDataProtectionFeature: String, DeveloperServicesFeature {+ public static let identifier = "dataProtection"++ case off = ""+ case complete+ case unlessOpen = "unlessopen"+ case untilFirstAuth = "untilfirstauth"+}+extension DataProtectionEntitlement: EntitlementWithFeature {+ func typedFeature() -> DeveloperServicesDataProtectionFeature {+ switch self {+ case .complete: return .complete+ case .unlessOpen: return .unlessOpen+ case .untilFirstAuth: return .untilFirstAuth+ }+ }+}++// MARK: - Boolean Features++// https://github.com/fastlane/fastlane/blob/master/spaceship/lib/spaceship/portal/app_service.rb++public struct DeveloperServicesAccessWifiFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "AWEQ28MY3E"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesAppGroupFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "APG3427HIY"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}+extension AppGroupEntitlement: EntitlementWithFeature {+ func typedFeature() -> DeveloperServicesAppGroupFeature {+ return .init(rawValue: !rawValue.isEmpty)+ }+}++public struct DeveloperServicesApplePayFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "OM633U5T5G"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesAssociatedDomainsFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "SKC3T5S89Y"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesClassKitFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "PKTJAN2017"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesAutoFillCredentialFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "CPEQ28MX4E"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesGameCenterFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "gameCenter"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesHealthKitFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "HK421J6T7P"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}+extension HealthKitEntitlement: EntitlementWithFeature {+ typealias Feature = DeveloperServicesHealthKitFeature+}++public struct DeveloperServicesHomeKitFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "homeKit"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}+extension HomeKitEntitlement: EntitlementWithFeature {+ typealias Feature = DeveloperServicesHomeKitFeature+}++public struct DeveloperServicesHotspotFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "HSC639VEI8"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesCloudFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "iCloud"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesInAppPurchaseFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "inAppPurchase"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesInterAppAudioFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "IAD53UNK2F"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}+extension InterAppAudioEntitlement: EntitlementWithFeature {+ typealias Feature = DeveloperServicesInterAppAudioFeature+}++public struct DeveloperServicesMultipathFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "MP49FN762P"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}+extension MultipathEntitlement: EntitlementWithFeature {+ typealias Feature = DeveloperServicesMultipathFeature+}++public struct DeveloperServicesNetworkExtensionFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "NWEXT04537"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}+extension NetworkExtensionEntitlement: EntitlementWithFeature {+ typealias Feature = DeveloperServicesNetworkExtensionFeature+}++public struct DeveloperServicesNFCTagReadingFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "NFCTRMAY17"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesPersonalVPNFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "V66P55NK2I"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesPassbookFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "passbook"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesPushNotificationFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "push"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesSiriKitFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "SI015DKUHP"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}+extension SiriKitEntitlement: EntitlementWithFeature {+ typealias Feature = DeveloperServicesSiriKitFeature+}++public struct DeveloperServicesVPNConfigurationFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "V66P55NK2I"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}+extension VPNConfigurationEntitlement: EntitlementWithFeature {+ typealias Feature = DeveloperServicesVPNConfigurationFeature+}++public struct DeveloperServicesWalletFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "pass"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct DeveloperServicesWirelessAccessoryFeature: DeveloperServicesFeature, RawRepresentable {+ public static let identifier = "WC421J6T7P"++ public let rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}+extension WirelessAccessoryEntitlement: EntitlementWithFeature {+ typealias Feature = DeveloperServicesWirelessAccessoryFeature+}diff --git a/Supersign/DeveloperServices/Requests/App IDs/Features/DeveloperServicesFeatures.swift b/Supersign/DeveloperServices/Requests/App IDs/Features/DeveloperServicesFeatures.swiftnew file mode 100644index 0000000..cc63f11--- /dev/null+++ b/Supersign/DeveloperServices/Requests/App IDs/Features/DeveloperServicesFeatures.swift@@ -0,0 +1,16 @@+//+// DeveloperServicesFeatures.swift+// Supercharge+//+// Created by Kabir Oberai on 19/09/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation+import ProtoCodable++struct DeveloperServicesFeatureContainer: ProtoCodableContainer {+ var value: DeveloperServicesFeature+}++typealias DeveloperServicesFeatures = ProtoCodableKeyValueContainer<DeveloperServicesFeatureContainer>diff --git a/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesCSRResponse.swift b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesCSRResponse.swiftnew file mode 100644index 0000000..eb92abe--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesCSRResponse.swift@@ -0,0 +1,37 @@+//+// DeveloperServicesCSRResponse.swift+// Supersign+//+// Created by Kabir Oberai on 09/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesCSRResponse: Decodable {+ public struct ID: RawRepresentable, Decodable {+ public let rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+ }+ public let id: ID+ public let certificateID: DeveloperServicesCertificate.ID+ public let serialNumber: DeveloperServicesCertificate.SerialNumber+ public let type: DeveloperServicesCertificate.CertificateType+ public let status: String+ public let statusCode: Int+ public let platform: DeveloperServicesPlatform+ public let machineID: String?+ public let machineName: String?++ private enum CodingKeys: String, CodingKey {+ case id = "certRequestId"+ case certificateID = "certificateId"+ case serialNumber = "serialNum"+ case type = "certificateType"+ case status = "statusString"+ case statusCode+ case platform = "csrPlatform"+ case machineID = "machineId"+ case machineName+ }+}diff --git a/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesCertificate.swift b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesCertificate.swiftnew file mode 100644index 0000000..2f7f1da--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesCertificate.swift@@ -0,0 +1,57 @@+//+// DeveloperServicesCertificate.swift+// Supercharge+//+// Created by Kabir Oberai on 29/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesCertificate: Decodable {+ public struct ID: RawRepresentable, Decodable {+ public let rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+ }+ public let id: ID++ public struct SerialNumber: RawRepresentable, Decodable {+ public let rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+ }+ public let serialNumber: SerialNumber++ public struct CertificateType: Decodable {+ public let displayID: String+ public let name: String+ public let maxActive: Int++ private enum CodingKeys: String, CodingKey {+ case displayID = "certificateTypeDisplayId"+ case name+ case maxActive+ }+ }+ public let type: CertificateType++ public let status: String+ public let statusCode: Int+ public let expiry: Date+ public let platform: DeveloperServicesPlatform+ public let machineID: String?+ public let machineName: String?+ public let content: Certificate++ private enum CodingKeys: String, CodingKey {+ case id = "certificateId"+ case serialNumber+ case type = "certificateType"+ case status+ case statusCode+ case expiry = "expirationDate"+ case platform = "certificatePlatform"+ case content = "certContent"+ case machineID = "machineId"+ case machineName+ }+}diff --git a/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesListCertificatesRequest.swift b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesListCertificatesRequest.swiftnew file mode 100644index 0000000..c3fbf65--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesListCertificatesRequest.swift@@ -0,0 +1,35 @@+//+// DeveloperServicesListCertificatesRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesListCertificatesRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ public let certificates: [DeveloperServicesCertificate]+ }+ public typealias Value = [DeveloperServicesCertificate]++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID++ var subAction: String { return "listAllDevelopmentCerts" }+ var subParameters: [String: Any] {+ return ["teamId": teamID.rawValue]+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.certificates))+ }++ public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {+ self.platform = platform+ self.teamID = teamID+ }++}diff --git a/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesRevokeCertificateRequest.swift b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesRevokeCertificateRequest.swiftnew file mode 100644index 0000000..6d9f0e9--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesRevokeCertificateRequest.swift@@ -0,0 +1,36 @@+//+// DeveloperServicesRevokeCertificateRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++// swiftlint:disable:next type_name+public struct DeveloperServicesRevokeCertificateRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {}+ public typealias Value = Response++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let serialNumber: DeveloperServicesCertificate.SerialNumber++ var subAction: String { return "revokeDevelopmentCert" }+ var subParameters: [String: Any] {+ return ["teamId": teamID.rawValue, "serialNumber": serialNumber.rawValue]+ }++ init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ serialNumber: DeveloperServicesCertificate.SerialNumber+ ) {+ self.platform = platform+ self.teamID = teamID+ self.serialNumber = serialNumber+ }++}diff --git a/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesSubmitCSRRequest.swift b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesSubmitCSRRequest.swiftnew file mode 100644index 0000000..e95c19f--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Certificates/DeveloperServicesSubmitCSRRequest.swift@@ -0,0 +1,53 @@+//+// DeveloperServicesSubmitCSRRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public class DeveloperServicesSubmitCSRRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ public let certRequest: DeveloperServicesCSRResponse+ }+ public typealias Value = DeveloperServicesCSRResponse++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let csr: CSR+ public let machineName: String+ public let machineID: String++ var subAction: String { return "submitDevelopmentCSR" }+ var subParameters: [String: Any] {+ let csrString = String(data: csr.data, encoding: .utf8) ?? ""+ return [+ "teamId": teamID.rawValue,+ "csrContent": csrString,+ "machineId": machineID,+ "machineName": machineName+ ]+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.certRequest))+ }++ public init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ csr: CSR,+ machineName: String,+ machineID: String+ ) {+ self.platform = platform+ self.teamID = teamID+ self.csr = csr+ self.machineName = machineName+ self.machineID = machineID+ }++}diff --git a/Supersign/DeveloperServices/Requests/Developer/DeveloperServicesViewDeveloperRequest.swift b/Supersign/DeveloperServices/Requests/Developer/DeveloperServicesViewDeveloperRequest.swiftnew file mode 100644index 0000000..e4a69e0--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Developer/DeveloperServicesViewDeveloperRequest.swift@@ -0,0 +1,39 @@+//+// DeveloperServicesViewDeveloperRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesViewDeveloperRequest: DeveloperServicesRequest {++ public struct Developer: Decodable {+ public let email: String++ public let firstName: String+ public let lastName: String++ public let dsFirstName: String+ public let dsLastName: String++ public let developerStatus: String+ }++ public struct Response: Decodable {+ let developer: Developer+ }+ public typealias Value = Developer++ public var action: String { return "viewDeveloper" }+ public var parameters: [String: Any] { return [:] }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.developer))+ }++ public init() {}++}diff --git a/Supersign/DeveloperServices/Requests/Devices/DeveloperServicesAddDeviceRequest.swift b/Supersign/DeveloperServices/Requests/Devices/DeveloperServicesAddDeviceRequest.swiftnew file mode 100644index 0000000..c35f964--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Devices/DeveloperServicesAddDeviceRequest.swift@@ -0,0 +1,48 @@+//+// DeveloperServicesAddDeviceRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesAddDeviceRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ let device: DeveloperServicesDevice+ }+ public typealias Value = DeveloperServicesDevice++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let udid: String+ public let name: String++ var subAction: String { return "addDevice" }+ var subParameters: [String: Any] {+ return [+ "teamId": teamID.rawValue,+ "deviceNumber": udid,+ "name": name+ ]+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.device))+ }++ public init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ udid: String,+ name: String+ ) {+ self.platform = platform+ self.teamID = teamID+ self.udid = udid+ self.name = name+ }++}diff --git a/Supersign/DeveloperServices/Requests/Devices/DeveloperServicesDevice.swift b/Supersign/DeveloperServices/Requests/Devices/DeveloperServicesDevice.swiftnew file mode 100644index 0000000..d7b8cad--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Devices/DeveloperServicesDevice.swift@@ -0,0 +1,32 @@+//+// DeveloperServicesDevice.swift+// Supercharge+//+// Created by Kabir Oberai on 07/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesDevice: Decodable {+ public struct ID: RawRepresentable, Decodable {+ public let rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+ }++ public let id: ID+ public let name: String+ public let udid: String+ public let platform: DeveloperServicesPlatform+ public let type: String // TODO: Create enum+ public let model: String++ private enum CodingKeys: String, CodingKey {+ case id = "deviceId"+ case name+ case udid = "deviceNumber"+ case platform = "devicePlatform"+ case type = "deviceClass"+ case model+ }+}diff --git a/Supersign/DeveloperServices/Requests/Devices/DeveloperServicesListDevicesRequest.swift b/Supersign/DeveloperServices/Requests/Devices/DeveloperServicesListDevicesRequest.swiftnew file mode 100644index 0000000..06bba5c--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Devices/DeveloperServicesListDevicesRequest.swift@@ -0,0 +1,39 @@+//+// DeveloperServicesListDevicesRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesListDevicesRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ public let devices: [DeveloperServicesDevice]+ }+ public typealias Value = [DeveloperServicesDevice]++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID++ var subAction: String { return "listDevices" }+ var subParameters: [String: Any] {+ return [+ "teamId": teamID.rawValue,+ "pageSize": "500",+ "includeRemovedDevices": "false"+ ]+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.devices))+ }++ public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {+ self.platform = platform+ self.teamID = teamID+ }++}diff --git a/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesDeleteProfileRequest.swift b/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesDeleteProfileRequest.swiftnew file mode 100644index 0000000..d5d9c06--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesDeleteProfileRequest.swift@@ -0,0 +1,35 @@+//+// DeveloperServicesDeleteProfileRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesDeleteProfileRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {}+ public typealias Value = Response++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let profileID: DeveloperServicesProfile.ID++ var subAction: String { return "deleteProvisioningProfile" }+ var subParameters: [String: Any] {+ return ["teamId": teamID.rawValue, "provisioningProfileId": profileID.rawValue]+ }++ public init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ profileID: DeveloperServicesProfile.ID+ ) {+ self.platform = platform+ self.teamID = teamID+ self.profileID = profileID+ }++}diff --git a/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesGetProfileRequest.swift b/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesGetProfileRequest.swiftnew file mode 100644index 0000000..c23ded1--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesGetProfileRequest.swift@@ -0,0 +1,41 @@+//+// DeveloperServicesGetProfileRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesGetProfileRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ public let provisioningProfile: DeveloperServicesProfile+ }+ public typealias Value = DeveloperServicesProfile++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID+ public let appIDID: DeveloperServicesAppID.ID++ var subAction: String { return "downloadTeamProvisioningProfile" }+ var subParameters: [String: Any] {+ return ["teamId": teamID.rawValue, "appIdId": appIDID.rawValue]+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.provisioningProfile))+ }++ public init(+ platform: DeveloperServicesPlatform,+ teamID: DeveloperServicesTeam.ID,+ appIDID: DeveloperServicesAppID.ID+ ) {+ self.platform = platform+ self.teamID = teamID+ self.appIDID = appIDID+ }++}diff --git a/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesListProfilesRequest.swift b/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesListProfilesRequest.swiftnew file mode 100644index 0000000..0166972--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesListProfilesRequest.swift@@ -0,0 +1,35 @@+//+// DeveloperServicesListProfilesRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesListProfilesRequest: DeveloperServicesPlatformRequest {++ public struct Response: Decodable {+ public let provisioningProfiles: [DeveloperServicesProfile]+ }+ public typealias Value = [DeveloperServicesProfile]++ public let platform: DeveloperServicesPlatform+ public let teamID: DeveloperServicesTeam.ID++ var subAction: String { return "listProvisioningProfiles" }+ var subParameters: [String: Any] {+ return ["teamId": teamID.rawValue]+ }++ public func parse(_ response: Response, completion: @escaping (Result<Value, Error>) -> Void) {+ completion(.success(response.provisioningProfiles))+ }++ public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {+ self.platform = platform+ self.teamID = teamID+ }++}diff --git a/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesProfile.swift b/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesProfile.swiftnew file mode 100644index 0000000..e09f237--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Profiles/DeveloperServicesProfile.swift@@ -0,0 +1,44 @@+//+// DeveloperServicesProfile.swift+// Supercharge+//+// Created by Kabir Oberai on 29/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesProfile: Decodable {+ public struct ID: RawRepresentable, Decodable {+ public let rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+ }++ public let id: ID+ public let name: String+ public let status: String+ public let type: String+ public let platform: DeveloperServicesPlatform+ public let uuid: String+ public let version: String+ public let expiry: Date+ public let appIDID: DeveloperServicesAppID.ID+ public let appID: DeveloperServicesAppID+ public let isFree: Bool+ public let mobileprovision: Mobileprovision?++ private enum CodingKeys: String, CodingKey {+ case id = "provisioningProfileId"+ case name+ case status+ case type+ case platform = "proProPlatform"+ case uuid = "UUID"+ case version+ case expiry = "dateExpire"+ case appIDID = "appIdId"+ case appID = "appId"+ case isFree = "isFreeProvisioningProfile"+ case mobileprovision = "encodedProfile"+ }+}diff --git a/Supersign/DeveloperServices/Requests/Teams/DeveloperServicesListTeamsRequest.swift b/Supersign/DeveloperServices/Requests/Teams/DeveloperServicesListTeamsRequest.swiftnew file mode 100644index 0000000..4397070--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Teams/DeveloperServicesListTeamsRequest.swift@@ -0,0 +1,29 @@+//+// DeveloperServicesListTeamsRequest.swift+// Supercharge+//+// Created by Kabir Oberai on 24/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesListTeamsRequest: DeveloperServicesRequest {++ public struct Response: Decodable {+ public let teams: [DeveloperServicesTeam]+ }+ public typealias Value = [DeveloperServicesTeam]++ public var action: String { return "listTeams" }+ public var parameters: [String: Any] { return [:] }++ public func parse(+ _ response: Response, completion: @escaping (Result<[DeveloperServicesTeam], Error>) -> Void+ ) {+ completion(.success(response.teams))+ }++ public init() {}++}diff --git a/Supersign/DeveloperServices/Requests/Teams/DeveloperServicesTeam.swift b/Supersign/DeveloperServices/Requests/Teams/DeveloperServicesTeam.swiftnew file mode 100644index 0000000..2f2ab13--- /dev/null+++ b/Supersign/DeveloperServices/Requests/Teams/DeveloperServicesTeam.swift@@ -0,0 +1,37 @@+//+// DeveloperServicesTeam.swift+// Supercharge+//+// Created by Kabir Oberai on 29/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct DeveloperServicesTeam: Decodable {+ public struct ID: RawRepresentable, Decodable {+ public let rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+ }++ public let id: ID+ public let status: String+ public let name: String++ public struct Membership: Decodable {+ public let name: String+ public let platform: DeveloperServicesPlatform+ }+ public let memberships: [Membership]++ public var isFree: Bool {+ !memberships.contains { $0.platform == .iOS && $0.name.contains("Apple Developer Program") }+ }++ private enum CodingKeys: String, CodingKey {+ case id = "teamId"+ case status+ case name+ case memberships+ }+}diff --git a/Supersign/Model/Certificate/Certificate.swift b/Supersign/Model/Certificate/Certificate.swiftnew file mode 100644index 0000000..da11f00--- /dev/null+++ b/Supersign/Model/Certificate/Certificate.swift@@ -0,0 +1,74 @@+//+// Certificate.swift+// Supercharge+//+// Created by Kabir Oberai on 07/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public class Certificate: Decodable {++ public enum Error: Swift.Error {+ case invalidCertificate+ }++ let raw: certificate_t++ private static func certificate(from data: Data) -> certificate_t? {+ data.withUnsafeBytes { bytes in+ let bound = bytes.bindMemory(to: Int8.self)+ return certificate_create_from_data(bound.baseAddress, bound.count)+ }+ }++ public init(data: Data) throws {+ guard let certificate = Self.certificate(from: data) else {+ throw Error.invalidCertificate+ }+ self.raw = certificate+ }++ public init(contentsOf url: URL) throws {+ guard let certificate = url.withUnsafeFileSystemRepresentation(certificate_create_from_path) else {+ throw Error.invalidCertificate+ }+ self.raw = certificate+ }++ public required init(from decoder: Decoder) throws {+ let container = try decoder.singleValueContainer()+ let data = try container.decode(Data.self)+ guard let certificate = Self.certificate(from: data) else {+ throw Error.invalidCertificate+ }+ self.raw = certificate+ }++ deinit {+ certificate_free(raw)+ }++ public func developerIdentity() throws -> String {+ guard let identity = certificate_get_developer_identity(raw) else {+ throw Error.invalidCertificate+ }+ return String(cString: identity)+ }++ public func serialNumber() throws -> String {+ guard let serial = certificate_copy_serial_number(raw) else {+ throw Error.invalidCertificate+ }+ defer { free(serial) }+ return String(cString: serial)+ }++ public func data() throws -> Data {+ guard let data = Data(cFunc: { certificate_generate_data(raw, $0) })+ else { throw Error.invalidCertificate }+ return data+ }++}diff --git a/Supersign/Model/Entitlements/Entitlement.swift b/Supersign/Model/Entitlements/Entitlement.swiftnew file mode 100644index 0000000..d2b695e--- /dev/null+++ b/Supersign/Model/Entitlements/Entitlement.swift@@ -0,0 +1,21 @@+//+// Entitlement.swift+// Supercharge+//+// Created by Kabir Oberai on 29/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation+import ProtoCodable++public protocol Entitlement: ProtoCodable {+ static var identifier: String { get }+ static var isFree: Bool { get }+ /// whether this entitlement should be included in developer services API requests+ static var canList: Bool { get }+}++public extension Entitlement {+ static var canList: Bool { return true }+}diff --git a/Supersign/Model/Entitlements/EntitlementTypes.swift b/Supersign/Model/Entitlements/EntitlementTypes.swiftnew file mode 100644index 0000000..06e1a6d--- /dev/null+++ b/Supersign/Model/Entitlements/EntitlementTypes.swift@@ -0,0 +1,163 @@+//+// EntitlementTypes.swift+// Supercharge+//+// Created by Kabir Oberai on 29/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation+import ProtoCodable++// swiftlint:disable type_name++extension EntitlementContainer {+ public static let supportedTypes: [ProtoCodable.Type] = [+ ApplicationIdentifierEntitlement.self,+ TeamIdentifierEntitlement.self,+ KeychainAccessGroupsEntitlement.self,+ GetTaskAllowEntitlement.self,+ AppGroupEntitlement.self,+ NetworkExtensionEntitlement.self,+ MultipathEntitlement.self,+ VPNConfigurationEntitlement.self,+ SiriKitEntitlement.self,+ InterAppAudioEntitlement.self,+ WirelessAccessoryEntitlement.self,+ HomeKitEntitlement.self,+ HealthKitEntitlement.self,+ ]+}++// MARK: - Entitlements without Features++public struct ApplicationIdentifierEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "application-identifier"+ public static let isFree = true++ public var rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+}++public struct TeamIdentifierEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "com.apple.developer.team-identifier"+ public static let isFree = true++ public var rawValue: String+ public init(rawValue: String) { self.rawValue = rawValue }+}++public struct KeychainAccessGroupsEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "keychain-access-groups"+ public static let isFree = true++ public var rawValue: [String]+ public init(rawValue: [String]) { self.rawValue = rawValue }++ // weird bug – the auto-generated implementation treats rawValue like a regular key for some reason+ public init(from decoder: Decoder) throws {+ rawValue = try decoder.singleValueContainer().decode([String].self)+ }+ public func encode(to encoder: Encoder) throws {+ var container = encoder.singleValueContainer()+ try container.encode(rawValue)+ }+}++public struct AppGroupEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "com.apple.security.application-groups"+ public static let isFree = true++ public var rawValue: [DeveloperServicesAppGroup.GroupID]+ public init(rawValue: [DeveloperServicesAppGroup.GroupID]) { self.rawValue = rawValue }++ public init(from decoder: Decoder) throws {+ rawValue = try decoder.singleValueContainer().decode([DeveloperServicesAppGroup.GroupID].self)+ }+ public func encode(to encoder: Encoder) throws {+ var container = encoder.singleValueContainer()+ try container.encode(rawValue)+ }+}++public struct GetTaskAllowEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "get-task-allow"+ public static let isFree = true+ public static let canList = false++ public var rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public enum DataProtectionEntitlement: String, Entitlement {+ public static let identifier = "com.apple.developer.default-data-protection"+ public static let isFree = true++ case complete = "NSFileProtectionComplete"+ case unlessOpen = "NSFileProtectionCompleteUnlessOpen"+ case untilFirstAuth = "NSFileProtectionCompleteUntilFirstUserAuthentication"+}++public struct NetworkExtensionEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "com.apple.developer.networking.networkextension"+ public static let isFree = false++ public var rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct MultipathEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "com.apple.developer.networking.multipath"+ public static let isFree = false++ public var rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct VPNConfigurationEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "com.apple.networking.vpn.configuration"+ public static let isFree = false++ public var rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct SiriKitEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "com.apple.developer.siri"+ public static let isFree = false++ public var rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct InterAppAudioEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "inter-app-audio"+ public static let isFree = true++ public var rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct WirelessAccessoryEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "com.apple.external-accessory.wireless-configuration"+ public static let isFree = true++ public var rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct HomeKitEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "com.apple.developer.homekit"+ public static let isFree = true++ public var rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}++public struct HealthKitEntitlement: Entitlement, RawRepresentable {+ public static let identifier = "com.apple.developer.healthkit"+ public static let isFree = true++ public var rawValue: Bool+ public init(rawValue: Bool) { self.rawValue = rawValue }+}diff --git a/Supersign/Model/Entitlements/Entitlements.swift b/Supersign/Model/Entitlements/Entitlements.swiftnew file mode 100644index 0000000..6642f0f--- /dev/null+++ b/Supersign/Model/Entitlements/Entitlements.swift@@ -0,0 +1,75 @@+//+// EntitlementContainer.swift+// Supercharge+//+// Created by Kabir Oberai on 19/09/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation+import ProtoCodable++public struct EntitlementContainer: ProtoCodableContainer {+ public var value: Entitlement+ public init(value: Entitlement) { self.value = value }+}++// allows access to a parsable entitlements list while not losing unparsed entitlements when it's modified+public struct Entitlements {++ public enum Error: Swift.Error {+ case dataCorrupted+ }++ private let decoder = PropertyListDecoder()+ private let encoder = PropertyListEncoder()++ private var dict: [String: PlistItem]++ public init(entitlements: [Entitlement]) throws {+ dict = [:]+ try setEntitlements(entitlements)+ }++ public func entitlements() throws -> [Entitlement] {+ try decoder.decode(+ ProtoCodableKeyValueContainer<EntitlementContainer>.self, from: encoder.encode(dict)+ ).values+ }++ // if `entitlements` and `setEntitlements` were the primitives, this function would end up performing+ // two entitlements() calls. This way we can optimize the number of calls.+ public mutating func updateEntitlements(_ block: (inout [Entitlement]) throws -> Void) throws {+ let old = try self.entitlements()++ var new = old+ try block(&new)++ let oldEnts = Dictionary(uniqueKeysWithValues: old.map { (type(of: $0).identifier, $0) })+ let newEnts = Dictionary(uniqueKeysWithValues: new.map { (type(of: $0).identifier, $0) })++ oldEnts.keys.filter { newEnts[$0] == nil }.forEach { dict[$0] = nil }+ try newEnts.forEach {+ dict[$0] = try PlistItem(value: $1.plistValue(withEncoder: encoder))+ }+ }++ public mutating func setEntitlements(_ new: [Entitlement]) throws {+ try updateEntitlements { $0 = new }+ }++}++extension Entitlements: Codable {++ public init(from decoder: Decoder) throws {+ self.dict = try decoder.singleValueContainer()+ .decode([String: PlistItem].self)+ }++ public func encode(to encoder: Encoder) throws {+ var container = encoder.singleValueContainer()+ try container.encode(dict)+ }++}diff --git a/Supersign/Model/Keypair/Keypair.swift b/Supersign/Model/Keypair/Keypair.swiftnew file mode 100644index 0000000..fe2bbfb--- /dev/null+++ b/Supersign/Model/Keypair/Keypair.swift@@ -0,0 +1,78 @@+//+// Keypair.swift+// Supercharge+//+// Created by Kabir Oberai on 07/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct PrivateKey {+ public let data: Data++ public init(data: Data) {+ self.data = data+ }++ public init(contentsOf url: URL) throws {+ self.data = try Data(contentsOf: url)+ }+}++public struct CSR {+ public let data: Data++ public init(data: Data) {+ self.data = data+ }++ public init(contentsOf url: URL) throws {+ self.data = try Data(contentsOf: url)+ }+}++public class Keypair {++ public enum Error: Swift.Error {+ case couldNotCreate+ case invalidKeypair+ }++ let raw: keypair_t++ public init() throws {+ guard let keypair = keypair_create() else {+ throw Error.couldNotCreate+ }+ self.raw = keypair+ }++ deinit {+ keypair_free(raw)+ }++ private func callKeypairDataFunc(+ fn: (keypair_t?, UnsafeMutablePointer<Int>?) -> UnsafeMutablePointer<Int8>?+ ) throws -> Data {+ var len = 0+ guard let bytes = fn(raw, &len) else {+ throw Error.invalidKeypair+ }+ defer { free(bytes) }+ return Data(bytes: UnsafeRawPointer(bytes), count: len)+ }++ public func privateKey() throws -> PrivateKey {+ guard let data = Data(cFunc: { keypair_copy_private_key(raw, $0) })+ else { throw Error.invalidKeypair }+ return PrivateKey(data: data)+ }++ public func generateCSR() throws -> CSR {+ guard let data = Data(cFunc: { keypair_generate_csr(raw, $0) })+ else { throw Error.invalidKeypair }+ return CSR(data: data)+ }++}diff --git a/Supersign/Model/Mobileprovision/Mobileprovision.swift b/Supersign/Model/Mobileprovision/Mobileprovision.swiftnew file mode 100644index 0000000..dcf1932--- /dev/null+++ b/Supersign/Model/Mobileprovision/Mobileprovision.swift@@ -0,0 +1,90 @@+//+// Mobileprovision.swift+// Supercharge+//+// Created by Kabir Oberai on 07/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public class Mobileprovision: Decodable {++ public enum Error: Swift.Error {+ case invalidProfile+ }++ public struct Digest: Decodable {+ public let name: String+ public let uuid: String+ public let teamIdentifiers: [DeveloperServicesTeam.ID]+ public let creationDate: Date+ public let expirationDate: Date+ public let devices: [String]+ public let certificates: [Certificate]+ public let entitlements: Entitlements++ private enum CodingKeys: String, CodingKey {+ case name = "Name"+ case uuid = "UUID"+ case teamIdentifiers = "TeamIdentifier"+ case creationDate = "CreationDate"+ case expirationDate = "ExpirationDate"+ case devices = "ProvisionedDevices"+ case certificates = "DeveloperCertificates"+ case entitlements = "Entitlements"+ }+ }++ let raw: mobileprovision_t++ private static func mobileprovision(from data: Data) -> mobileprovision_t? {+ data.withUnsafeBytes { bytes in+ let bound = bytes.bindMemory(to: Int8.self)+ return mobileprovision_create_from_data(bound.baseAddress, bound.count)+ }+ }++ public init(data: Data) throws {+ guard let profile = Self.mobileprovision(from: data) else {+ throw Error.invalidProfile+ }+ self.raw = profile+ }++ public init(contentsOf url: URL) throws {+ guard let profile = url.withUnsafeFileSystemRepresentation(mobileprovision_create_from_path) else {+ throw Error.invalidProfile+ }+ self.raw = profile+ }++ public required init(from decoder: Decoder) throws {+ let container = try decoder.singleValueContainer()+ let data = try container.decode(Data.self)+ guard let profile = Self.mobileprovision(from: data) else {+ throw Error.invalidProfile+ }+ self.raw = profile+ }++ deinit {+ mobileprovision_free(raw)+ }++ public func digest() throws -> Digest {+ var len = 0+ guard let ptr = mobileprovision_get_digest(raw, &len), len > 0 else {+ throw Error.invalidProfile+ }+ let data = Data(bytes: UnsafeRawPointer(ptr), count: len)+ return try PropertyListDecoder().decode(Digest.self, from: data)+ }++ public func data() throws -> Data {+ guard let data = Data(cFunc: { mobileprovision_get_data(raw, $0) })+ else { throw Error.invalidProfile }+ return data+ }++}diff --git a/Supersign/Model/Mobileprovision/mobileprovision.c b/Supersign/Model/Mobileprovision/mobileprovision.cnew file mode 100644index 0000000..ba26830--- /dev/null+++ b/Supersign/Model/Mobileprovision/mobileprovision.c@@ -0,0 +1,63 @@+//+// mobileprovision_utils.c+// supersign+//+// Created by Kabir Oberai on 05/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++#include <stdlib.h>+#include <string.h>+#include <openssl/pkcs7.h>+#include <openssl/x509.h>+#include <openssl/bio.h>+#include "mobileprovision.h"++struct mobileprovision {+ PKCS7 *raw;+};++static mobileprovision_t mobileprovision_create(PKCS7 *raw) {+ mobileprovision_t profile = malloc(sizeof(struct mobileprovision));+ profile->raw = raw;+ return profile;+}++mobileprovision_t mobileprovision_create_from_data(const char *data, size_t len) {+ PKCS7 *raw = NULL;+ d2i_PKCS7(&raw, (const unsigned char **)&data, len);+ if (!raw) return NULL;++ return mobileprovision_create(raw);+}++mobileprovision_t mobileprovision_create_from_path(const char *path) {+ BIO *file = BIO_new_file(path, "r");+ if (!file) return NULL;++ PKCS7 *raw = NULL;+ d2i_PKCS7_bio(file, &raw);++ BIO_free(file);++ return mobileprovision_create(raw);+}++void mobileprovision_free(mobileprovision_t profile) {+ PKCS7_free(profile->raw);+ free(profile);+}++char *mobileprovision_get_data(mobileprovision_t profile, size_t *len) {+ unsigned char *data = NULL;+ size_t data_len = i2d_PKCS7(profile->raw, &data);+ if (data_len < 0) return NULL;+ *len = data_len;+ return (char *)data;+}++const char *mobileprovision_get_digest(mobileprovision_t profile, size_t *len) {+ ASN1_OCTET_STRING *str = profile->raw->d.sign->contents->d.data;+ if (len) *len = str->length;+ return (char *)str->data;+}diff --git a/Supersign/Model/Mobileprovision/mobileprovision.h b/Supersign/Model/Mobileprovision/mobileprovision.hnew file mode 100644index 0000000..1da31a6--- /dev/null+++ b/Supersign/Model/Mobileprovision/mobileprovision.h@@ -0,0 +1,33 @@+//+// mobileprovision_utils.h+// supersign+//+// Created by Kabir Oberai on 05/07/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++#ifndef mobileprovision_h+#define mobileprovision_h++#include <stdio.h>++typedef struct mobileprovision *mobileprovision_t;++// MARK: - Lifecycle++/// create a profile from the given data+mobileprovision_t mobileprovision_create_from_data(const char *data, size_t len);++/// create a profile from the given file path+mobileprovision_t mobileprovision_create_from_path(const char *path);++/// free `profile`+void mobileprovision_free(mobileprovision_t profile);++// MARK: - Operations++char *mobileprovision_get_data(mobileprovision_t profile, size_t *len);++const char *mobileprovision_get_digest(mobileprovision_t profile, size_t *len);++#endif /* mobileprovision_h */diff --git a/Supersign/Signer/Signer.swift b/Supersign/Signer/Signer.swiftnew file mode 100644index 0000000..616a3ee--- /dev/null+++ b/Supersign/Signer/Signer.swift@@ -0,0 +1,103 @@+//+// Signer.swift+// Supersign+//+// Created by Kabir Oberai on 13/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++public struct Signer {++ public enum Error: LocalizedError {+ case noSigners+ case errorReading(String)+ case errorWriting(String)++ public var errorDescription: String? {+ switch self {+ case .noSigners:+ return NSLocalizedString("signer.error.no_signers", value: "No signers found", comment: "")+ case .errorReading(let file):+ return String.localizedStringWithFormat(+ NSLocalizedString(+ "signer.error.error_reading", value: "Error while reading %@", comment: ""+ ), "\(file)"+ )+ case .errorWriting(let file):+ return String.localizedStringWithFormat(+ NSLocalizedString(+ "signer.error.error_writing", value: "Error while writing %@", comment: ""+ ), "\(file)"+ )+ }+ }+ }++ public let context: SigningContext+ public let provisioner: Provisioner++ public init(context: SigningContext) {+ self.context = context+ self.provisioner = Provisioner(context: context)+ }++ private func sign(+ app: URL,+ signingInfo: SigningInfo,+ provisioningDict: [URL: ProvisioningInfo],+ progress: @escaping (Double) -> Void,+ completion: @escaping (Result<Void, Swift.Error>) -> Void+ ) {+ for (url, info) in provisioningDict {+ let infoPlist = url.appendingPathComponent("Info.plist")+ guard let dict = NSMutableDictionary(contentsOf: infoPlist) else {+ return completion(.failure(Error.errorReading("Info.plist")))+ }+ dict[kCFBundleIdentifierKey as String] = info.newBundleID+ guard dict.write(to: infoPlist, atomically: true) else {+ return completion(.failure(Error.errorWriting("Info.plist")))+ }++ do {+ let profURL = url.appendingPathComponent("embedded.mobileprovision")+ if profURL.exists {+ try FileManager.default.removeItem(at: profURL)+ }+ try info.mobileprovision.data().write(to: profURL)+ } catch {+ return completion(.failure(error))+ }+ }++ let entitlements = provisioningDict.mapValues { $0.entitlements }++ context.signerImpl.sign(+ app: app,+ certificate: signingInfo.certificate,+ privateKey: signingInfo.privateKey,+ entitlementMapping: entitlements,+ progress: progress,+ completion: completion+ )+ }++ public func sign(+ app: URL,+ progress: @escaping (Double) -> Void,+ completion: @escaping (Result<Void, Swift.Error>) -> Void+ ) {+ provisioner.provision(app: app) { r in+ guard let (signingInfo, provisioningDict) = r.get(withErrorHandler: completion) else { return }+ self.sign(+ app: app,+ signingInfo: signingInfo,+ provisioningDict: provisioningDict,+ progress: progress,+ completion: completion+ )+ }+ }++}diff --git a/Supersign/Signer/SigningContext.swift b/Supersign/Signer/SigningContext.swiftnew file mode 100644index 0000000..32e6f24--- /dev/null+++ b/Supersign/Signer/SigningContext.swift@@ -0,0 +1,49 @@+//+// SigningContext.swift+// Supersign+//+// Created by Kabir Oberai on 13/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++#if canImport(UIKit)+import UIKit+#endif++public struct SigningContext {++ public let udid: String+ public let team: DeveloperServicesTeam+ public let signerImpl: SignerImpl+ public let platform: DeveloperServicesPlatform+ public let client: DeveloperServicesClient++ public init(+ udid: String,+ team: DeveloperServicesTeam,+ signerImpl: SignerImpl? = nil,+ platform: DeveloperServicesPlatform = .iOS,+ client: DeveloperServicesClient = .shared+ ) throws {+ self.udid = udid+ self.team = team+ self.signerImpl = try signerImpl ?? .first()+ self.platform = platform+ self.client = client+ }++ public var deviceName: String {+ #if targetEnvironment(simulator)+ return "Simulator"+ #elseif canImport(UIKit)+ return UIDevice.current.name+ #elseif os(macOS)+ return Host.current.localizedName ?? "Mac"+ #else+ return "Supercharge Client"+ #endif+ }++}diff --git a/Supersign/SignerImpl/SignerImpl.swift b/Supersign/SignerImpl/SignerImpl.swiftnew file mode 100644index 0000000..6e71dc7--- /dev/null+++ b/Supersign/SignerImpl/SignerImpl.swift@@ -0,0 +1,146 @@+//+// SignerImpl.swift+// Supersign+//+// Created by Kabir Oberai on 10/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation+import LegibleError++extension signer_t: CLinkedListElement {}++/// a wrapper around signer_t+public struct SignerImpl {++ private static let signingQueue = DispatchQueue(+ label: "com.kabiroberai.Supercharge.signing-queue",+ attributes: .concurrent+ )++ public enum Error: LocalizedError {+ case notFound+ case signer(String)+ case unknown++ public var errorDescription: String? {+ switch self {+ case .notFound:+ return NSLocalizedString(+ "signer_impl.error.not_found", value: "No signer implementation found", comment: ""+ )+ case .signer(let error):+ return error+ case .unknown:+ return NSLocalizedString(+ "signer_impl.error.unknown", value: "An unknown signing error occurred", comment: ""+ )+ }+ }+ }++ public let name: String+ private let sign: sign_func+ private let analyze: analyze_func++ private init(signer: signer_t) {+ name = String(cString: signer.name)+ sign = signer.sign+ analyze = signer.analyze+ }++ public static func all() -> [SignerImpl] {+ CLinkedList(start: signer_list).map(SignerImpl.init)+ }++ public static func first() throws -> SignerImpl {+ guard let impl = all().first else { throw Error.notFound }+ return impl+ }++ private func _sign(+ app: URL,+ certificate: Certificate,+ privateKey: PrivateKey,+ entitlementMapping: [URL: Entitlements],+ progress: @escaping (Double) -> Void+ ) throws {+ let encoder = PropertyListEncoder()+ encoder.outputFormat = .xml+ let entsArray: [entitlements_data_t] = try entitlementMapping.map { url, ents in+ try url.withUnsafeFileSystemRepresentation { bundlePath in+ try encoder.encode(ents).withUnsafeBytes { bytes in+ let bound = bytes.bindMemory(to: Int8.self)+ return entitlements_data_t(+ bundle_path: bundlePath, data: bound.baseAddress, len: bound.count+ )+ }+ }+ }+ try entsArray.withUnsafeBufferPointer { ents in+ try certificate.data().withUnsafeBytes { certBytes in+ try privateKey.data.withUnsafeBytes { privBytes in+ let certBound = certBytes.bindMemory(to: Int8.self)+ let privBound = privBytes.bindMemory(to: Int8.self)++ var exception: UnsafeMutablePointer<Int8>?+ let ret = sign(+ app.path,+ certBound.baseAddress,+ certBound.count,+ privBound.baseAddress,+ privBound.count,+ ents.baseAddress,+ ents.count,+ progress,+ &exception+ )+ guard ret == 0 else {+ defer { free(exception) }+ throw exception+ .map { UnsafePointer($0) }+ .map(String.init(cString:))+ .map(Error.signer)+ ?? .unknown+ }+ if let exception = exception { free(exception) }+ }+ }+ }+ }++ public func sign(+ app: URL,+ certificate: Certificate,+ privateKey: PrivateKey,+ entitlementMapping: [URL: Entitlements],+ progress: @escaping (Double) -> Void,+ completion: @escaping (Result<Void, Swift.Error>) -> Void+ ) {+ Self.signingQueue.async {+ do {+ try self._sign(+ app: app,+ certificate: certificate,+ privateKey: privateKey,+ entitlementMapping: entitlementMapping,+ progress: progress+ )+ completion(.success(()))+ } catch {+ completion(.failure(error))+ }+ }+ }++ public func analyze(executable: URL) -> Data? {+ executable.withUnsafeFileSystemRepresentation({ (path: UnsafePointer<Int8>?) -> Data? in+ var len = 0+ guard let out = analyze(path, &len) else { return nil }+ defer { free(out) }+ return Data(bytes: UnsafeRawPointer(out), count: len)+ })+ }++}diff --git a/Supersign/Utilities/CHelpers.swift b/Supersign/Utilities/CHelpers.swiftnew file mode 100644index 0000000..ff34e1c--- /dev/null+++ b/Supersign/Utilities/CHelpers.swift@@ -0,0 +1,18 @@+//+// CHelpers.swift+// Supersign+//+// Created by Kabir Oberai on 13/10/19.+// Copyright © 2019 Kabir Oberai. All rights reserved.+//++import Foundation++extension Data {+ init?(cFunc: (UnsafeMutablePointer<Int>?) -> UnsafeMutablePointer<Int8>?) {+ var len = 0+ guard let bytes = cFunc(&len) else { return nil }+ defer { free(bytes) }+ self.init(bytes: UnsafeRawPointer(bytes), count: len)+ }+}