Add a helper to verify stream signatures explicitly

Adds the helper `VerifySignatureExplit()` to get an explicit `SignatureVerificationError`
when verifying a `PlainMessageReader`. This is needed for mobile apps, that
can't cast an error to a signature error.
This commit is contained in:
marin thiercelin 2021-07-14 09:56:59 +02:00
parent cd4adae9f2
commit f4ccc63c40
No known key found for this signature in database
GPG key ID: 117C025B1F21B2C6
3 changed files with 195 additions and 0 deletions

View file

@ -180,3 +180,24 @@ func (r *Go2IOSReader) Read(max int) (result *MobileReadResult, err error) {
}
return result, nil
}
// VerifySignatureExplicit calls the reader's VerifySignature()
// and tries to cast the returned error to a SignatureVerificationError.
func VerifySignatureExplicit(
reader *crypto.PlainMessageReader,
) (signatureVerificationError *crypto.SignatureVerificationError, err error) {
if reader == nil {
return nil, errors.New("gopenppg: the reader can't be nil")
}
err = reader.VerifySignature()
if err != nil {
castedErr := &crypto.SignatureVerificationError{}
isType := errors.As(err, castedErr)
if !isType {
return
}
signatureVerificationError = castedErr
err = nil
}
return
}