##
##  python-crypto.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package versions
%define       V_python           3.14
%define       V_pycrypto         2.6.1
%define       V_pyopenssl        25.3.0
%define       V_cryptography     46.0.3
%define       V_pyasn1           0.6.1
%define       V_pyasn1_modules   0.2.8
%define       V_ndg_httpsclient  0.5.1
%define       V_pynacl           1.5.0
%define       V_libnacl          2.1.0
%define       V_service_identity 24.2.0
%define       V_asn1crypto       1.5.1
%define       V_certifi          2025.10.5
%define       V_passlib          1.7.4

#   package information
Name:         python-crypto
Summary:      Python Modules for Cryptography
URL:          http://www.python.org/
Vendor:       Python Community
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Language
License:      GPL
Version:      %{V_python}
Release:      20251016

#   package options
%option       with_libnacl      no

#   list of sources
Source0:      https://files.pythonhosted.org/packages/source/p/pycrypto/pycrypto-%{V_pycrypto}.tar.gz
Source1:      https://files.pythonhosted.org/packages/source/p/pyOpenSSL/pyopenssl-%{V_pyopenssl}.tar.gz
Source2:      https://files.pythonhosted.org/packages/source/c/cryptography/cryptography-%{V_cryptography}.tar.gz
Source3:      https://files.pythonhosted.org/packages/source/p/pyasn1/pyasn1-%{V_pyasn1}.tar.gz
Source4:      https://files.pythonhosted.org/packages/source/p/pyasn1-modules/pyasn1-modules-%{V_pyasn1_modules}.tar.gz
Source5:      https://files.pythonhosted.org/packages/source/n/ndg-httpsclient/ndg_httpsclient-%{V_ndg_httpsclient}.tar.gz
Source6:      https://files.pythonhosted.org/packages/source/P/PyNaCl/PyNaCl-%{V_pynacl}.tar.gz
Source7:      https://files.pythonhosted.org/packages/source/l/libnacl/libnacl-%{V_libnacl}.tar.gz
Source8:      https://files.pythonhosted.org/packages/source/s/service_identity/service_identity-%{V_service_identity}.tar.gz
Source9:      https://files.pythonhosted.org/packages/source/a/asn1crypto/asn1crypto-%{V_asn1crypto}.tar.gz
Source10:     https://files.pythonhosted.org/packages/source/c/certifi/certifi-%{V_certifi}.tar.gz
Source11:     https://files.pythonhosted.org/packages/source/p/passlib/passlib-%{V_passlib}.tar.gz
Patch0:       python-crypto.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, python >= %{V_python}, rust
PreReq:       OpenPKG, openpkg >= 20160101, python >= %{V_python}
BuildPreReq:  openssl, gmp, libsodium, python-sys, python-parse, python-setup
PreReq:       openssl, gmp, libsodium, python-sys, python-parse, python-setup
%if "%{with_libnacl}" == "yes"
BuildPreReq:  python::with_ctypes = yes
PreReq:       python::with_ctypes = yes
%endif

%description
    This is a set of Python extension modules for cryptography.

