#!/bin/sh
# PQ Shift pre-commit hook: blocks new classic-only cryptography in staged changes.
# Install: cp guard/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
# Needs tools/pqshift.py vendored into the repo (check it against the published SHA256SUMS).
# Works under Git for Windows (Git Bash runs this script).

PQSHIFT="tools/pqshift.py"

if [ ! -f "$PQSHIFT" ]; then
    echo "pq-shift: $PQSHIFT not found, so the cryptography guard cannot run." >&2
    echo "pq-shift: vendor it from https://zirkomirko.com/tools/pq-shift/ or remove this hook on purpose." >&2
    exit 1
fi

PY=""
for candidate in python3 python py; do
    if command -v "$candidate" >/dev/null 2>&1; then
        PY="$candidate"
        break
    fi
done

if [ -z "$PY" ]; then
    echo "pq-shift: no Python found; cannot run the cryptography guard." >&2
    exit 1
fi

"$PY" "$PQSHIFT" guard --staged || {
    echo "pq-shift: commit blocked. Fix the findings above, or add a dated exception with a reason to .pqshift.json." >&2
    exit 1
}
