Skip to content

Commit

Permalink
Remove dependency on cmp package
Browse files Browse the repository at this point in the history
  • Loading branch information
ellgreen committed Sep 20, 2024
1 parent 22dbdc6 commit 129213a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions testcerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ Simplify your testing, and don't hassle with certificates anymore.
package testcerts

import (
"cmp"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
Expand Down Expand Up @@ -159,6 +158,12 @@ func (ca *CertificateAuthority) NewKeyPairFromConfig(config KeyPairConfig) (*Key
return nil, err
}

// If a serial number is provided, use it, otherwise use 42
serialNumber := config.SerialNumber
if serialNumber == nil {
serialNumber = big.NewInt(42)
}

// Create a Certificate
kp := &KeyPair{cert: &x509.Certificate{
Subject: pkix.Name{
Expand All @@ -167,7 +172,7 @@ func (ca *CertificateAuthority) NewKeyPairFromConfig(config KeyPairConfig) (*Key
},
DNSNames: config.Domains,
IPAddresses: ips,
SerialNumber: cmp.Or(config.SerialNumber, big.NewInt(42)),
SerialNumber: serialNumber,
NotBefore: time.Now().Add(-1 * time.Hour),
NotAfter: time.Now().Add(2 * time.Hour),
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
Expand Down

0 comments on commit 129213a

Please sign in to comment.