1{ lib, stdenv
2, buildPythonPackage
3, fetchPypi
4, rustPlatform
5, setuptools-rust
6, openssl
7, cryptography_vectors
8, darwin
9, packaging
10, six
11, isPyPy
12, cffi
13, pytest
14, pytest-subtests
15, pretend
16, libiconv
17, iso8601
18, pytz
19, hypothesis
20}:
21
22buildPythonPackage rec {
23 pname = "cryptography";
24 version = "3.4.8"; # Also update the hash in vectors.nix
25
26 src = fetchPypi {
27 inherit pname version;
28 sha256 = "072awar70cwfd2hnx0pvp1dkc7gw45mbm3wcyddvxz5frva5xk4l";
29 };
30
31 cargoDeps = rustPlatform.fetchCargoTarball {
32 inherit src;
33 sourceRoot = "${pname}-${version}/${cargoRoot}";
34 name = "${pname}-${version}";
35 sha256 = "01h511h6l4qvjxbaw662m1l84pb4wrhwxmnb3qj6ik13mx2m477m";
36 };
37
38 cargoRoot = "src/rust";
39
40 outputs = [ "out" "dev" ];
41
42 nativeBuildInputs = lib.optionals (!isPyPy) [
43 cffi
44 ] ++ [
45 rustPlatform.cargoSetupHook
46 setuptools-rust
47 ] ++ (with rustPlatform; [ rust.cargo rust.rustc ]);
48
49 buildInputs = [ openssl ]
50 ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security libiconv ];
51 propagatedBuildInputs = [
52 packaging
53 six
54 ] ++ lib.optionals (!isPyPy) [
55 cffi
56 ];
57
58 checkInputs = [
59 cryptography_vectors
60 hypothesis
61 iso8601
62 pretend
63 pytest
64 pytest-subtests
65 pytz
66 ];
67
68 pytestFlags = lib.concatStringsSep " " ([
69 "--disable-pytest-warnings"
70 ] ++
71 lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
72 # aarch64-darwin forbids W+X memory, but this tests depends on it:
73 # * https://cffi.readthedocs.io/en/latest/using.html#callbacks
74 "--ignore=tests/hazmat/backends/test_openssl_memleak.py"
75 ]
76 );
77
78 checkPhase = ''
79 py.test ${pytestFlags} tests
80 '';
81
82 # IOKit's dependencies are inconsistent between OSX versions, so this is the best we
83 # can do until nix 1.11's release
84 __impureHostDeps = [ "/usr/lib" ];
85
86 meta = with lib; {
87 description = "A package which provides cryptographic recipes and primitives";
88 longDescription = ''
89 Cryptography includes both high level recipes and low level interfaces to
90 common cryptographic algorithms such as symmetric ciphers, message
91 digests, and key derivation functions.
92 Our goal is for it to be your "cryptographic standard library". It
93 supports Python 2.7, Python 3.5+, and PyPy 5.4+.
94 '';
95 homepage = "https://github.com/pyca/cryptography";
96 changelog = "https://cryptography.io/en/latest/changelog/#v"
97 + replaceStrings [ "." ] [ "-" ] version;
98 license = with licenses; [ asl20 bsd3 psfl ];
99 maintainers = with maintainers; [ primeos ];
100 };
101}