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:
parent
cd4adae9f2
commit
f4ccc63c40
3 changed files with 195 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue