1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 callPackage,
6 setuptools,
7 bcrypt,
8 certifi,
9 cffi,
10 cryptography-vectors ? (callPackage ./vectors.nix { }),
11 fetchFromGitHub,
12 isPyPy,
13 libiconv,
14 libxcrypt,
15 openssl,
16 pkg-config,
17 pretend,
18 pytest-xdist,
19 pytestCheckHook,
20 pythonOlder,
21 rustPlatform,
22}:
23
24buildPythonPackage rec {
25 pname = "cryptography";
26 version = "44.0.2"; # Also update the hash in vectors.nix
27 pyproject = true;
28
29 disabled = pythonOlder "3.7";
30
31 src = fetchFromGitHub {
32 owner = "pyca";
33 repo = "cryptography";
34 tag = version;
35 hash = "sha256-nXwW6v+U47/+CmjhREHcuQ7QQi/b26gagWBQ3F16DuQ=";
36 };
37
38 cargoDeps = rustPlatform.fetchCargoVendor {
39 inherit pname version src;
40 hash = "sha256-HbUsV+ABE89UvhCRZYXr+Q/zRDKUy+HgCVdQFHqaP4o=";
41 };
42
43 postPatch = ''
44 substituteInPlace pyproject.toml \
45 --replace-fail "--benchmark-disable" ""
46 '';
47
48 build-system = [
49 rustPlatform.cargoSetupHook
50 rustPlatform.maturinBuildHook
51 pkg-config
52 setuptools
53 ] ++ lib.optionals (!isPyPy) [ cffi ];
54
55 buildInputs =
56 [ openssl ]
57 ++ lib.optionals stdenv.hostPlatform.isDarwin [
58 libiconv
59 ]
60 ++ lib.optionals (pythonOlder "3.9") [ libxcrypt ];
61
62 dependencies = lib.optionals (!isPyPy) [ cffi ];
63
64 optional-dependencies.ssh = [ bcrypt ];
65
66 nativeCheckInputs = [
67 certifi
68 cryptography-vectors
69 pretend
70 pytestCheckHook
71 pytest-xdist
72 ] ++ optional-dependencies.ssh;
73
74 pytestFlagsArray = [ "--disable-pytest-warnings" ];
75
76 disabledTestPaths = [
77 # save compute time by not running benchmarks
78 "tests/bench"
79 ];
80
81 passthru = {
82 vectors = cryptography-vectors;
83 };
84
85 meta = with lib; {
86 description = "Package which provides cryptographic recipes and primitives";
87 longDescription = ''
88 Cryptography includes both high level recipes and low level interfaces to
89 common cryptographic algorithms such as symmetric ciphers, message
90 digests, and key derivation functions.
91 '';
92 homepage = "https://github.com/pyca/cryptography";
93 changelog =
94 "https://cryptography.io/en/latest/changelog/#v" + replaceStrings [ "." ] [ "-" ] version;
95 license = with licenses; [
96 asl20
97 bsd3
98 psfl
99 ];
100 maintainers = with maintainers; [ SuperSandro2000 ];
101 };
102}