Deprecate Key#Check()

This commit is contained in:
Aron Wussler 2020-11-04 16:42:28 +01:00
parent dc08a383a1
commit b50a051c7e
4 changed files with 18 additions and 72 deletions

View file

@ -306,37 +306,8 @@ func (key *Key) IsUnlocked() (bool, error) {
// Check verifies if the public keys match the private key parameters by
// signing and verifying.
// Deprecated: all keys are now checked on parsing.
func (key *Key) Check() (bool, error) {
var err error
testSign := bytes.Repeat([]byte{0x01}, 64)
testReader := bytes.NewReader(testSign)
if !key.IsPrivate() {
return false, errors.New("gopenpgp: can check only private key")
}
unlocked, err := key.IsUnlocked()
if err != nil {
return false, err
}
if !unlocked {
return false, errors.New("gopenpgp: key is not unlocked")
}
var signBuf bytes.Buffer
if err = openpgp.DetachSign(&signBuf, key.entity, testReader, nil); err != nil {
return false, errors.New("gopenpgp: unable to sign with key")
}
testReader = bytes.NewReader(testSign)
signer, err := openpgp.CheckDetachedSignature(openpgp.EntityList{key.entity}, testReader, &signBuf, nil)
if signer == nil || err != nil {
return false, nil
}
return true, nil
}