%track
    prog python-crypto:pycrypto = {
        version   = %{V_pycrypto}
        url       = https://pypi.python.org/pypi/pycrypto
        regex     = pycrypto-(__VER__)\.tar\.gz
    }
    prog python-crypto:pyopenssl = {
        version   = %{V_pyopenssl}
        url       = https://pypi.python.org/pypi/pyOpenSSL/
        regex     = pyopenssl-(__VER__)\.tar\.gz
    }
    prog python-crypto:cryptography = {
        version   = %{V_cryptography}
        url       = https://pypi.python.org/pypi/cryptography/
        regex     = cryptography-(__VER__)\.tar\.gz
    }
    prog python-crypto:pyasn1 = {
        version   = %{V_pyasn1}
        url       = https://pypi.python.org/pypi/pyasn1/
        regex     = pyasn1-(__VER__)\.tar\.gz
    }
    prog python-crypto:pyasn1-modules = {
        version   = %{V_pyasn1_modules}
        url       = https://pypi.python.org/pypi/pyasn1-modules/
        regex     = pyasn1-modules-(__VER__)\.tar\.gz
    }
    prog python-crypto:ndg-httpsclient = {
        version   = %{V_ndg_httpsclient}
        url       = https://pypi.python.org/pypi/ndg-httpsclient/
        regex     = ndg_httpsclient-(__VER__)\.tar\.gz
    }
    prog python-crypto:PyNaCl = {
        version   = %{V_pynacl}
        url       = https://pypi.python.org/pypi/PyNaCl/
        regex     = PyNaCl-(__VER__)\.tar\.gz
    }
    prog python-crypto:libnacl = {
        version   = %{V_libnacl}
        url       = https://pypi.python.org/pypi/libnacl/
        regex     = libnacl-(__VER__)\.tar\.gz
    }
    prog python-crypto:service_identity = {
        version   = %{V_service_identity}
        url       = https://pypi.python.org/pypi/service_identity/
        regex     = service_identity-(__VER__)\.tar\.gz
    }
    prog python-crypto:asn1crypto = {
        version   = %{V_asn1crypto}
        url       = https://pypi.python.org/pypi/asn1crypto/
        regex     = asn1crypto-(__VER__)\.tar\.gz
    }
    prog python-crypto:certifi = {
        version   = %{V_certifi}
        url       = https://pypi.python.org/pypi/certifi/
        regex     = certifi-(__VER__)\.tar\.gz
    }
    prog python-crypto:passlib = {
        version   = %{V_passlib}
        url       = https://pypi.python.org/pypi/passlib/
        regex     = passlib-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %setup -q -T -D -a 3
    %setup -q -T -D -a 4
    %setup -q -T -D -a 5
    %setup -q -T -D -a 6
    %setup -q -T -D -a 7
    %setup -q -T -D -a 8
    %setup -q -T -D -a 9
    %setup -q -T -D -a 10
    %setup -q -T -D -a 11
    %patch -p0

%build

%install
    export PYTHONPATH=$RPM_BUILD_ROOT%{l_prefix}/lib/python%{V_python}/site-packages
    #   (   cd pycrypto-%{V_pycrypto}
    #       CFLAGS="%{l_cflags -O} %{l_cppflags}" \
    #       CXXFLAGS="%{l_cxxflags -O} %{l_cppflags}" \
    #       LDFLAGS="%{l_ldflags}" \
    #       HOME=`pwd` %{l_prefix}/bin/python \
    #           -m pip install \
    #           --root=$RPM_BUILD_ROOT \
    #           --prefix=%{l_prefix} \
    #           --ignore-installed \
    #           --no-deps \
    #           .
    #   ) || exit $?
    ( cd pyopenssl-%{V_pyopenssl}
      %{l_prefix}/bin/python setup.py build_ext \
          %{l_cppflags openssl .} %{l_ldflags}
      %{l_prefix}/bin/python setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd cryptography-%{V_cryptography}
      HOME=`pwd` %{l_prefix}/bin/python \
          -m pip install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix} \
          --ignore-installed \
          --no-deps \
          .
    ) || exit $?
    ( cd pyasn1-%{V_pyasn1}
      %{l_prefix}/bin/python setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd pyasn1-modules-%{V_pyasn1_modules}
      %{l_prefix}/bin/python setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd ndg_httpsclient-%{V_ndg_httpsclient}
      %{l_prefix}/bin/python setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd PyNaCl-%{V_pynacl}
      SODIUM_INSTALL=system \
      %{l_prefix}/bin/python setup.py build_ext \
          %{l_cppflags} %{l_ldflags}
      SODIUM_INSTALL=system \
      %{l_prefix}/bin/python setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
%if "%{with_libnacl}" == "yes"
    ( cd libnacl-%{V_libnacl}
      SODIUM_INSTALL=system \
      %{l_prefix}/bin/python setup.py build_ext \
          %{l_cppflags} %{l_ldflags}
      SODIUM_INSTALL=system \
      %{l_prefix}/bin/python setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
%endif
    ( cd service_identity-%{V_service_identity}
      HOME=`pwd` %{l_prefix}/bin/python \
          -m pip install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix} \
          --ignore-installed \
          --no-deps \
          .
    ) || exit $?
    ( cd asn1crypto-%{V_asn1crypto}
      %{l_prefix}/bin/python setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd certifi-%{V_certifi}
      %{l_prefix}/bin/python setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd passlib-%{V_passlib}
      %{l_prefix}/bin/python setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

