# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           python 1.0

github.setup        pyca cryptography 43.0.3
name                py-${github.project}
revision            0
categories-append   devel
license             BSD

python.versions     27 37 38 39 310 311 312 313
python.pep517       yes

maintainers         {stromnov @stromnov} openmaintainer

description         cryptography is a package designed to expose \
                    cryptographic primitives and recipes to Python developers.

long_description    {*}${description}

checksums           ${distname}${extract.suffix} \
                    rmd160  d051b41e20cc06e79d58aa4d29cb8b5e7298abfc \
                    sha256  959c24c0287e6f4023d22785989fd00a8b5239d4a25f0ce72a757b360661af05 \
                    size    36067295

# See:
# * https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst
# * https://ports.macports.org/port/rust/summary
set cryptography_darwin_min_ver 13

if {${name} ne ${subport} \
    && [string match "py*-${github.project}" ${subport}]} {
    depends_build-append \
                    port:py${python.version}-setuptools

    depends_lib-append \
                    port:py${python.version}-cffi

    # legacy support
    if {${python.version} eq 27 \
        || ${os.platform} eq "darwin" && ${os.major} < ${cryptography_darwin_min_ver}} {
        PortGroup           openssl 1.0

        if {${python.version} eq 27} {
            # Needs the same OpenSSL version as Python itself was built with.
            openssl.branch  1.1

            github.setup    pyca cryptography 3.3.2
            revision        0
            checksums       rmd160  13380349b4a5559153c1e8a328fd4629b81e134d \
                            sha256  2c8af64316fa1c09162c6e99dba9c23c76a07c3466dbbf62db8df970b45f935f \
                            size    35729139

            depends_lib-append \
                            port:py${python.version}-enum34 \
                            port:py${python.version}-ipaddress
        } else {
            github.setup    pyca cryptography 3.4.8
            revision        0
            checksums       rmd160  01ea4549ac0dc751bf7a81bfeb4b3c942303f254 \
                            sha256  cce7ee0b1082753df56c6bbbbe3c4122daba3b821b0d2129537d058624e67198 \
                            size    35736917

            # CRYPTOGRAPHY_DONT_BUILD_RUST is not respected by the build.
            # So just remove Rust stuff from setup.py, it is optional in 3.4.x.
            patchfiles-append \
                            patch-build-no-rust.diff
            # We do not want a build conflict with OpenSSL 3 here.
            # Thise version is easily fixable to build against it.
            patchfiles-append \
                            patch-openssl3.diff
        }

        python.pep517   no

        description     Legacy support of Python cryptography.

        long_description    {*}${description}

        if {${os.platform} eq "darwin" && ${os.major} < 11} {
            # https://trac.macports.org/ticket/54519
            patchfiles-append   patch-src__cffi_src_build_openssl.py.diff
        }

        compiler.cpath-prepend \
                        [openssl::include_dir]

        depends_lib-append \
                        port:py${python.version}-six

    } else {
        PortGroup   rust 1.0

        if { ${python.version} < 38 } {
            github.setup    pyca cryptography 42.0.5
            revision        0
            checksums       ${distname}${extract.suffix} \
                            rmd160  c5cdccb51bab89cb05abf0789878f51bbcca16c9 \
                            sha256  0c2a89eca28bd8290d9b7764f0117fcc578df0341f235807d7bffb668ac595b2 \
                            size    36020322

            # Needs to use the same openssl version as python itself was built with...
            # https://trac.macports.org/ticket/63968
            openssl.branch  1.1

            cargo.crates \
                        asn1 0.15.5 ae3ecbce89a22627b5e8e6e11d69715617138290289e385cde773b1fe50befdb \
                        asn1_derive 0.15.5 861af988fac460ac69a09f41e6217a8fb9178797b76fcc9478444be6a59be19c \
                        autocfg 1.1.0 d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa \
                        base64 0.21.7 9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567 \
                        bitflags 1.3.2 bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a \
                        bitflags 2.4.2 ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf \
                        cc 1.0.83 f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0 \
                        cfg-if 1.0.0 baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd \
                        foreign-types 0.3.2 f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1 \
                        foreign-types-shared 0.1.1 00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b \
                        heck 0.4.1 95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8 \
                        indoc 2.0.4 1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8 \
                        libc 0.2.152 13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7 \
                        lock_api 0.4.11 3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45 \
                        memoffset 0.9.0 5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c \
                        once_cell 1.19.0 3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92 \
                        openssl 0.10.63 15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8 \
                        openssl-macros 0.1.1 a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c \
                        openssl-sys 0.9.99 22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae \
                        parking_lot 0.12.1 3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f \
                        parking_lot_core 0.9.9 4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e \
                        pem 3.0.3 1b8fcc794035347fb64beda2d3b462595dd2753e3f268d89c5aae77e8cf2c310 \
                        pkg-config 0.3.29 2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb \
                        portable-atomic 1.6.0 7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0 \
                        proc-macro2 1.0.78 e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae \
                        pyo3 0.20.3 53bdbb96d49157e65d45cc287af5f32ffadd5f4761438b527b055fb0d4bb8233 \
                        pyo3-build-config 0.20.3 deaa5745de3f5231ce10517a1f5dd97d53e5a2fd77aa6b5842292085831d48d7 \
                        pyo3-ffi 0.20.3 62b42531d03e08d4ef1f6e85a2ed422eb678b8cd62b762e53891c05faf0d4afa \
                        pyo3-macros 0.20.3 7305c720fa01b8055ec95e484a6eca7a83c841267f0dd5280f0c8b8551d2c158 \
                        pyo3-macros-backend 0.20.3 7c7e9b68bb9c3149c5b0cade5d07f953d6d125eb4337723c4ccdb665f1f96185 \
                        quote 1.0.35 291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef \
                        redox_syscall 0.4.1 4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa \
                        scopeguard 1.2.0 94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49 \
                        self_cell 1.0.3 58bf37232d3bb9a2c4e641ca2a11d83b5062066f88df7fed36c28772046d65ba \
                        smallvec 1.13.1 e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7 \
                        syn 2.0.48 0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f \
                        target-lexicon 0.12.13 69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae \
                        unicode-ident 1.0.12 3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b \
                        unindent 0.2.3 c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce \
                        vcpkg 0.2.15 accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426 \
                        windows-targets 0.48.5 9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c \
                        windows_aarch64_gnullvm 0.48.5 2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8 \
                        windows_aarch64_msvc 0.48.5 dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc \
                        windows_i686_gnu 0.48.5 a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e \
                        windows_i686_msvc 0.48.5 8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406 \
                        windows_x86_64_gnu 0.48.5 53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e \
                        windows_x86_64_gnullvm 0.48.5 0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc \
                        windows_x86_64_msvc 0.48.5 ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538
        } else {
            python.pep517_backend   maturin
            openssl.branch  3

            patchfiles-append   patch-setuptools_no_version.diff

            # cd ${worksrcpath}/src/rust
            # sudo cargo update
            # egrep -e '^(name|version|checksum) = ' Cargo.lock | perl -pe 's/^(?:name|version|checksum) = "(.+)"/$1/' | tr '\n' ' ' | perl -pe 's|([0-9a-f]{64})|\1 \\\n|g' | pbcopy
            cargo.crates \
                        asn1 0.16.2 532ceda058281b62096b2add4ab00ab3a453d30dee28b8890f62461a0109ebbd \
                        asn1_derive 0.16.2 56e6076d38cc17cc22b0f65f31170a2ee1975e6b07f0012893aefd86ce19c987 \
                        autocfg 1.3.0 0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0 \
                        base64 0.22.1 72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6 \
                        bitflags 2.6.0 b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de \
                        cc 1.1.6 2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f \
                        cfg-if 1.0.0 baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd \
                        foreign-types 0.3.2 f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1 \
                        foreign-types-shared 0.1.1 00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b \
                        heck 0.5.0 2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea \
                        indoc 2.0.5 b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5 \
                        libc 0.2.155 97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c \
                        memoffset 0.9.1 488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a \
                        once_cell 1.19.0 3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92 \
                        openssl 0.10.68 6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5 \
                        openssl-macros 0.1.1 a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c \
                        openssl-sys 0.9.104 45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741 \
                        pem 3.0.4 8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae \
                        pkg-config 0.3.30 d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec \
                        portable-atomic 1.7.0 da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265 \
                        proc-macro2 1.0.86 5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77 \
                        pyo3 0.22.2 831e8e819a138c36e212f3af3fd9eeffed6bf1510a805af35b0edee5ffa59433 \
                        pyo3-build-config 0.22.2 1e8730e591b14492a8945cdff32f089250b05f5accecf74aeddf9e8272ce1fa8 \
                        pyo3-ffi 0.22.2 5e97e919d2df92eb88ca80a037969f44e5e70356559654962cbb3316d00300c6 \
                        pyo3-macros 0.22.2 eb57983022ad41f9e683a599f2fd13c3664d7063a3ac5714cae4b7bee7d3f206 \
                        pyo3-macros-backend 0.22.2 ec480c0c51ddec81019531705acac51bcdbeae563557c982aa8263bb96880372 \
                        quote 1.0.36 0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7 \
                        self_cell 1.0.4 d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a \
                        syn 2.0.71 b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462 \
                        target-lexicon 0.12.15 4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2 \
                        unicode-ident 1.0.12 3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b \
                        unindent 0.2.3 c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce \
                        vcpkg 0.2.15 accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426
        }

        depends_build-append \
                    port:py${python.version}-setuptools-rust

        depends_test-append \
                    port:py${python.version}-cryptography_vectors \
                    port:py${python.version}-certifi \
                    port:py${python.version}-pytest-benchmark \
                    port:py${python.version}-pytest-xdist \
                    port:py${python.version}-pretend

        test.run    yes
        test.target tests
    }

    livecheck.type  none
}

# package cryptography_vectors
regsub 27 ${python.versions} "" python_versions_no27
foreach python_version ${python_versions_no27} {
    subport py${python_version}-cryptography_vectors {
        supported_archs noarch
        platforms       "darwin any >= ${cryptography_darwin_min_ver}"

        if { ${python.version} >= 37 } {
            python.pep517_backend   flit
        }

        if { ${python.version} < 38 } {
            github.setup    pyca cryptography 42.0.5
            revision        0
            checksums       ${distname}${extract.suffix} \
                            rmd160  c5cdccb51bab89cb05abf0789878f51bbcca16c9 \
                            sha256  0c2a89eca28bd8290d9b7764f0117fcc578df0341f235807d7bffb668ac595b2 \
                            size    36020322
        }

        build.dir   ${worksrcpath}/vectors

        livecheck.type  none
    }
}
