credentials_util_pre_go17.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // +build !go1.7
  2. /*
  3. *
  4. * Copyright 2016, Google Inc.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following disclaimer
  15. * in the documentation and/or other materials provided with the
  16. * distribution.
  17. * * Neither the name of Google Inc. nor the names of its
  18. * contributors may be used to endorse or promote products derived from
  19. * this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. package credentials
  35. import (
  36. "crypto/tls"
  37. )
  38. // cloneTLSConfig returns a shallow clone of the exported
  39. // fields of cfg, ignoring the unexported sync.Once, which
  40. // contains a mutex and must not be copied.
  41. //
  42. // If cfg is nil, a new zero tls.Config is returned.
  43. //
  44. // TODO replace this function with official clone function.
  45. func cloneTLSConfig(cfg *tls.Config) *tls.Config {
  46. if cfg == nil {
  47. return &tls.Config{}
  48. }
  49. return &tls.Config{
  50. Rand: cfg.Rand,
  51. Time: cfg.Time,
  52. Certificates: cfg.Certificates,
  53. NameToCertificate: cfg.NameToCertificate,
  54. GetCertificate: cfg.GetCertificate,
  55. RootCAs: cfg.RootCAs,
  56. NextProtos: cfg.NextProtos,
  57. ServerName: cfg.ServerName,
  58. ClientAuth: cfg.ClientAuth,
  59. ClientCAs: cfg.ClientCAs,
  60. InsecureSkipVerify: cfg.InsecureSkipVerify,
  61. CipherSuites: cfg.CipherSuites,
  62. PreferServerCipherSuites: cfg.PreferServerCipherSuites,
  63. SessionTicketsDisabled: cfg.SessionTicketsDisabled,
  64. SessionTicketKey: cfg.SessionTicketKey,
  65. ClientSessionCache: cfg.ClientSessionCache,
  66. MinVersion: cfg.MinVersion,
  67. MaxVersion: cfg.MaxVersion,
  68. CurvePreferences: cfg.CurvePreferences,
  69. }
  70. }