diff options
author | greatroar <61184462+greatroar@users.noreply.github.com> | 2022-09-09 14:22:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-09 14:22:38 +0200 |
commit | 152388b3a3bd177be86acb44fc1ef1a26b993073 (patch) | |
tree | 0486381aab25dff1c957026be10784d19d7718b9 | |
parent | 053425695a5d84ed72056c88222b1d891f61badf (diff) |
lib/tlsutil: Use crypto.Signer interface (#8526)
*rsa.PrivateKey and *ecdsa.PrivateKey are both Signers, which have a
method to get the public key. No need for the type switch.
-rw-r--r-- | lib/tlsutil/tlsutil.go | 13 |
1 files changed, 1 insertions, 12 deletions
diff --git a/lib/tlsutil/tlsutil.go b/lib/tlsutil/tlsutil.go index f2d3a3b8d7..e184d16dd9 100644 --- a/lib/tlsutil/tlsutil.go +++ b/lib/tlsutil/tlsutil.go @@ -115,7 +115,7 @@ func generateCertificate(commonName string, lifetimeDays int) (*pem.Block, *pem. BasicConstraintsValid: true, } - derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, publicKey(priv), priv) + derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, priv.Public(), priv) if err != nil { return nil, nil, fmt.Errorf("create cert: %w", err) } @@ -235,17 +235,6 @@ func (c *UnionedConnection) Read(b []byte) (n int, err error) { return c.Conn.Read(b) } -func publicKey(priv interface{}) interface{} { - switch k := priv.(type) { - case *rsa.PrivateKey: - return &k.PublicKey - case *ecdsa.PrivateKey: - return &k.PublicKey - default: - return nil - } -} - func pemBlockForKey(priv interface{}) (*pem.Block, error) { switch k := priv.(type) { case *rsa.PrivateKey: |