Skip to content

Commit

Permalink
Merge pull request #336 from johanbrandhorst/patch-1
Browse files Browse the repository at this point in the history
Add Go 1.8 TLS config Clone method.
  • Loading branch information
kozlovic committed Dec 15, 2017
2 parents f0d9c59 + 4798ae8 commit 3de6ea0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 65 deletions.
38 changes: 8 additions & 30 deletions util/tls.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
// Copyright 2016 Apcera Inc. All rights reserved.
// +build go1.7
// Copyright 2017 Apcera Inc. All rights reserved.
// +build go1.8

package util

import (
"crypto/tls"
)
import "crypto/tls"

// CloneTLSConfig returns a copy of c. Only the exported fields are copied.
// This is temporary, until this is provided by the language.
// https://go-review.googlesource.com/#/c/28075/
// CloneTLSConfig returns a copy of c.
func CloneTLSConfig(c *tls.Config) *tls.Config {
return &tls.Config{
Rand: c.Rand,
Time: c.Time,
Certificates: c.Certificates,
NameToCertificate: c.NameToCertificate,
GetCertificate: c.GetCertificate,
RootCAs: c.RootCAs,
NextProtos: c.NextProtos,
ServerName: c.ServerName,
ClientAuth: c.ClientAuth,
ClientCAs: c.ClientCAs,
InsecureSkipVerify: c.InsecureSkipVerify,
CipherSuites: c.CipherSuites,
PreferServerCipherSuites: c.PreferServerCipherSuites,
SessionTicketsDisabled: c.SessionTicketsDisabled,
SessionTicketKey: c.SessionTicketKey,
ClientSessionCache: c.ClientSessionCache,
MinVersion: c.MinVersion,
MaxVersion: c.MaxVersion,
CurvePreferences: c.CurvePreferences,
DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled,
Renegotiation: c.Renegotiation,
if c == nil {
return &tls.Config{}
}

return c.Clone()
}
37 changes: 37 additions & 0 deletions util/tls_go17.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2016 Apcera Inc. All rights reserved.
// +build go1.7,!go1.8

package util

import (
"crypto/tls"
)

// CloneTLSConfig returns a copy of c. Only the exported fields are copied.
// This is temporary, until this is provided by the language.
// https://go-review.googlesource.com/#/c/28075/
func CloneTLSConfig(c *tls.Config) *tls.Config {
return &tls.Config{
Rand: c.Rand,
Time: c.Time,
Certificates: c.Certificates,
NameToCertificate: c.NameToCertificate,
GetCertificate: c.GetCertificate,
RootCAs: c.RootCAs,
NextProtos: c.NextProtos,
ServerName: c.ServerName,
ClientAuth: c.ClientAuth,
ClientCAs: c.ClientCAs,
InsecureSkipVerify: c.InsecureSkipVerify,
CipherSuites: c.CipherSuites,
PreferServerCipherSuites: c.PreferServerCipherSuites,
SessionTicketsDisabled: c.SessionTicketsDisabled,
SessionTicketKey: c.SessionTicketKey,
ClientSessionCache: c.ClientSessionCache,
MinVersion: c.MinVersion,
MaxVersion: c.MaxVersion,
CurvePreferences: c.CurvePreferences,
DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled,
Renegotiation: c.Renegotiation,
}
}
35 changes: 0 additions & 35 deletions util/tls_pre17.go

This file was deleted.

0 comments on commit 3de6ea0

Please sign in to comment.