* Change keyring unlock functionalities * Add keyring#Lock, keyring#CheckIntegrity, tests * Update helpers, fix bugs * Update go.mod with ProtonMail/crypto commit * Change key management system * Clear keys from memory + tests * Create SessionKey with direct encryption for datapackets. Move symmetrickey to password. * Fix upstream dependencies * Update module to V2, documentation * Add linter * Add v2 folder to .gitignore * Minor changes to KeyID getters * Remove old changelog * Improve docs, remove compilation script
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package helper
|
|
|
|
import (
|
|
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
|
)
|
|
|
|
// ExplicitVerifyMessage contains explicitly the signature verification error, for gomobile users
|
|
type ExplicitVerifyMessage struct {
|
|
Message *crypto.PlainMessage
|
|
SignatureVerificationError *crypto.SignatureVerificationError
|
|
}
|
|
|
|
// DecryptExplicitVerify decrypts an armored PGP message given a private key and its passphrase
|
|
// and verifies the embedded signature.
|
|
// Returns the plain data or an error on signature verification failure.
|
|
func DecryptExplicitVerify(
|
|
pgpMessage *crypto.PGPMessage,
|
|
privateKeyRing, publicKeyRing *crypto.KeyRing,
|
|
verifyTime int64,
|
|
) (*ExplicitVerifyMessage, error) {
|
|
var explicitVerify *ExplicitVerifyMessage
|
|
|
|
message, err := privateKeyRing.Decrypt(pgpMessage, publicKeyRing, verifyTime)
|
|
|
|
if err != nil {
|
|
castedErr, isType := err.(crypto.SignatureVerificationError)
|
|
if !isType {
|
|
return nil, err
|
|
}
|
|
|
|
explicitVerify = &ExplicitVerifyMessage{
|
|
Message: message,
|
|
SignatureVerificationError: &castedErr,
|
|
}
|
|
} else {
|
|
explicitVerify = &ExplicitVerifyMessage{
|
|
Message: message,
|
|
SignatureVerificationError: nil,
|
|
}
|
|
}
|
|
|
|
return explicitVerify, nil
|
|
}
|