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