Improve error handling, fix linter (#92)
* Improve error handling, fix linter
This commit is contained in:
parent
6b2ac0b11c
commit
53a85837e0
23 changed files with 194 additions and 186 deletions
|
|
@ -2,8 +2,10 @@ package helper
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
goerrors "errors"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type ExplicitVerifyMessage struct {
|
||||
|
|
@ -24,14 +26,15 @@ func DecryptExplicitVerify(
|
|||
message, err := privateKeyRing.Decrypt(pgpMessage, publicKeyRing, verifyTime)
|
||||
|
||||
if err != nil {
|
||||
castedErr, isType := err.(crypto.SignatureVerificationError)
|
||||
castedErr := &crypto.SignatureVerificationError{}
|
||||
isType := goerrors.As(err, castedErr)
|
||||
if !isType {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "gopenpgp: unable to decrypt message")
|
||||
}
|
||||
|
||||
explicitVerify = &ExplicitVerifyMessage{
|
||||
Message: message,
|
||||
SignatureVerificationError: &castedErr,
|
||||
SignatureVerificationError: castedErr,
|
||||
}
|
||||
} else {
|
||||
explicitVerify = &ExplicitVerifyMessage{
|
||||
|
|
@ -51,7 +54,7 @@ func DecryptAttachment(keyPacket []byte, dataPacket []byte, keyRing *crypto.KeyR
|
|||
|
||||
decrypted, err := keyRing.DecryptAttachment(splitMessage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "gopenpgp: unable to decrypt attachment")
|
||||
}
|
||||
return decrypted, nil
|
||||
}
|
||||
|
|
@ -64,7 +67,7 @@ func EncryptAttachment(plainData []byte, filename string, keyRing *crypto.KeyRin
|
|||
plainMessage := crypto.NewPlainMessageFromFile(plainData, filename, uint32(crypto.GetUnixTime()))
|
||||
decrypted, err := keyRing.EncryptAttachment(plainMessage, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "gopenpgp: unable to encrypt attachment")
|
||||
}
|
||||
return decrypted, nil
|
||||
}
|
||||
|
|
@ -74,7 +77,7 @@ func EncryptAttachment(plainData []byte, filename string, keyRing *crypto.KeyRin
|
|||
func GetJsonSHA256Fingerprints(publicKey string) ([]byte, error) {
|
||||
key, err := crypto.NewKeyFromArmored(publicKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "gopenpgp: unable to parse key")
|
||||
}
|
||||
|
||||
return json.Marshal(key.GetSHA256Fingerprints())
|
||||
|
|
@ -94,5 +97,9 @@ func EncryptSignArmoredDetachedMobile(
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &EncryptSignArmoredDetachedMobileResult{ciphertext, encryptedSignature}, nil
|
||||
|
||||
return &EncryptSignArmoredDetachedMobileResult{
|
||||
Ciphertext: ciphertext,
|
||||
EncryptedSignature: encryptedSignature,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue