openpgp: allow RSA/ECDSA signers to return a pointer

Fixes golang/go#27606

Change-Id: I88b2f7c7796b43449a17a6be963c05f741dbf904
Reviewed-on: https://go-review.googlesource.com/137895
Reviewed-by: Filippo Valsorda <filippo@golang.org>
This commit is contained in:
Axel Wagner 2018-09-27 00:24:25 +02:00 коммит произвёл Filippo Valsorda
Родитель f7f546618e
Коммит e3636079e1
2 изменённых файлов: 9 добавлений и 19 удалений

Просмотреть файл

@ -68,10 +68,17 @@ func NewECDSAPrivateKey(currentTime time.Time, priv *ecdsa.PrivateKey) *PrivateK
// implements RSA or ECDSA.
func NewSignerPrivateKey(currentTime time.Time, signer crypto.Signer) *PrivateKey {
pk := new(PrivateKey)
// In general, the public Keys should be used as pointers. We still
// type-switch on the values, for backwards-compatibility.
switch pubkey := signer.Public().(type) {
case *rsa.PublicKey:
pk.PublicKey = *NewRSAPublicKey(currentTime, pubkey)
pk.PubKeyAlgo = PubKeyAlgoRSASignOnly
case rsa.PublicKey:
pk.PublicKey = *NewRSAPublicKey(currentTime, &pubkey)
pk.PubKeyAlgo = PubKeyAlgoRSASignOnly
case *ecdsa.PublicKey:
pk.PublicKey = *NewECDSAPublicKey(currentTime, pubkey)
case ecdsa.PublicKey:
pk.PublicKey = *NewECDSAPublicKey(currentTime, &pubkey)
default:

Просмотреть файл

@ -14,7 +14,6 @@ import (
"crypto/x509"
"encoding/hex"
"hash"
"io"
"testing"
"time"
)
@ -162,15 +161,7 @@ func TestECDSAPrivateKey(t *testing.T) {
}
type rsaSigner struct {
priv *rsa.PrivateKey
}
func (s *rsaSigner) Public() crypto.PublicKey {
return s.priv.PublicKey
}
func (s *rsaSigner) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error) {
return s.priv.Sign(rand, msg, opts)
*rsa.PrivateKey
}
func TestRSASignerPrivateKey(t *testing.T) {
@ -208,15 +199,7 @@ func TestRSASignerPrivateKey(t *testing.T) {
}
type ecdsaSigner struct {
priv *ecdsa.PrivateKey
}
func (s *ecdsaSigner) Public() crypto.PublicKey {
return s.priv.PublicKey
}
func (s *ecdsaSigner) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error) {
return s.priv.Sign(rand, msg, opts)
*ecdsa.PrivateKey
}
func TestECDSASignerPrivateKey(t *testing.T) {