Buckets:

download
raw
1.11 kB
"""Integrity checks for grammar download artifacts."""
import hashlib
import hmac
import re
from collections.abc import Mapping
from pathlib import Path
from typing import Any
class ArtifactIntegrityError(ValueError):
"""Raised when an artifact is not covered by trusted provenance."""
def verify_artifact(path: Path, provenance: Mapping[str, Any]) -> None:
"""Verify ``path`` against its repo-owned SHA-256 provenance entry."""
expected = provenance.get("sha256")
if not isinstance(expected, str) or not re.fullmatch(r"[0-9a-fA-F]{64}", expected):
raise ArtifactIntegrityError("Artifact provenance requires a SHA-256 checksum")
if not path.is_file():
raise ArtifactIntegrityError(f"Artifact does not exist: {path}")
digest = hashlib.sha256()
with path.open("rb") as artifact:
for block in iter(lambda: artifact.read(1024 * 1024), b""):
digest.update(block)
if not hmac.compare_digest(digest.hexdigest(), expected.lower()):
raise ArtifactIntegrityError(
"Artifact checksum does not match trusted provenance"
)

Xet Storage Details

Size:
1.11 kB
·
Xet hash:
2c068d700d603069d0f1c9b1c0003109a6d9261e10cda9b8f55ecc0068d25c5e

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.