Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
appstore-distribution ▾

xtool.git / Sources / XKit / Utilities / ProvisioningIdentifiers.swift

ProvisioningIdentifiers.swift51 lines · 1.7 KiBRaw
1//
2// ProvisioningIdentifiers.swift
3// XKit
4//
5// Created by Kabir Oberai on 14/10/19.
6// Copyright © 2019 Kabir Oberai. All rights reserved.
7//
8
9import Foundation
10
11enum ProvisioningIdentifiers {}
12
13extension ProvisioningIdentifiers {
14
15 static let idPrefix = "XTL-"
16 static let groupPrefix = "group."
17 static let namePrefix = "XTool "
18
19 static func sanitize(identifier: String) -> String {
20 guard identifier.hasPrefix(Self.idPrefix) else { return identifier }
21 return identifier.split(separator: ".").dropFirst().joined(separator: ".")
22 }
23
24 static func identifier(fromSanitized sanitized: String, context: SigningContext) -> String {
25 let uuid = context.auth.identityID.split(separator: "-")[0].uppercased()
26 return "\(Self.idPrefix)\(uuid).\(sanitized)"
27 }
28
29 static func safeify(identifier: String) -> String {
30 identifier.replacingOccurrences(of: ".", with: " ")
31 }
32
33 static func sanitize(groupID: DeveloperServicesAppGroup.GroupID) -> String {
34 var id = groupID.rawValue
35 if id.hasPrefix(Self.groupPrefix) { id.removeFirst(Self.groupPrefix.count) }
36 return sanitize(identifier: id)
37 }
38
39 static func groupID(fromSanitized sanitized: String, context: SigningContext) -> DeveloperServicesAppGroup.GroupID {
40 .init(rawValue: "\(Self.groupPrefix)\(identifier(fromSanitized: sanitized, context: context))")
41 }
42
43 static func groupName(fromSanitized sanitized: String) -> String {
44 "\(Self.namePrefix)group \(safeify(identifier: sanitized))"
45 }
46
47 static func appName(fromSanitized sanitized: String) -> String {
48 "\(Self.namePrefix)\(safeify(identifier: sanitized))"
49 }
50
51}