checkPinned function
void
checkPinned(})
Checks that bytes, downloaded as what, are the size bytes whose
SHA-256 is sha256. Throws DownloadException when they are not:
changed after they were pinned, or broken on the way.
Implementation
void checkPinned(
Uint8List bytes, {
required int size,
required String sha256,
required String what,
}) {
if (bytes.length != size) {
throw DownloadException(
'$what downloaded as ${bytes.length} bytes, but the catalog says '
'$size. The download was refused.',
);
}
if (Sha256.hexOf(bytes) != sha256) {
throw DownloadException(
'$what does not match its catalog fingerprint (SHA-256). It may have '
'been changed after it was published, so it was refused.',
);
}
}