Jelajahi Sumber

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
Alexey Gordeev 6 tahun lalu
induk
melakukan
0195dfd5b3

+ 2 - 6
Sources/RootsEncoder/main.swift

@@ -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)

+ 2 - 2
Sources/SwiftGRPC/Core/Channel.swift

@@ -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() }

File diff ditekan karena terlalu besar
+ 1 - 1
Sources/SwiftGRPC/Core/Roots.swift


Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini