Skip to content

Commit 29ea986

Browse files
committed
Improve signature method code
1 parent 3e488a0 commit 29ea986

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

Sources/WalletOrders/OrderBuilder.swift

+16-10
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,34 @@ public struct OrderBuilder: Sendable {
7878
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
7979
defer { try? FileManager.default.removeItem(at: dir) }
8080

81-
try manifest.write(to: dir.appendingPathComponent(Self.manifestFileName))
82-
try self.pemWWDRCertificate.write(to: dir.appendingPathComponent("wwdr.pem"), atomically: true, encoding: .utf8)
83-
try self.pemCertificate.write(to: dir.appendingPathComponent("certificate.pem"), atomically: true, encoding: .utf8)
84-
try self.pemPrivateKey.write(to: dir.appendingPathComponent("private.pem"), atomically: true, encoding: .utf8)
81+
let manifestURL = dir.appendingPathComponent(Self.manifestFileName)
82+
let wwdrURL = dir.appendingPathComponent("wwdr.pem")
83+
let certificateURL = dir.appendingPathComponent("certificate.pem")
84+
let privateKeyURL = dir.appendingPathComponent("private.pem")
85+
let signatureURL = dir.appendingPathComponent(Self.signatureFileName)
86+
87+
try manifest.write(to: manifestURL)
88+
try self.pemWWDRCertificate.write(to: wwdrURL, atomically: true, encoding: .utf8)
89+
try self.pemCertificate.write(to: certificateURL, atomically: true, encoding: .utf8)
90+
try self.pemPrivateKey.write(to: privateKeyURL, atomically: true, encoding: .utf8)
8591

8692
let process = Process()
8793
process.currentDirectoryURL = dir
8894
process.executableURL = self.openSSLURL
8995
process.arguments = [
9096
"smime", "-binary", "-sign",
91-
"-certfile", dir.appendingPathComponent("wwdr.pem").path,
92-
"-signer", dir.appendingPathComponent("certificate.pem").path,
93-
"-inkey", dir.appendingPathComponent("private.pem").path,
94-
"-in", dir.appendingPathComponent(Self.manifestFileName).path,
95-
"-out", dir.appendingPathComponent(Self.signatureFileName).path,
97+
"-certfile", wwdrURL.path,
98+
"-signer", certificateURL.path,
99+
"-inkey", privateKeyURL.path,
100+
"-in", manifestURL.path,
101+
"-out", signatureURL.path,
96102
"-outform", "DER",
97103
"-passin", "pass:\(pemPrivateKeyPassword)",
98104
]
99105
try process.run()
100106
process.waitUntilExit()
101107

102-
return try Data(contentsOf: dir.appendingPathComponent(Self.signatureFileName))
108+
return try Data(contentsOf: signatureURL)
103109
} else {
104110
let signature = try CMS.sign(
105111
manifest,

Sources/WalletPasses/PassBuilder.swift

+16-10
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,34 @@ public struct PassBuilder: Sendable {
103103
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
104104
defer { try? FileManager.default.removeItem(at: dir) }
105105

106-
try manifest.write(to: dir.appendingPathComponent(Self.manifestFileName))
107-
try self.pemWWDRCertificate.write(to: dir.appendingPathComponent("wwdr.pem"), atomically: true, encoding: .utf8)
108-
try self.pemCertificate.write(to: dir.appendingPathComponent("certificate.pem"), atomically: true, encoding: .utf8)
109-
try self.pemPrivateKey.write(to: dir.appendingPathComponent("private.pem"), atomically: true, encoding: .utf8)
106+
let manifestURL = dir.appendingPathComponent(Self.manifestFileName)
107+
let wwdrURL = dir.appendingPathComponent("wwdr.pem")
108+
let certificateURL = dir.appendingPathComponent("certificate.pem")
109+
let privateKeyURL = dir.appendingPathComponent("private.pem")
110+
let signatureURL = dir.appendingPathComponent(Self.signatureFileName)
111+
112+
try manifest.write(to: manifestURL)
113+
try self.pemWWDRCertificate.write(to: wwdrURL, atomically: true, encoding: .utf8)
114+
try self.pemCertificate.write(to: certificateURL, atomically: true, encoding: .utf8)
115+
try self.pemPrivateKey.write(to: privateKeyURL, atomically: true, encoding: .utf8)
110116

111117
let process = Process()
112118
process.currentDirectoryURL = dir
113119
process.executableURL = self.openSSLURL
114120
process.arguments = [
115121
"smime", "-binary", "-sign",
116-
"-certfile", dir.appendingPathComponent("wwdr.pem").path,
117-
"-signer", dir.appendingPathComponent("certificate.pem").path,
118-
"-inkey", dir.appendingPathComponent("private.pem").path,
119-
"-in", dir.appendingPathComponent(Self.manifestFileName).path,
120-
"-out", dir.appendingPathComponent(Self.signatureFileName).path,
122+
"-certfile", wwdrURL.path,
123+
"-signer", certificateURL.path,
124+
"-inkey", privateKeyURL.path,
125+
"-in", manifestURL.path,
126+
"-out", signatureURL.path,
121127
"-outform", "DER",
122128
"-passin", "pass:\(pemPrivateKeyPassword)",
123129
]
124130
try process.run()
125131
process.waitUntilExit()
126132

127-
return try Data(contentsOf: dir.appendingPathComponent(Self.signatureFileName))
133+
return try Data(contentsOf: signatureURL)
128134
} else {
129135
let signature = try CMS.sign(
130136
manifest,

0 commit comments

Comments
 (0)