Skip to content

miniproto.media.cdn.verify_cdn_part

verify_cdn_part(invoke: RawInvoker, redirect: CdnRedirect, *, offset: int, data: bytes, known_hashes: dict[int, types.FileHash] | None = None, request_timeout: float | None = None) -> None

Verify a decrypted CDN chunk against Telegram’s 128 KiB SHA-256 file hashes.

Parameters:

  • invoke (RawInvoker) – Async raw-RPC invoker used to request missing CDN hash metadata.
  • redirect (CdnRedirect) – CDN token and redirect-provided hash metadata for this file.
  • offset (int) – File offset of the first byte in data.
  • data (bytes) – Already-decrypted CDN bytes to validate; bytes are not zeroized.
  • known_hashes (dict[int, FileHash] | None) – Optional mutable offset-to-hash cache shared by the caller. Redirect hashes seed a new cache when it is omitted.
  • request_timeout (float | None) – Optional per-RPC timeout in seconds for missing hash fetches.

Raises:

  • CdnIntegrityError – Any byte lacks a valid complete hash block, hash metadata is invalid, or a SHA-256 digest mismatches.
  • CancelledError – The awaited metadata request is cancelled.

Hashes delivered with the redirect seed the lookup; uncovered blocks are fetched from the master DC with upload.getCdnFileHashes. Every byte of data must be covered by a verified hash. Each raw FileHash.limit defines the exact number of bytes sliced and hashed for its offset, so a short chunk cannot be treated as a partial successful block.