# -*- 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 42.0.5
name                py-${github.project}
revision            0
categories-append   devel
license             BSD

python.versions     27 36 37 38 39 310 311 312
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  c5cdccb51bab89cb05abf0789878f51bbcca16c9 \
                    sha256  0c2a89eca28bd8290d9b7764f0117fcc578df0341f235807d7bffb668ac595b2 \
                    size    36020322

# 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
        github.setup    pyca cryptography 3.3.2
        revision        0

        python.pep517   no

        # Build fails with OpenSSL 3; use 1.1 for now
        openssl.branch  1.1

        description     Legacy support of Python cryptography.

        long_description    {*}${description}

        checksums       rmd160  13380349b4a5559153c1e8a328fd4629b81e134d \
                        sha256  2c8af64316fa1c09162c6e99dba9c23c76a07c3466dbbf62db8df970b45f935f \
                        size    35729139

        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

        if {${python.version} eq 27} {
            depends_lib-append \
                        port:py${python.version}-enum34 \
                        port:py${python.version}-ipaddress
        }
    } elseif {${python.version} eq 36} {
        PortGroup       rust 1.0

        github.setup    pyca cryptography 36.0.2
        revision        0

        python.pep517   no

        openssl.branch  1.1

        checksums   ${distname}${extract.suffix} \
                    rmd160  6513816850a696909886ebab1e562b1150d7ef5f \
                    sha256  db5b8ad6b9d3cd099e543dc70826946e61282d920126c43bc4534dea174df537 \
                    size    35821161

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

        cargo.crates \
                    Inflector 0.11.4 fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3 \
                    aliasable 0.1.3 250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd \
                    asn1 0.8.7 cfffb35195feaeffb071af0f7a643405667813dd8629c27cb0c310fb76654ab1 \
                    asn1_derive 0.8.7 bc894fa05f786b6481065514e6ff5e1838a3362f543f71f6e1a92ff27b051c25 \
                    autocfg 1.0.1 cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a \
                    base64 0.13.0 904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd \
                    bitflags 1.3.2 bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a \
                    cfg-if 1.0.0 baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd \
                    chrono 0.4.19 670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73 \
                    indoc 0.3.6 47741a8bc60fb26eb8d6e0238bbb26d8575ff623fdc97b1a2c00c050b9684ed8 \
                    indoc-impl 0.3.6 ce046d161f000fffde5f432a0d034d0341dc152643b2598ed5bfce44c4f3a8f0 \
                    instant 0.1.12 7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c \
                    lazy_static 1.4.0 e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646 \
                    libc 0.2.107 fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219 \
                    lock_api 0.4.5 712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109 \
                    num-integer 0.1.44 d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db \
                    num-traits 0.2.14 9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290 \
                    once_cell 1.8.0 692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56 \
                    ouroboros 0.13.0 f357ef82d1b4db66fbed0b8d542cbd3c22d0bf5b393b3c257b9ba4568e70c9c3 \
                    ouroboros_macro 0.13.0 44a0b52c2cbaef7dffa5fec1a43274afe8bd2a644fa9fc50a9ef4ff0269b1257 \
                    parking_lot 0.11.2 7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99 \
                    parking_lot_core 0.8.5 d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216 \
                    paste 0.1.18 45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880 \
                    paste-impl 0.1.18 d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6 \
                    pem 1.0.1 06673860db84d02a63942fa69cd9543f2624a5df3aea7f33173048fa7ad5cf1a \
                    proc-macro-error 1.0.4 da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c \
                    proc-macro-error-attr 1.0.4 a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869 \
                    proc-macro-hack 0.5.19 dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5 \
                    proc-macro2 1.0.32 ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43 \
                    pyo3 0.15.1 7cf01dbf1c05af0a14c7779ed6f3aa9deac9c3419606ac9de537a2d649005720 \
                    pyo3-build-config 0.15.1 dbf9e4d128bfbddc898ad3409900080d8d5095c379632fbbfbb9c8cfb1fb852b \
                    pyo3-macros 0.15.1 67701eb32b1f9a9722b4bc54b548ff9d7ebfded011c12daece7b9063be1fd755 \
                    pyo3-macros-backend 0.15.1 f44f09e825ee49a105f2c7b23ebee50886a9aee0746f4dd5a704138a64b0218a \
                    quote 1.0.10 38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05 \
                    redox_syscall 0.2.10 8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff \
                    regex 1.5.4 d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461 \
                    regex-syntax 0.6.25 f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b \
                    scopeguard 1.1.0 d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd \
                    smallvec 1.7.0 1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309 \
                    stable_deref_trait 1.2.0 a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3 \
                    syn 1.0.81 f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966 \
                    unicode-xid 0.2.2 8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3 \
                    unindent 0.1.7 f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7 \
                    version_check 0.9.3 5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe \
                    winapi 0.3.9 5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419 \
                    winapi-i686-pc-windows-gnu 0.4.0 ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6 \
                    winapi-x86_64-pc-windows-gnu 0.4.0 712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f
    } else {
        PortGroup   rust 1.0

        # Needs to use the same openssl version as python itself was built with...
        # https://trac.macports.org/ticket/63968
        if { ${python.version} < 38 } {
            openssl.branch  1.1
        } else {
            openssl.branch  3
        }

        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 \
                    port:py${python.version}-pytest-benchmark \
                    port:py${python.version}-pytest-cov \
                    port:py${python.version}-pytest-xdist \
                    port:py${python.version}-pretend

        # 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.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

        pre-test {
            test.env-append \
                    PYTHONPATH=[glob -nocomplain ${worksrcpath}/build/lib*]
        }

        test.run    yes
        test.cmd    py.test-${python.branch}
        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
        }

        build.dir   ${worksrcpath}/vectors

        livecheck.type  none
    }
}
