crypto: integrate varsig

This commit is contained in:
Michael Muré
2025-07-30 18:32:14 +02:00
committed by Michael Muré
parent b520568e7d
commit 2f76eaa8fe
30 changed files with 451 additions and 123 deletions

View File

@@ -6,12 +6,24 @@ import (
"github.com/MetaMask/go-did-it/crypto"
)
// TryAllVerify tries to verify the signature with all the methods in the slice.
// TryAllVerifyBytes tries to verify the signature as bytes with all the methods in the slice.
// It returns true if the signature is verified, and the method that verified it.
// If no method verifies the signature, it returns false and nil.
func TryAllVerify(methods []VerificationMethodSignature, data []byte, sig []byte) (bool, VerificationMethodSignature) {
func TryAllVerifyBytes(methods []VerificationMethodSignature, data []byte, sig []byte, opts ...crypto.SigningOption) (bool, VerificationMethodSignature) {
for _, method := range methods {
if valid, err := method.Verify(data, sig); err == nil && valid {
if valid, err := method.VerifyBytes(data, sig, opts...); err == nil && valid {
return true, method
}
}
return false, nil
}
// TryAllVerifyASN1 tries to verify the signature as ASN.1 with all the methods in the slice.
// It returns true if the signature is verified, and the method that verified it.
// If no method verifies the signature, it returns false and nil.
func TryAllVerifyASN1(methods []VerificationMethodSignature, data []byte, sig []byte, opts ...crypto.SigningOption) (bool, VerificationMethodSignature) {
for _, method := range methods {
if valid, err := method.VerifyASN1(data, sig, opts...); err == nil && valid {
return true, method
}
}