verifyBundleText function
True when info carries a valid signature by one of keys over the canonical string for bundleText.
A key id narrows the candidates; an unknown key id is not "any key" (keys without a kid still apply).
Implementation
Future<bool> verifyBundleText(List<ImportedKey> keys, SignatureInfo info, String bundleText) async {
List<int> signature;
try {
signature = base64UrlDecodeStrict(info.signature);
} on FormatException {
return false;
}
if (signature.length != 64) return false;
final data = utf8.encode(canonicalString(info.environmentId, info.revision, info.checksum, sha256Hex(bundleText)));
final candidates = info.kid == null ? keys : keys.where((k) => k.kid == info.kid || k.kid == null);
for (final k in candidates) {
try {
if (await _ed25519.verify(data, signature: Signature(signature, publicKey: k.key))) return true;
} catch (_) {
// try the next key
}
}
return false;
}