| 1 |
/* |
| 2 |
Copyright 2019 The Kubernetes Authors. |
| 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 |
|
| 17 |
package dynamiccertificates |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
) |
| 22 |
|
| 23 |
// dynamicCertificateContent holds the content that overrides the baseTLSConfig |
| 24 |
type dynamicCertificateContent struct { |
| 25 |
// clientCA holds the content for the clientCA bundle |
| 26 |
clientCA caBundleContent |
| 27 |
servingCert certKeyContent |
| 28 |
sniCerts []sniCertKeyContent |
| 29 |
} |
| 30 |
|
| 31 |
// caBundleContent holds the content for the clientCA bundle. Wrapping the bytes makes the Equals work nicely with the |
| 32 |
// method receiver. |
| 33 |
type caBundleContent struct { |
| 34 |
caBundle []byte |
| 35 |
} |
| 36 |
|
| 37 |
func (c *dynamicCertificateContent) Equal(rhs *dynamicCertificateContent) bool { |
| 38 |
if c == nil || rhs == nil { |
| 39 |
return c == rhs |
| 40 |
} |
| 41 |
|
| 42 |
if !c.clientCA.Equal(&rhs.clientCA) { |
| 43 |
return false |
| 44 |
} |
| 45 |
|
| 46 |
if !c.servingCert.Equal(&rhs.servingCert) { |
| 47 |
return false |
| 48 |
} |
| 49 |
|
| 50 |
if len(c.sniCerts) != len(rhs.sniCerts) { |
| 51 |
return false |
| 52 |
} |
| 53 |
|
| 54 |
for i := range c.sniCerts { |
| 55 |
if !c.sniCerts[i].Equal(&rhs.sniCerts[i]) { |
| 56 |
return false |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
return true |
| 61 |
} |
| 62 |
|
| 63 |
func (c *caBundleContent) Equal(rhs *caBundleContent) bool { |
| 64 |
if c == nil || rhs == nil { |
| 65 |
return c == rhs |
| 66 |
} |
| 67 |
|
| 68 |
return bytes.Equal(c.caBundle, rhs.caBundle) |
| 69 |
} |