credentials_util_go17.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // +build go1.7
  2. // +build !go1.8
  3. /*
  4. *
  5. * Copyright 2016 gRPC authors.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. */
  20. package credentials
  21. import (
  22. "crypto/tls"
  23. )
  24. // cloneTLSConfig returns a shallow clone of the exported
  25. // fields of cfg, ignoring the unexported sync.Once, which
  26. // contains a mutex and must not be copied.
  27. //
  28. // If cfg is nil, a new zero tls.Config is returned.
  29. func cloneTLSConfig(cfg *tls.Config) *tls.Config {
  30. if cfg == nil {
  31. return &tls.Config{}
  32. }
  33. return &tls.Config{
  34. Rand: cfg.Rand,
  35. Time: cfg.Time,
  36. Certificates: cfg.Certificates,
  37. NameToCertificate: cfg.NameToCertificate,
  38. GetCertificate: cfg.GetCertificate,
  39. RootCAs: cfg.RootCAs,
  40. NextProtos: cfg.NextProtos,
  41. ServerName: cfg.ServerName,
  42. ClientAuth: cfg.ClientAuth,
  43. ClientCAs: cfg.ClientCAs,
  44. InsecureSkipVerify: cfg.InsecureSkipVerify,
  45. CipherSuites: cfg.CipherSuites,
  46. PreferServerCipherSuites: cfg.PreferServerCipherSuites,
  47. SessionTicketsDisabled: cfg.SessionTicketsDisabled,
  48. SessionTicketKey: cfg.SessionTicketKey,
  49. ClientSessionCache: cfg.ClientSessionCache,
  50. MinVersion: cfg.MinVersion,
  51. MaxVersion: cfg.MaxVersion,
  52. CurvePreferences: cfg.CurvePreferences,
  53. DynamicRecordSizingDisabled: cfg.DynamicRecordSizingDisabled,
  54. Renegotiation: cfg.Renegotiation,
  55. }
  56. }