Skip to content

Commit 0195dfd

Browse files
VladlexMrMage
authored andcommitted
Proposal to fix #362. (#363)
* Proposal to fix #362. Allows user to setup a channel with a client certificate and key but still use default root certificates. * fix #362. Respect PR critique. make roots_pem() public. Update Channel init. * fix #362: make roots_pem() return force-unwrapped String. Change Channel API accordingly. * Remove an obsolete comment. * Minor whitespace tweak #1 * Minor whitespace tweak #2
1 parent 3cd505a commit 0195dfd

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

Sources/RootsEncoder/main.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,13 @@ if CommandLine.arguments.contains("test") {
9898
s += "import Foundation\n"
9999
s += "\n"
100100

101-
s += "func roots_pem() -> String? {\n"
101+
s += "public func roots_pem() -> String {\n"
102102
let fileURL = URL(fileURLWithPath: "Assets/roots.pem")
103103
let filedata = try Data(contentsOf: fileURL)
104104
let encoding = filedata.base64EncodedString()
105105
s += " let roots = \n"
106106
s += " \"" + encoding + "\"\n"
107-
s += " if let data = Data(base64Encoded: roots, options:[]) {\n"
108-
s += " return String(data:data, encoding:.utf8)\n"
109-
s += " } else {\n"
110-
s += " return nil\n"
111-
s += " }\n"
107+
s += " return String(data: Data(base64Encoded: roots, options: [])!, encoding: .utf8)!\n"
112108
s += "}\n"
113109
}
114110
print(s)

Sources/SwiftGRPC/Core/Channel.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ public class Channel {
7979
/// Initializes a gRPC channel
8080
///
8181
/// - Parameter address: the address of the server to be called
82-
/// - Parameter certificates: a PEM representation of certificates to use
82+
/// - Parameter certificates: a PEM representation of certificates to use.
8383
/// - Parameter clientCertificates: a PEM representation of the client certificates to use
8484
/// - Parameter clientKey: a PEM representation of the client key to use
8585
/// - Parameter arguments: list of channel configuration options
86-
public init(address: String, certificates: String, clientCertificates: String? = nil, clientKey: String? = nil, arguments: [Argument] = []) {
86+
public init(address: String, certificates: String = roots_pem(), clientCertificates: String? = nil, clientKey: String? = nil, arguments: [Argument] = []) {
8787
gRPC.initialize()
8888
host = address
8989
let argumentWrappers = arguments.map { $0.toCArg() }

Sources/SwiftGRPC/Core/Roots.swift

+2-6
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)