Skip to content

Commit 5e37590

Browse files
committed
code optimization
1 parent c21e85d commit 5e37590

7 files changed

Lines changed: 16 additions & 36 deletions

File tree

bundler/bundler.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,7 @@ func isSelfSigned(cert *x509.Certificate) bool {
398398
}
399399

400400
func isChainRootNode(cert *x509.Certificate) bool {
401-
if isSelfSigned(cert) {
402-
return true
403-
}
404-
return false
401+
return isSelfSigned(cert)
405402
}
406403

407404
func (b *Bundler) verifyChain(chain []*fetchedIntermediate) bool {

config/config.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/cloudflare/cfssl/helpers"
2020
"github.com/cloudflare/cfssl/log"
2121
ocspConfig "github.com/cloudflare/cfssl/ocsp/config"
22+
2223
// empty import of zlint/v3 required to have lints registered.
2324
_ "github.com/zmap/zlint/v3"
2425
"github.com/zmap/zlint/v3/lint"
@@ -296,7 +297,7 @@ func (p *SigningProfile) populate(cfg *Config) error {
296297

297298
if p.AuthRemote.AuthKeyName != "" {
298299
log.Debug("match auth remote key in profile to auth_keys section")
299-
if key, ok := cfg.AuthKeys[p.AuthRemote.AuthKeyName]; ok == true {
300+
if key, ok := cfg.AuthKeys[p.AuthRemote.AuthKeyName]; ok {
300301
if key.Type == "standard" {
301302
p.RemoteProvider, err = auth.New(key.Key, nil)
302303
if err != nil {
@@ -441,11 +442,7 @@ func (p *Signing) NeedsRemoteSigner() bool {
441442
}
442443
}
443444

444-
if p.Default.RemoteServer != "" {
445-
return true
446-
}
447-
448-
return false
445+
return p.Default.RemoteServer != ""
449446
}
450447

451448
// NeedsLocalSigner returns true if one of the profiles doe not have a remote set
@@ -456,11 +453,7 @@ func (p *Signing) NeedsLocalSigner() bool {
456453
}
457454
}
458455

459-
if p.Default.RemoteServer == "" {
460-
return true
461-
}
462-
463-
return false
456+
return p.Default.RemoteServer == ""
464457
}
465458

466459
// Usages parses the list of key uses in the profile, translating them
@@ -559,7 +552,7 @@ func (p *SigningProfile) hasLocalConfig() bool {
559552
p.OCSP != "" ||
560553
p.ExpiryString != "" ||
561554
p.BackdateString != "" ||
562-
p.CAConstraint.IsCA != false ||
555+
p.CAConstraint.IsCA ||
563556
!p.NotBefore.IsZero() ||
564557
!p.NotAfter.IsZero() ||
565558
p.NameWhitelistString != "" ||

csr/csr.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,11 @@ func getHosts(cert *x509.Certificate) []string {
289289
for _, ip := range cert.IPAddresses {
290290
hosts = append(hosts, ip.String())
291291
}
292-
for _, dns := range cert.DNSNames {
293-
hosts = append(hosts, dns)
294-
}
295-
for _, email := range cert.EmailAddresses {
296-
hosts = append(hosts, email)
297-
}
292+
hosts = append(hosts, cert.DNSNames...)
293+
hosts = append(hosts, cert.EmailAddresses...)
298294
for _, uri := range cert.URIs {
299295
hosts = append(hosts, uri.String())
300296
}
301-
302297
return hosts
303298
}
304299

@@ -482,8 +477,6 @@ func appendCAInfoToCSR(reqConf *CAConfig, csr *x509.CertificateRequest) error {
482477

483478
// appendCAInfoToCSR appends user-defined extension to a CSR
484479
func appendExtensionsToCSR(extensions []pkix.Extension, csr *x509.CertificateRequest) error {
485-
for _, extension := range extensions {
486-
csr.ExtraExtensions = append(csr.ExtraExtensions, extension)
487-
}
480+
csr.ExtraExtensions = append(csr.ExtraExtensions, extensions...)
488481
return nil
489482
}

helpers/derhelpers/derhelpers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ func ParsePrivateKeyDER(keyDER []byte) (key crypto.Signer, err error) {
3434
}
3535
}
3636

37-
switch generalKey.(type) {
37+
switch generalKey := generalKey.(type) {
3838
case *rsa.PrivateKey:
39-
return generalKey.(*rsa.PrivateKey), nil
39+
return generalKey, nil
4040
case *ecdsa.PrivateKey:
41-
return generalKey.(*ecdsa.PrivateKey), nil
41+
return generalKey, nil
4242
case ed25519.PrivateKey:
43-
return generalKey.(ed25519.PrivateKey), nil
43+
return generalKey, nil
4444
}
4545

4646
// should never reach here

helpers/helpers.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@ func ValidExpiry(c *x509.Certificate) bool {
120120
maxMonths = 120
121121
}
122122

123-
if MonthsValid(c) > maxMonths {
124-
return false
125-
}
126-
return true
123+
return MonthsValid(c) <= maxMonths
127124
}
128125

129126
// SignatureString returns the TLS signature string corresponding to

helpers/testsuite/testing_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func cleanCLIOutput(CLIOutput []byte, item string) (cleanedOutput []byte, err er
352352
eligibleSearchIndex := strings.Index(outputString, "{")
353353
outputString = outputString[eligibleSearchIndex:]
354354
// Make sure the item is present in the output.
355-
if strings.Index(outputString, itemString) == -1 {
355+
if !strings.Contains(outputString, itemString) {
356356
return nil, errors.New("Item " + item + " not found in CLI Output")
357357
}
358358
// We add 2 for the [:"] that follows the item

initca/initca.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func NewFromSigner(req *csr.CertificateRequest, priv crypto.Signer) (cert, csrPE
157157
}
158158

159159
policy.Default.CAConstraint.MaxPathLen = req.CA.PathLength
160-
if req.CA.PathLength != 0 && req.CA.PathLenZero == true {
160+
if req.CA.PathLength != 0 && req.CA.PathLenZero {
161161
log.Infof("ignore invalid 'pathlenzero' value")
162162
} else {
163163
policy.Default.CAConstraint.MaxPathLenZero = req.CA.PathLenZero

0 commit comments

Comments
 (0)