# Maintainer: Szilárd Pfeiffer <coroner@pfeifferszilard.hu>

_base=cryptolyzer
pkgname=${_base}
pkgver=1.6.1
# shellcheck disable=SC2034
pkgrel=1
# shellcheck disable=SC2034
pkgdesc="Multi-protocol cryptographic configuration analyzer"
# shellcheck disable=SC2034
arch=(any)
url="https://gitlab.com/coroner/${_base}"
# shellcheck disable=SC2034
license=(MPL-2.0)
# shellcheck disable=SC2034
depends=(python
         python-asn1crypto
         python-attrs
         python-beautifulsoup4
         python-colorama
         "python-cryptodatahub>=1.6.1"
         "python-cryptoparser>=1.6.1"
         python-dnspython
         "python-pycryptodomex>=3.19"
         python-requests
         python-urllib3)
# shellcheck disable=SC2034
optdepends=("python-certvalidator: X.509 certificate chain validation, trust store check and revocation check"
            "python-oscrypto: X.509 certificate chain validation, trust store check and revocation check")
# shellcheck disable=SC2034
makedepends=(python-build python-installer python-setuptools python-setuptools-scm python-wheel)
# shellcheck disable=SC2034
checkdepends=(python-asn1crypto python-attrs python-beautifulsoup4 python-colorama
              python-cryptodatahub python-cryptoparser python-dnspython
              "python-pycryptodomex>=3.19" python-pyfakefs python-requests python-urllib3)
# The library and the command were packaged separately before, as python-cryptolyzer and cryptolyzer.
# shellcheck disable=SC2034
provides=("python-${_base}")
# shellcheck disable=SC2034
conflicts=("python-${_base}")
# shellcheck disable=SC2034
replaces=("python-${_base}")

_builddir=${_base}-v${pkgver}

# shellcheck disable=SC2034
source=("${pkgname}-${pkgver}.tar.gz::${url}/-/archive/v${pkgver}/${_builddir}.tar.gz")
# shellcheck disable=SC2034
sha256sums=(SKIP)

build() {
  cd ${_builddir} || exit
  python -m build --wheel --no-isolation
}

check() {
  cd ${_builddir} || exit
  rm -rf test-install
  python -m installer --destdir=test-install dist/*.whl
  local site_packages
  site_packages=$(python -c "import sysconfig; print(sysconfig.get_paths()['purelib'])")
  # cryptolyzer reads its own distribution metadata on import, so the tests run
  # against an installed copy rather than the source tree.
  PYTHONPATH="${PWD}/test-install${site_packages}" \
  CRYPTOLYZER_TEST_SKIP_LIVE_SERVER=1 CRYPTOLYZER_TEST_SKIP_LIVE_DNS=1 \
  no_proxy=127.0.0.1,localhost \
      python -m unittest discover
}

package() {
  cd ${_builddir} || exit
  # shellcheck disable=SC2154
  python -m installer --destdir="${pkgdir}" dist/*.whl
  install -Dm644 LICENSE.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt"
  install -Dm644 README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md"
}
