TLSConfig+Internal.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2025, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. @available(gRPCSwiftNIOTransport 1.2, *)
  17. extension TLSConfig.PrivateKeySource {
  18. /// Marker protocol for transport specific private key sources.
  19. ///
  20. /// `TLSConfig.PrivateKeySource` is from the core module which means it can't take a NIOSSL
  21. /// or NIOTransportServices dependency. In order to support more sources this transport-specific
  22. /// protocol is provided as non-public API.
  23. package protocol TransportSpecific: Sendable {}
  24. package static func transportSpecific(_ source: any TransportSpecific) -> Self {
  25. Self(wrapped: .transportSpecific(source))
  26. }
  27. }
  28. @available(gRPCSwiftNIOTransport 1.2, *)
  29. extension TLSConfig.CertificateSource {
  30. /// A type-erased transport specific certificate source.
  31. ///
  32. /// `TLSConfig.CertificateSource` is from the core module which means it can't take a NIOSSL
  33. /// or NIOTransportServices dependency. In order to support more sources a transport-specific
  34. /// erased source is provided as non-public API.
  35. package struct TransportSpecific: Sendable, Equatable {
  36. package var wrapped: any Sendable
  37. private let isEqualTo: @Sendable (TransportSpecific) -> Bool
  38. package init<Value: Sendable & Equatable>(_ wrapped: Value) {
  39. self.wrapped = wrapped
  40. self.isEqualTo = { other in
  41. if let otherValue = other.wrapped as? Value {
  42. return otherValue == wrapped
  43. } else {
  44. return false
  45. }
  46. }
  47. }
  48. package static func == (lhs: Self, rhs: Self) -> Bool {
  49. lhs.isEqualTo(rhs)
  50. }
  51. }
  52. package static func transportSpecific(_ value: TransportSpecific) -> Self {
  53. return Self(wrapped: .transportSpecific(value))
  54. }
  55. }