1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 callPackage,
6 cargo,
7 certifi,
8 cffi,
9 cryptography-vectors ? (callPackage ./vectors.nix { }),
10 fetchPypi,
11 fetchpatch2,
12 isPyPy,
13 libiconv,
14 libxcrypt,
15 openssl,
16 pkg-config,
17 pretend,
18 pytest-xdist,
19 pytestCheckHook,
20 pythonOlder,
21 rustc,
22 rustPlatform,
23 Security,
24 setuptoolsRustBuildHook,
25}:
26
27buildPythonPackage rec {
28 pname = "cryptography";
29 version = "42.0.5"; # Also update the hash in vectors.nix
30 pyproject = true;
31
32 disabled = pythonOlder "3.7";
33
34 src = fetchPypi {
35 inherit pname version;
36 hash = "sha256-b+B+7JXf1HfrlTCu9b6tNP7IGbOq9sW9bSBWXaYHv+E=";
37 };
38
39 cargoDeps = rustPlatform.fetchCargoTarball {
40 inherit src;
41 sourceRoot = "${pname}-${version}/${cargoRoot}";
42 name = "${pname}-${version}";
43 hash = "sha256-Pw3ftpcDMfZr/w6US5fnnyPVsFSB9+BuIKazDocYjTU=";
44 };
45
46 patches = [
47 (fetchpatch2 {
48 # skip overflowing tests on 32 bit; https://github.com/pyca/cryptography/pull/10366
49 url = "https://github.com/pyca/cryptography/commit/d741901dddd731895346636c0d3556c6fa51fbe6.patch";
50 hash = "sha256-eC+MZg5O8Ia5CbjRE4y+JhaFs3Q5c62QtPHr3x9T+zw=";
51 })
52 ];
53
54 postPatch = ''
55 substituteInPlace pyproject.toml \
56 --replace-fail "--benchmark-disable" ""
57 '';
58
59 cargoRoot = "src/rust";
60
61 nativeBuildInputs = [
62 rustPlatform.cargoSetupHook
63 setuptoolsRustBuildHook
64 cargo
65 rustc
66 pkg-config
67 ] ++ lib.optionals (!isPyPy) [ cffi ];
68
69 buildInputs =
70 [ openssl ]
71 ++ lib.optionals stdenv.isDarwin [
72 Security
73 libiconv
74 ]
75 ++ lib.optionals (pythonOlder "3.9") [ libxcrypt ];
76
77 propagatedBuildInputs = lib.optionals (!isPyPy) [ cffi ];
78
79 nativeCheckInputs = [
80 certifi
81 cryptography-vectors
82 pretend
83 pytestCheckHook
84 pytest-xdist
85 ];
86
87 pytestFlagsArray = [ "--disable-pytest-warnings" ];
88
89 disabledTestPaths = [
90 # save compute time by not running benchmarks
91 "tests/bench"
92 ];
93
94 meta = with lib; {
95 description = "A package which provides cryptographic recipes and primitives";
96 longDescription = ''
97 Cryptography includes both high level recipes and low level interfaces to
98 common cryptographic algorithms such as symmetric ciphers, message
99 digests, and key derivation functions.
100 '';
101 homepage = "https://github.com/pyca/cryptography";
102 changelog =
103 "https://cryptography.io/en/latest/changelog/#v" + replaceStrings [ "." ] [ "-" ] version;
104 license = with licenses; [
105 asl20
106 bsd3
107 psfl
108 ];
109 maintainers = with maintainers; [ SuperSandro2000 ];
110 };
111}