@@ -22,16 +22,44 @@ public protocol PackageCollectionSigner {
22
22
/// - collection: The package collection to be signed
23
23
/// - certChainPaths: Paths to all DER-encoded certificates in the chain. The certificate used for signing
24
24
/// must be the first in the array.
25
- /// - certPrivateKeyPath: Path to the private key (*.pem) of the certificate
25
+ /// - privateKeyPEM: Data of the private key (*.pem) of the certificate
26
26
/// - certPolicyKey: The key of the `CertificatePolicy` to use for validating certificates
27
27
/// - callback: The callback to invoke when the signed collection is available.
28
28
func sign( collection: PackageCollectionModel . V1 . Collection ,
29
29
certChainPaths: [ URL ] ,
30
- certPrivateKeyPath : URL ,
30
+ privateKeyPEM : Data ,
31
31
certPolicyKey: CertificatePolicyKey ,
32
32
callback: @escaping ( Result < PackageCollectionModel . V1 . SignedCollection , Error > ) -> Void )
33
33
}
34
34
35
+ extension PackageCollectionSigner {
36
+ /// Signs package collection using the given certificate and key.
37
+ ///
38
+ /// - Parameters:
39
+ /// - collection: The package collection to be signed
40
+ /// - certChainPaths: Paths to all DER-encoded certificates in the chain. The certificate used for signing
41
+ /// must be the first in the array.
42
+ /// - certPrivateKeyPath: Path to the private key (*.pem) of the certificate
43
+ /// - certPolicyKey: The key of the `CertificatePolicy` to use for validating certificates
44
+ /// - callback: The callback to invoke when the signed collection is available.
45
+ public func sign( collection: PackageCollectionModel . V1 . Collection ,
46
+ certChainPaths: [ URL ] ,
47
+ certPrivateKeyPath: URL ,
48
+ certPolicyKey: CertificatePolicyKey = . default,
49
+ callback: @escaping ( Result < PackageCollectionModel . V1 . SignedCollection , Error > ) -> Void ) {
50
+ do {
51
+ let privateKey = try Data ( contentsOf: certPrivateKeyPath)
52
+ self . sign ( collection: collection,
53
+ certChainPaths: certChainPaths,
54
+ privateKeyPEM: privateKey,
55
+ certPolicyKey: certPolicyKey,
56
+ callback: callback)
57
+ } catch {
58
+ callback ( . failure( error) )
59
+ }
60
+ }
61
+ }
62
+
35
63
public protocol PackageCollectionSignatureValidator {
36
64
/// Validates a signed package collection.
37
65
///
@@ -126,7 +154,7 @@ public struct PackageCollectionSigning: PackageCollectionSigner, PackageCollecti
126
154
127
155
public func sign( collection: Model . Collection ,
128
156
certChainPaths: [ URL ] ,
129
- certPrivateKeyPath : URL ,
157
+ privateKeyPEM : Data ,
130
158
certPolicyKey: CertificatePolicyKey = . default,
131
159
callback: @escaping ( Result < Model . SignedCollection , Error > ) -> Void ) {
132
160
do {
@@ -148,9 +176,6 @@ public struct PackageCollectionSigning: PackageCollectionSigner, PackageCollecti
148
176
certChain: certChainData. map { $0. base64EncodedString ( ) }
149
177
)
150
178
151
- // Key for signing
152
- let privateKeyPEM = try Data ( contentsOf: certPrivateKeyPath)
153
-
154
179
let privateKey : PrivateKey
155
180
switch keyType {
156
181
case . RSA:
0 commit comments