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.
This commit is contained in:
greatroar 2022-09-09 14:22:38 +02:00 committed by GitHub
parent 053425695a
commit 152388b3a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 12 deletions

View File

@ -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: