瀏覽代碼

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.
greatroar 3 年之前
父節點
當前提交
152388b3a3
共有 1 個文件被更改,包括 1 次插入12 次删除
  1. 1 12
      lib/tlsutil/tlsutil.go

+ 1 - 12
lib/tlsutil/tlsutil.go

@@ -115,7 +115,7 @@ func generateCertificate(commonName string, lifetimeDays int) (*pem.Block, *pem.
 		BasicConstraintsValid: true,
 		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 {
 	if err != nil {
 		return nil, nil, fmt.Errorf("create cert: %w", err)
 		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)
 	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) {
 func pemBlockForKey(priv interface{}) (*pem.Block, error) {
 	switch k := priv.(type) {
 	switch k := priv.(type) {
 	case *rsa.PrivateKey:
 	case *rsa.PrivateKey: