Files
xtool-mirror/Sources/Supersign/Utilities/ProvisioningIdentifiers.swift
2024-11-17 03:09:06 -05:00

54 lines
1.9 KiB
Swift

//
// ProvisioningIdentifiers.swift
// Supersign
//
// Created by Kabir Oberai on 14/10/19.
// Copyright © 2019 Kabir Oberai. All rights reserved.
//
import Foundation
enum ProvisioningIdentifiers {}
extension ProvisioningIdentifiers {
static let idPrefix = "SC-"
static let groupPrefix = "group."
static let namePrefix = "Supercharge "
static func sanitize(identifier: String) -> String {
guard identifier.hasPrefix(Self.idPrefix) else { return identifier }
return identifier.split(separator: ".").dropFirst().joined(separator: ".")
}
static func identifier(fromSanitized sanitized: String, context: SigningContext? = nil) -> String {
// FIXME: Use something better than the team ID to generate the prefix. Maybe a random
// UUID works as long as we can remember what the random UUID for each app was.
let uuid = context?.teamID.rawValue ?? String(UUID().uuidString.split(separator: "-")[0])
return "\(Self.idPrefix)\(uuid).\(sanitized)"
}
static func safeify(identifier: String) -> String {
identifier.replacingOccurrences(of: ".", with: " ")
}
static func sanitize(groupID: DeveloperServicesAppGroup.GroupID) -> String {
var id = groupID.rawValue
if id.hasPrefix(Self.groupPrefix) { id.removeFirst(Self.groupPrefix.count) }
return sanitize(identifier: id)
}
static func groupID(fromSanitized sanitized: String, context: SigningContext? = nil) -> DeveloperServicesAppGroup.GroupID {
.init(rawValue: "\(Self.groupPrefix)\(identifier(fromSanitized: sanitized, context: context))")
}
static func groupName(fromSanitized sanitized: String) -> String {
"\(Self.namePrefix)group \(safeify(identifier: sanitized))"
}
static func appName(fromSanitized sanitized: String) -> String {
"\(Self.namePrefix)\(safeify(identifier: sanitized))"
}
}