Skip to content

Commit

Permalink
Proposal to fix #362. (#363)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Vladlex authored and MrMage committed Feb 19, 2019
1 parent 3cd505a commit 0195dfd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
8 changes: 2 additions & 6 deletions Sources/RootsEncoder/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,13 @@ if CommandLine.arguments.contains("test") {
s += "import Foundation\n"
s += "\n"

s += "func roots_pem() -> String? {\n"
s += "public func roots_pem() -> String {\n"
let fileURL = URL(fileURLWithPath: "Assets/roots.pem")
let filedata = try Data(contentsOf: fileURL)
let encoding = filedata.base64EncodedString()
s += " let roots = \n"
s += " \"" + encoding + "\"\n"
s += " if let data = Data(base64Encoded: roots, options:[]) {\n"
s += " return String(data:data, encoding:.utf8)\n"
s += " } else {\n"
s += " return nil\n"
s += " }\n"
s += " return String(data: Data(base64Encoded: roots, options: [])!, encoding: .utf8)!\n"
s += "}\n"
}
print(s)
4 changes: 2 additions & 2 deletions Sources/SwiftGRPC/Core/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public class Channel {
/// Initializes a gRPC channel
///
/// - Parameter address: the address of the server to be called
/// - Parameter certificates: a PEM representation of certificates to use
/// - Parameter certificates: a PEM representation of certificates to use.
/// - Parameter clientCertificates: a PEM representation of the client certificates to use
/// - Parameter clientKey: a PEM representation of the client key to use
/// - Parameter arguments: list of channel configuration options
public init(address: String, certificates: String, clientCertificates: String? = nil, clientKey: String? = nil, arguments: [Argument] = []) {
public init(address: String, certificates: String = roots_pem(), clientCertificates: String? = nil, clientKey: String? = nil, arguments: [Argument] = []) {
gRPC.initialize()
host = address
let argumentWrappers = arguments.map { $0.toCArg() }
Expand Down
8 changes: 2 additions & 6 deletions Sources/SwiftGRPC/Core/Roots.swift

Large diffs are not rendered by default.

0 comments on commit 0195dfd

Please sign in to comment.