1{ lib
2, stdenv
3, buildPythonPackage
4, callPackage
5, cargo
6, cffi
7, fetchPypi
8, hypothesis
9, iso8601
10, isPyPy
11, libiconv
12, libxcrypt
13, openssl
14, pkg-config
15, pretend
16, py
17, pytest-subtests
18, pytestCheckHook
19, pythonOlder
20, pytz
21, rustc
22, rustPlatform
23, Security
24, setuptoolsRustBuildHook
25}:
26
27let
28 cryptography-vectors = callPackage ./vectors.nix { };
29in
30buildPythonPackage rec {
31 pname = "cryptography";
32 version = "41.0.3"; # Also update the hash in vectors.nix
33 format = "pyproject";
34 disabled = pythonOlder "3.7";
35
36 src = fetchPypi {
37 inherit pname version;
38 hash = "sha256-bRknQRE+9eMNidy1uVbvThV48wRwhwG4tz044+FGHzQ=";
39 };
40
41 cargoDeps = rustPlatform.fetchCargoTarball {
42 inherit src;
43 sourceRoot = "${pname}-${version}/${cargoRoot}";
44 name = "${pname}-${version}";
45 hash = "sha256-LQu7waympGUs+CZun2yDQd2gUUAgyisKBG5mddrfSo0=";
46 };
47
48 postPatch = ''
49 substituteInPlace pyproject.toml \
50 --replace "--benchmark-disable" ""
51 '';
52
53 cargoRoot = "src/rust";
54
55 nativeBuildInputs = [
56 rustPlatform.cargoSetupHook
57 setuptoolsRustBuildHook
58 cargo
59 rustc
60 pkg-config
61 ] ++ lib.optionals (!isPyPy) [
62 cffi
63 ];
64
65 buildInputs = [
66 openssl
67 ] ++ lib.optionals stdenv.isDarwin [
68 Security
69 libiconv
70 ] ++ lib.optionals (pythonOlder "3.9") [
71 libxcrypt
72 ];
73
74 propagatedBuildInputs = lib.optionals (!isPyPy) [
75 cffi
76 ];
77
78 nativeCheckInputs = [
79 cryptography-vectors
80 hypothesis
81 iso8601
82 pretend
83 py
84 pytestCheckHook
85 pytest-subtests
86 pytz
87 ];
88
89 pytestFlagsArray = [
90 "--disable-pytest-warnings"
91 ];
92
93 disabledTestPaths = [
94 # save compute time by not running benchmarks
95 "tests/bench"
96 ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
97 # aarch64-darwin forbids W+X memory, but this tests depends on it:
98 # * https://cffi.readthedocs.io/en/latest/using.html#callbacks
99 "tests/hazmat/backends/test_openssl_memleak.py"
100 ];
101
102 meta = with lib; {
103 description = "A package which provides cryptographic recipes and primitives";
104 longDescription = ''
105 Cryptography includes both high level recipes and low level interfaces to
106 common cryptographic algorithms such as symmetric ciphers, message
107 digests, and key derivation functions.
108 '';
109 homepage = "https://github.com/pyca/cryptography";
110 changelog = "https://cryptography.io/en/latest/changelog/#v"
111 + replaceStrings [ "." ] [ "-" ] version;
112 license = with licenses; [ asl20 bsd3 psfl ];
113 maintainers = with maintainers; [ SuperSandro2000 ];
114 };
115}