Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
main ▾

xtool.git / Sources / XKit / Signer / Signer.swift

Signer.swift50 lines · 1.3 KiBRaw
1import Foundation
2import Dependencies
3
4public enum SignerIdentity: Sendable {
5 case real(Certificate, PrivateKey)
6 case adhoc
7}
8
9public protocol Signer: Sendable {
10 // entitlementMapping is [bundle url] -> [plist data]
11 func sign(
12 app: URL,
13 identity: SignerIdentity,
14 entitlementMapping: [URL: Data],
15 deep: Bool,
16 progress: @escaping @Sendable (Double?) -> Void
17 ) async throws
18
19 func analyze(executable: URL) async throws -> Data?
20}
21
22private enum SignerDependencyKey: DependencyKey {
23 static var liveValue: any Signer { RCodesignSigner() }
24 static var testValue: any Signer { UnimplementedSigner() }
25}
26
27extension DependencyValues {
28 public var signer: any Signer {
29 get { self[SignerDependencyKey.self] }
30 set { self[SignerDependencyKey.self] = newValue }
31 }
32}
33
34private struct UnimplementedSigner: Signer {
35 func sign(
36 app: URL,
37 identity: SignerIdentity,
38 entitlementMapping: [URL: Data],
39 deep: Bool,
40 progress: @escaping @Sendable (Double?) -> Void
41 ) async throws {
42 let operation: () throws -> Void = unimplemented()
43 try operation()
44 }
45
46 func analyze(executable: URL) async throws -> Data? {
47 let operation: () throws -> Data? = unimplemented()
48 return try operation()
49 }
50}